Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 7533137

Browse files
committed
Closing #18668: Properly document setting m_size in PyModuleDef
2 parents 236a547 + 0d2d2b8 commit 7533137

1 file changed

Lines changed: 10 additions & 4 deletions

File tree

Doc/c-api/module.rst

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -189,16 +189,22 @@ These functions are usually used in the module initialization function.
189189
190190
.. c:member:: Py_ssize_t m_size
191191
192-
If the module object needs additional memory, this should be set to the
193-
number of bytes to allocate; a pointer to the block of memory can be
194-
retrieved with :c:func:`PyModule_GetState`. If no memory is needed, set
195-
this to ``-1``.
192+
Some modules allow re-initialization (calling their ``PyInit_*`` function
193+
more than once). These modules should keep their state in a per-module
194+
memory area that can be retrieved with :c:func:`PyModule_GetState`.
196195
197196
This memory should be used, rather than static globals, to hold per-module
198197
state, since it is then safe for use in multiple sub-interpreters. It is
199198
freed when the module object is deallocated, after the :c:member:`m_free`
200199
function has been called, if present.
201200
201+
Setting ``m_size`` to a positive value specifies the size of the additional
202+
memory required by the module. Setting it to ``-1`` means that the module can
203+
not be re-initialized because it has global state. Setting it to ``0`` is
204+
forbidden.
205+
206+
See :PEP:`3121` for more details.
207+
202208
.. c:member:: PyMethodDef* m_methods
203209
204210
A pointer to a table of module-level functions, described by

0 commit comments

Comments
 (0)