diff options
author | Victor Stinner <vstinner@python.org> | 2020-03-17 17:09:46 (GMT) |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-03-17 17:09:46 (GMT) |
commit | 5b1ef200d31a74a9b478d0217d73ed0a659a8a06 (patch) | |
tree | 3a3afde33a456ac49284058c00b1d685c54bcf3c /Doc/c-api/module.rst | |
parent | 52268941f37e3e27bd01792b081877ec3bc9ce12 (diff) | |
download | cpython-5b1ef200d31a74a9b478d0217d73ed0a659a8a06.zip cpython-5b1ef200d31a74a9b478d0217d73ed0a659a8a06.tar.gz cpython-5b1ef200d31a74a9b478d0217d73ed0a659a8a06.tar.bz2 |
bpo-39824: module_traverse() don't call m_traverse if md_state=NULL (GH-18738)
Extension modules: m_traverse, m_clear and m_free functions of
PyModuleDef are no longer called if the module state was requested
but is not allocated yet. This is the case immediately after the
module is created and before the module is executed (Py_mod_exec
function). More precisely, these functions are not called if m_size is
greater than 0 and the module state (as returned by
PyModule_GetState()) is NULL.
Extension modules without module state (m_size <= 0) are not affected.
Co-Authored-By: Petr Viktorin <encukou@gmail.com>
Diffstat (limited to 'Doc/c-api/module.rst')
-rw-r--r-- | Doc/c-api/module.rst | 44 |
1 files changed, 34 insertions, 10 deletions
diff --git a/Doc/c-api/module.rst b/Doc/c-api/module.rst index 57902a9..8d1a0fb 100644 --- a/Doc/c-api/module.rst +++ b/Doc/c-api/module.rst @@ -196,23 +196,47 @@ or request "multi-phase initialization" by returning the definition struct itsel .. c:member:: traverseproc m_traverse A traversal function to call during GC traversal of the module object, or - ``NULL`` if not needed. This function may be called before module state - is allocated (:c:func:`PyModule_GetState()` may return `NULL`), - and before the :c:member:`Py_mod_exec` function is executed. + ``NULL`` if not needed. + + This function is not called if the module state was requested but is not + allocated yet. This is the case immediately after the module is created + and before the module is executed (:c:data:`Py_mod_exec` function). More + precisely, this function is not called if :c:member:`m_size` is greater + than 0 and the module state (as returned by :c:func:`PyModule_GetState`) + is ``NULL``. + + .. versionchanged:: 3.9 + No longer called before the module state is allocated. .. c:member:: inquiry m_clear A clear function to call during GC clearing of the module object, or - ``NULL`` if not needed. This function may be called before module state - is allocated (:c:func:`PyModule_GetState()` may return `NULL`), - and before the :c:member:`Py_mod_exec` function is executed. + ``NULL`` if not needed. + + This function is not called if the module state was requested but is not + allocated yet. This is the case immediately after the module is created + and before the module is executed (:c:data:`Py_mod_exec` function). More + precisely, this function is not called if :c:member:`m_size` is greater + than 0 and the module state (as returned by :c:func:`PyModule_GetState`) + is ``NULL``. + + .. versionchanged:: 3.9 + No longer called before the module state is allocated. .. c:member:: freefunc m_free - A function to call during deallocation of the module object, or ``NULL`` if - not needed. This function may be called before module state - is allocated (:c:func:`PyModule_GetState()` may return `NULL`), - and before the :c:member:`Py_mod_exec` function is executed. + A function to call during deallocation of the module object, or ``NULL`` + if not needed. + + This function is not called if the module state was requested but is not + allocated yet. This is the case immediately after the module is created + and before the module is executed (:c:data:`Py_mod_exec` function). More + precisely, this function is not called if :c:member:`m_size` is greater + than 0 and the module state (as returned by :c:func:`PyModule_GetState`) + is ``NULL``. + + .. versionchanged:: 3.9 + No longer called before the module state is allocated. Single-phase initialization ........................... |