Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit7c3539b

Browse files
miss-islingtonencukouZeroIntensity
authored
[3.14] Clarify argument/result ownership/validity for PyModule_* functions (GH-141159) (GH-141190)
(cherry picked from commitffd6473)Co-authored-by: Petr Viktorin <encukou@gmail.com>Co-authored-by: Peter Bierma <zintensitydev@gmail.com>
1 parentd729087 commit7c3539b

File tree

1 file changed

+14
-1
lines changed

1 file changed

+14
-1
lines changed

‎Doc/c-api/module.rst‎

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ Module Objects
1313
..index::single: ModuleType (in module types)
1414

1515
This instance of:c:type:`PyTypeObject` represents the Python module type. This
16-
is exposed to Python programs as``types.ModuleType``.
16+
is exposed to Python programs as:py:class:`types.ModuleType`.
1717

1818

1919
..c:function::intPyModule_Check(PyObject *p)
@@ -71,6 +71,9 @@ Module Objects
7171
``PyObject_*`` functions rather than directly manipulate a module's
7272
:attr:`~object.__dict__`.
7373
74+
The returned reference is borrowed from the module; it is valid until
75+
the module is destroyed.
76+
7477
7578
..c:function:: PyObject*PyModule_GetNameObject(PyObject *module)
7679
@@ -90,6 +93,10 @@ Module Objects
9093
Similar to:c:func:`PyModule_GetNameObject` but return the name encoded to
9194
``'utf-8'``.
9295
96+
The returned buffer is only valid until the module is renamed or destroyed.
97+
Note that Python code may rename a module by setting its:py:attr:`~module.__name__`
98+
attribute.
99+
93100
..c:function::void*PyModule_GetState(PyObject *module)
94101
95102
Return the "state" of the module, that is, a pointer to the block of memory
@@ -126,6 +133,9 @@ Module Objects
126133
Similar to:c:func:`PyModule_GetFilenameObject` but return the filename
127134
encoded to 'utf-8'.
128135
136+
The returned buffer is only valid until the module's:py:attr:`~module.__file__` attribute
137+
is reassigned or the module is destroyed.
138+
129139
..deprecated::3.2
130140
:c:func:`PyModule_GetFilename` raises:exc:`UnicodeEncodeError` on
131141
unencodable filenames, use:c:func:`PyModule_GetFilenameObject` instead.
@@ -649,6 +659,9 @@ or code that creates modules dynamically.
649659
:c:type:`PyMethodDef` arrays; in thatcase they should call this function
650660
directly.
651661
662+
The *functions* array must be statically allocated (or otherwise guaranteed
663+
to outlive the module object).
664+
652665
.. versionadded:: 3.5
653666
654667
.. c:function:: int PyModule_SetDocString(PyObject *module, const char *docstring)

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp