Uh oh!
There was an error while loading. Please reload this page.
gh-117511: Make PyMutex public in the non-limited API - #117731
Conversation
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Co-authored-by: Erlend E. Aasland <erlend.aasland@protonmail.com>
Co-authored-by: Erlend E. Aasland <erlend.aasland@protonmail.com>
Update code comments to further clarify that the `_bits` field is not part of the public C API.
colesbury
commented
Jun 17, 2024
@encukou@vstinner - I've updated the docs based on capi-workgroup/decisions#22 (comment). I'm not sure of the best way to make the functions also exported as regular functions, particularly with the same name. It's easy to export them with different names and |
vstinner
commented
Jun 17, 2024
You can look at my PR which does exactly that just for Py_TYPE(): https://github.com/python/cpython/pull/120601/files In short, add an underscore prefix to the static inline function, then use a macro to "rename" the static inline function. |
Uh oh!
There was an error while loading. Please reload this page.
| #ifndef Py_LIMITED_API | ||
| # define Py_CPYTHON_LOCK_H | ||
| # include "cpython/lock.h" |
There was a problem hiding this comment.
I don't see the value of such header file. Just include cpython/lock.h in Python.h, and check Py_LIMITED_API in cpython/lock.h.
There was a problem hiding this comment.
@ericsnowcurrently expressed a preference for this style when pyatomic.h was added: #109344 (comment)
There was a problem hiding this comment.
IMO, it's helpful to follow a consistent pattern when it comes to the Include/cpython header files. That means in some cases we end up with very minimal header files like this in Include/.
There was a problem hiding this comment.
If you mention consistency, there are already many header files in Include/cpython/ which have no companion Include/ header file:
$ grep cpython/ Include/Python.h
#include "cpython/pydebug.h"
#include "cpython/longintrepr.h"
#include "cpython/odictobject.h"
#include "cpython/funcobject.h"
#include "cpython/classobject.h"
#include "cpython/code.h"
#include "cpython/cellobject.h"
#include "cpython/initconfig.h"
#include "cpython/genobject.h"
#include "cpython/picklebufobject.h"
#include "cpython/pytime.h"
#include "cpython/context.h"
#include "cpython/pyctype.h"
#include "cpython/pyfpe.h"
#include "cpython/tracemalloc.h"
#include "cpython/optimizer.h"
| op->ob_tid = _Py_ThreadId(); | ||
| op->_padding = 0; | ||
| op->ob_mutex = (struct _PyMutex){ 0 }; | ||
| op->ob_mutex = (PyMutex){ 0 }; |
There was a problem hiding this comment.
If there is no public PyMutex_STATIC_INIT, can you maybe add a private one in pycore_lock.h?
There was a problem hiding this comment.
Let's consider that in a separate PR:
- It's not directly related to making the API public
- It would make sense to consider that for multiple types (e.g.,
PyEvent,_PyOnceFlag), not justPyMutex
| #undef PyMutex_Lock | ||
| void | ||
| _PyMutex_LockSlow(PyMutex *m) | ||
| PyMutex_Lock(PyMutex *m) |
There was a problem hiding this comment.
You might move it to the end to still use the static inline macro in the following lines.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
| #ifndef Py_LIMITED_API | ||
| # define Py_CPYTHON_LOCK_H | ||
| # include "cpython/lock.h" |
There was a problem hiding this comment.
If you mention consistency, there are already many header files in Include/cpython/ which have no companion Include/ header file:
$ grep cpython/ Include/Python.h
#include "cpython/pydebug.h"
#include "cpython/longintrepr.h"
#include "cpython/odictobject.h"
#include "cpython/funcobject.h"
#include "cpython/classobject.h"
#include "cpython/code.h"
#include "cpython/cellobject.h"
#include "cpython/initconfig.h"
#include "cpython/genobject.h"
#include "cpython/picklebufobject.h"
#include "cpython/pytime.h"
#include "cpython/context.h"
#include "cpython/pyctype.h"
#include "cpython/pyfpe.h"
#include "cpython/tracemalloc.h"
#include "cpython/optimizer.h"
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
vstinner
left a comment
There was a problem hiding this comment.
LGTM. Thanks for the different update and the doc.
@colesbury got an exception from @Yhg1s (3.13 release manager) to add this API to Python 3.13, god.
Thanks @colesbury for the PR 🌮🎉.. I'm working now to backport this PR to: 3.13. |
Sorry, @colesbury, I could not cleanly backport this to |
…ythonGH-117731) (cherry picked from commit 3af7263) Co-authored-by: Sam Gross <colesbury@gmail.com>
…ythonGH-117731) (cherry picked from commit 3af7263) Co-authored-by: Sam Gross <colesbury@gmail.com>
GH-120800 is a backport of this pull request to the 3.13 branch. |
vstinner
commented
Jun 20, 2024
Yeah, congrats! |
erlend-aasland
commented
Jun 27, 2024
That is very good news! Glad to see this land. |
PyMutexfunctions public #117511📚 Direct link 📚: https://cpython-previews--117731.org.readthedocs.build/en/117731/c-api/init.html#synchronization-primitives
📚 Documentation preview 📚: https://cpython-previews--117731.org.readthedocs.build/