Skip to content

Commit 135a4d7

Browse files
aiskerlend-aasland
authored andcommitted
pythongh-102468: Document PyCFunction_New* and PyCMethod_New (pythonGH-112557)
Co-authored-by: Erlend E. Aasland <[email protected]>
1 parent 12c03d5 commit 135a4d7

File tree

2 files changed

+49
-0
lines changed

2 files changed

+49
-0
lines changed

Doc/c-api/structures.rst

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -399,6 +399,40 @@ definition with the same method name.
399399
slot. This is helpful because calls to PyCFunctions are optimized more
400400
than wrapper object calls.
401401
402+
.. c:function:: PyObject * PyCMethod_New(PyMethodDef *ml, PyObject *self, PyObject *module, PyTypeObject *cls)
403+
404+
Turn *ml* into a Python :term:`callable` object.
405+
The caller must ensure that *ml* outlives the :term:`callable`.
406+
Typically, *ml* is defined as a static variable.
407+
408+
The *self* parameter will be passed as the *self* argument
409+
to the C function in ``ml->ml_meth`` when invoked.
410+
*self* can be ``NULL``.
411+
412+
The :term:`callable` object's ``__module__`` attribute
413+
can be set from the given *module* argument.
414+
*module* should be a Python string,
415+
which will be used as name of the module the function is defined in.
416+
If unavailable, it can be set to :const:`None` or ``NULL``.
417+
418+
.. seealso:: :attr:`function.__module__`
419+
420+
The *cls* parameter will be passed as the *defining_class*
421+
argument to the C function.
422+
Must be set if :c:macro:`METH_METHOD` is set on ``ml->ml_flags``.
423+
424+
.. versionadded:: 3.9
425+
426+
427+
.. c:function:: PyObject * PyCFunction_NewEx(PyMethodDef *ml, PyObject *self, PyObject *module)
428+
429+
Equivalent to ``PyCMethod_New(ml, self, module, NULL)``.
430+
431+
432+
.. c:function:: PyObject * PyCFunction_New(PyMethodDef *ml, PyObject *self)
433+
434+
Equivalent to ``PyCMethod_New(ml, self, NULL, NULL)``.
435+
402436
403437
Accessing attributes of extension types
404438
---------------------------------------

Doc/data/refcounts.dat

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -402,6 +402,21 @@ PyContextVar_Reset:int:::
402402
PyContextVar_Reset:PyObject*:var:0:
403403
PyContextVar_Reset:PyObject*:token:-1:
404404

405+
PyCFunction_New:PyObject*::+1:
406+
PyCFunction_New:PyMethodDef*:ml::
407+
PyCFunction_New:PyObject*:self:+1:
408+
409+
PyCFunction_NewEx:PyObject*::+1:
410+
PyCFunction_NewEx:PyMethodDef*:ml::
411+
PyCFunction_NewEx:PyObject*:self:+1:
412+
PyCFunction_NewEx:PyObject*:module:+1:
413+
414+
PyCMethod_New:PyObject*::+1:
415+
PyCMethod_New:PyMethodDef*:ml::
416+
PyCMethod_New:PyObject*:self:+1:
417+
PyCMethod_New:PyObject*:module:+1:
418+
PyCMethod_New:PyObject*:cls:+1:
419+
405420
PyDate_Check:int:::
406421
PyDate_Check:PyObject*:ob:0:
407422

0 commit comments

Comments
 (0)