Skip to content

Commit 0d2d2b8

Browse files
committed
Issue #18668: Properly document setting m_size in PyModuleDef
1 parent 9ae513c commit 0d2d2b8

File tree

1 file changed

+10
-4
lines changed

1 file changed

+10
-4
lines changed

Doc/c-api/module.rst

+10-4
Original file line numberDiff line numberDiff line change
@@ -182,16 +182,22 @@ These functions are usually used in the module initialization function.
182182
183183
.. c:member:: Py_ssize_t m_size
184184
185-
If the module object needs additional memory, this should be set to the
186-
number of bytes to allocate; a pointer to the block of memory can be
187-
retrieved with :c:func:`PyModule_GetState`. If no memory is needed, set
188-
this to ``-1``.
185+
Some modules allow re-initialization (calling their ``PyInit_*`` function
186+
more than once). These modules should keep their state in a per-module
187+
memory area that can be retrieved with :c:func:`PyModule_GetState`.
189188
190189
This memory should be used, rather than static globals, to hold per-module
191190
state, since it is then safe for use in multiple sub-interpreters. It is
192191
freed when the module object is deallocated, after the :c:member:`m_free`
193192
function has been called, if present.
194193
194+
Setting ``m_size`` to a positive value specifies the size of the additional
195+
memory required by the module. Setting it to ``-1`` means that the module can
196+
not be re-initialized because it has global state. Setting it to ``0`` is
197+
forbidden.
198+
199+
See :PEP:`3121` for more details.
200+
195201
.. c:member:: PyMethodDef* m_methods
196202
197203
A pointer to a table of module-level functions, described by

0 commit comments

Comments
 (0)