summaryrefslogtreecommitdiffstats
path: root/Doc/c-api
diff options
context:
space:
mode:
authorMiss Islington (bot) <31488909+miss-islington@users.noreply.github.com>2024-01-17 09:21:08 (GMT)
committerGitHub <noreply@github.com>2024-01-17 09:21:08 (GMT)
commit27941b14ab9ecdb88fe2ced68b50fa428c2ea8f2 (patch)
treeca9b0b6a6f5600e113254b135b7b97f5e2c5f176 /Doc/c-api
parent5af161ffe629dc142d46a48489259ca4a0166ac0 (diff)
downloadcpython-27941b14ab9ecdb88fe2ced68b50fa428c2ea8f2.zip
cpython-27941b14ab9ecdb88fe2ced68b50fa428c2ea8f2.tar.gz
cpython-27941b14ab9ecdb88fe2ced68b50fa428c2ea8f2.tar.bz2
[3.12] gh-102468: Document `PyCFunction_New*` and `PyCMethod_New` (GH-112557) (GH-114119)
gh-102468: Document `PyCFunction_New*` and `PyCMethod_New` (GH-112557) (cherry picked from commit a482bc67ee786e60937a547776fcf9528810e1ce) Co-authored-by: AN Long <aisk@users.noreply.github.com> Co-authored-by: Erlend E. Aasland <erlend.aasland@protonmail.com>
Diffstat (limited to 'Doc/c-api')
-rw-r--r--Doc/c-api/structures.rst34
1 files changed, 34 insertions, 0 deletions
diff --git a/Doc/c-api/structures.rst b/Doc/c-api/structures.rst
index 7d82f78..86c7794 100644
--- a/Doc/c-api/structures.rst
+++ b/Doc/c-api/structures.rst
@@ -399,6 +399,40 @@ definition with the same method name.
slot. This is helpful because calls to PyCFunctions are optimized more
than wrapper object calls.
+.. c:function:: PyObject * PyCMethod_New(PyMethodDef *ml, PyObject *self, PyObject *module, PyTypeObject *cls)
+
+ Turn *ml* into a Python :term:`callable` object.
+ The caller must ensure that *ml* outlives the :term:`callable`.
+ Typically, *ml* is defined as a static variable.
+
+ The *self* parameter will be passed as the *self* argument
+ to the C function in ``ml->ml_meth`` when invoked.
+ *self* can be ``NULL``.
+
+ The :term:`callable` object's ``__module__`` attribute
+ can be set from the given *module* argument.
+ *module* should be a Python string,
+ which will be used as name of the module the function is defined in.
+ If unavailable, it can be set to :const:`None` or ``NULL``.
+
+ .. seealso:: :attr:`function.__module__`
+
+ The *cls* parameter will be passed as the *defining_class*
+ argument to the C function.
+ Must be set if :c:macro:`METH_METHOD` is set on ``ml->ml_flags``.
+
+ .. versionadded:: 3.9
+
+
+.. c:function:: PyObject * PyCFunction_NewEx(PyMethodDef *ml, PyObject *self, PyObject *module)
+
+ Equivalent to ``PyCMethod_New(ml, self, module, NULL)``.
+
+
+.. c:function:: PyObject * PyCFunction_New(PyMethodDef *ml, PyObject *self)
+
+ Equivalent to ``PyCMethod_New(ml, self, NULL, NULL)``.
+
Accessing attributes of extension types
---------------------------------------