Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
24 commits
Select commit Hold shift + click to select a range
fa92cb4
Add Py_mod_gil module slot
swtaarrs Mar 12, 2024
7edf796
Merge remote-tracking branch 'upstream/main' into cpython-mod-gil
swtaarrs Mar 22, 2024
450aa41
Some review comments from Eric
swtaarrs Mar 27, 2024
6bbd281
Merge remote-tracking branch 'upstream/main' into cpython-mod-gil
swtaarrs Apr 3, 2024
47b9e26
Fix enabling the GIL, also support disabling the GIL
swtaarrs Apr 15, 2024
f7c3e50
Merge remote-tracking branch 'upstream/main' into cpython-mod-gil
swtaarrs Apr 15, 2024
6c198e4
Fix module size in test_objecttypes
swtaarrs Apr 15, 2024
554c5b4
Add missing : in Py_mod_gil documentation
swtaarrs Apr 15, 2024
cd187a0
Merge remote-tracking branch 'upstream/main' into cpython-mod-gil
swtaarrs Apr 23, 2024
8057478
From Eric: better loop, move _PyImport_CheckGILForModule
swtaarrs Apr 23, 2024
a8f0943
Merge remote-tracking branch 'upstream/main' into cpython-mod-gil
swtaarrs Apr 26, 2024
bbb949e
Remove code to enable/disable the GIL (it will go in a different PR)
swtaarrs Apr 30, 2024
7f1205e
Don't put PyModule_SetGIL() in the limited API
swtaarrs Apr 26, 2024
f8b02b3
Set m->md_gil in PyModule_FromDefAndSpec2, rename/guard PyModule_SetG…
swtaarrs May 1, 2024
d2bad05
Fix limited API version for Py_mod_gil
swtaarrs May 1, 2024
d7d59f0
Update NEWS entry for behavioral changes
swtaarrs Apr 30, 2024
ccd6e00
Mark all modules as not using GIL
swtaarrs May 1, 2024
8846586
Merge remote-tracking branch 'upstream/main' into HEAD
swtaarrs May 1, 2024
99bc5cb
Fix 'gil_slot set but not used' warning
swtaarrs May 1, 2024
6882c13
Patch generator for Python-ast.c instead of just the file itself
swtaarrs May 1, 2024
da63df1
Update limited API version for _scproxy.c
swtaarrs May 1, 2024
2998def
Fix _testconsole.c for Windows build
swtaarrs May 1, 2024
77d1652
Fix winsound.c for Windows build
swtaarrs May 2, 2024
d1fe0cc
Mark more modules as not using the GIL
swtaarrs May 2, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Set m->md_gil in PyModule_FromDefAndSpec2, rename/guard PyModule_SetG…
…IL()
  • Loading branch information
swtaarrs committed May 1, 2024
commit f8b02b33feaf93e915192e437d2f04a4e8568cc0
10 changes: 5 additions & 5 deletions Doc/c-api/module.rst
Original file line number Diff line number Diff line change
Expand Up @@ -634,15 +634,15 @@ state:

.. versionadded:: 3.9

.. c:function:: int PyModule_SetGIL(PyObject *module, void *gil)
.. c:function:: int PyModule_ExperimentalSetGIL(PyObject *module, void *gil)

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ehm, can this please be renamed to PyUnstable as suggested before? We have such naming schemes for a reason.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry, I'll get a PR ready. I went with this name because having both Unstable and Experimental in the name felt redundant, and in this comment, @ericsnowcurrently expressed a preference for PyModule_ExperimentalSetGIL() over PyUnstable_Module_SetGIL().

Does anyone else have strong feelings on whether it should be PyUnstable_Module_ExperimentalSetGIL() or PyUnstable_Module_SetGIL()?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

PR here: #118645

IMO, the “experimental” is redundant. If we need “Experimental” too, we should rethink the entire PEP-689 naming convention.


In Python builds not configured with :option:`--disable-gil`, do
nothing. Otherwise, indicate that *module* does or does not support running
without the global interpreter lock (GIL), using one of the values from
Indicate that *module* does or does not support running without the global
interpreter lock (GIL), using one of the values from
:c:macro:`Py_mod_gil`. It must be called during *module*'s initialization
function. If this function is not called during module initialization, the
import machinery assumes the module does not support running without the
GIL.
GIL. This function is only available in Python builds configured with
:option:`--disable-gil`.
Return ``-1`` on error, ``0`` on success.

.. versionadded:: 3.13
Expand Down
4 changes: 2 additions & 2 deletions Include/moduleobject.h
Original file line number Diff line number Diff line change
Expand Up @@ -100,8 +100,8 @@ struct PyModuleDef_Slot {
# define Py_MOD_GIL_NOT_USED ((void *)1)
#endif

#ifndef Py_LIMITED_API
PyAPI_FUNC(int) PyModule_SetGIL(PyObject *module, void *gil);
#if !defined(Py_LIMITED_API) && defined(Py_GIL_DISABLED)
PyAPI_FUNC(int) PyModule_ExperimentalSetGIL(PyObject *module, void *gil);
#endif
Comment thread
swtaarrs marked this conversation as resolved.

struct PyModuleDef {
Expand Down
9 changes: 6 additions & 3 deletions Objects/moduleobject.c
Original file line number Diff line number Diff line change
Expand Up @@ -390,6 +390,9 @@ PyModule_FromDefAndSpec2(PyModuleDef* def, PyObject *spec, int module_api_versio
if (PyModule_Check(m)) {
((PyModuleObject*)m)->md_state = NULL;
((PyModuleObject*)m)->md_def = def;
#ifdef Py_GIL_DISABLED
((PyModuleObject*)m)->md_gil = gil_slot;
#endif
} else {
if (def->m_size > 0 || def->m_traverse || def->m_clear || def->m_free) {
PyErr_Format(
Expand Down Expand Up @@ -431,18 +434,18 @@ PyModule_FromDefAndSpec2(PyModuleDef* def, PyObject *spec, int module_api_versio
return NULL;
}

#ifdef Py_GIL_DISABLED
int
PyModule_SetGIL(PyObject *module, void *gil)
PyModule_ExperimentalSetGIL(PyObject *module, void *gil)
{
if (!PyModule_Check(module)) {
PyErr_BadInternalCall();
return -1;
}
#ifdef Py_GIL_DISABLED
((PyModuleObject *)module)->md_gil = gil;
#endif
return 0;
}
#endif

int
PyModule_ExecDef(PyObject *module, PyModuleDef *def)
Expand Down