-
-
Notifications
You must be signed in to change notification settings - Fork 33.8k
Clarify argument/result ownership/validity for PyModule_* functions #141159
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -13,7 +13,7 @@ Module Objects | |
| .. index:: single: ModuleType (in module types) | ||
|
|
||
| This instance of :c:type:`PyTypeObject` represents the Python module type. This | ||
| is exposed to Python programs as ``types.ModuleType``. | ||
| is exposed to Python programs as :py:class:`types.ModuleType`. | ||
|
|
||
|
|
||
| .. c:function:: int PyModule_Check(PyObject *p) | ||
|
|
@@ -71,6 +71,9 @@ Module Objects | |
| ``PyObject_*`` functions rather than directly manipulate a module's | ||
| :attr:`~object.__dict__`. | ||
|
|
||
| The returned reference is borrowed from the module; it is valid until | ||
| the module is destroyed. | ||
|
|
||
|
|
||
| .. c:function:: PyObject* PyModule_GetNameObject(PyObject *module) | ||
|
|
||
|
|
@@ -90,6 +93,10 @@ Module Objects | |
| Similar to :c:func:`PyModule_GetNameObject` but return the name encoded to | ||
| ``'utf-8'``. | ||
|
|
||
| The returned buffer is only valid until the module is renamed or destroyed. | ||
| Note that Python code may rename a module by setting its :py:attr:`~module.__name__` | ||
| attribute. | ||
|
|
||
| .. c:function:: void* PyModule_GetState(PyObject *module) | ||
|
|
||
| Return the "state" of the module, that is, a pointer to the block of memory | ||
|
|
@@ -126,6 +133,9 @@ Module Objects | |
| Similar to :c:func:`PyModule_GetFilenameObject` but return the filename | ||
| encoded to 'utf-8'. | ||
|
|
||
| The returned buffer is only valid until the module's :py:attr:`~module.__file__` attribute | ||
| is reassigned or the module is destroyed. | ||
|
|
||
| .. deprecated:: 3.2 | ||
| :c:func:`PyModule_GetFilename` raises :exc:`UnicodeEncodeError` on | ||
| unencodable filenames, use :c:func:`PyModule_GetFilenameObject` instead. | ||
|
|
@@ -671,6 +681,9 @@ or code that creates modules dynamically. | |
| :c:type:`PyMethodDef` arrays; in that case they should call this function | ||
| directly. | ||
|
|
||
| The *functions* array must be statically allocated (or otherwise guaranteed | ||
| to outlive the module object). | ||
|
Comment on lines
+684
to
+685
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I don't think there is a practical alternative unless you're doing something really special, so I would like keep this footnote-ish -- but part of the same sentence to avoid wording like “as a special exception”.
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Ok, I don't wholly agree, but I won't bother arguing about it. |
||
|
|
||
| .. versionadded:: 3.5 | ||
|
|
||
| .. c:function:: int PyModule_SetDocString(PyObject *module, const char *docstring) | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think it's a little bit confusing to say something must be true, and then immediately contradict it. How about we say something like this?