Uh oh!
There was an error while loading.Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork32.2k
gh-117511: Make PyMutex public in the non-limited API#117731
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to ourterms of service andprivacy statement. We’ll occasionally send you account related emails.
Already on GitHub?Sign in to your account
Uh oh!
There was an error while loading.Please reload this page.
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.
Misc/NEWS.d/next/C API/2024-04-10-16-48-04.gh-issue-117511.RZtBRK.rst OutdatedShow resolvedHide resolved
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 notpart of the public C API.
@encukou@vstinner - I've updated the docs based oncapi-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 |
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others.Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others.Learn more.
@ericsnowcurrently expressed a preference for this style whenpyatomic.h
was added:#109344 (comment)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others.Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others.Learn more.
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"
@@ -2372,7 +2372,7 @@ new_reference(PyObject *op) | |||
#else | |||
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others.Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others.Learn more.
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
Python/lock.c Outdated
void | ||
_PyMutex_LockSlow(PyMutex *m) | ||
PyMutex_Lock(PyMutex *m) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others.Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others.Learn more.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others.Learn more.
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.
3af7263
intopython:mainUh oh!
There was an error while loading.Please reload this page.
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 commit3af7263)Co-authored-by: Sam Gross <colesbury@gmail.com>
…ythonGH-117731)(cherry picked from commit3af7263)Co-authored-by: Sam Gross <colesbury@gmail.com>
GH-120800 is a backport of this pull request to the3.13 branch. |
Yeah, congrats! |
That is very good news! Glad to see this land. |
Uh oh!
There was an error while loading.Please reload this page.
PyMutex
functions 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/