Skip to content

Commit bda62c0

Browse files
miss-islingtonaiskerlend-aasland
authored
[3.11] gh-102468: Document PyCFunction_New* and PyCMethod_New (GH-112557) (GH-114120)
gh-102468: Document `PyCFunction_New*` and `PyCMethod_New` (GH-112557) (cherry picked from commit a482bc6) Co-authored-by: AN Long <[email protected]> Co-authored-by: Erlend E. Aasland <[email protected]>
1 parent 8cb1b79 commit bda62c0

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
@@ -418,6 +418,40 @@ definition with the same method name.
418418
slot. This is helpful because calls to PyCFunctions are optimized more
419419
than wrapper object calls.
420420
421+
.. c:function:: PyObject * PyCMethod_New(PyMethodDef *ml, PyObject *self, PyObject *module, PyTypeObject *cls)
422+
423+
Turn *ml* into a Python :term:`callable` object.
424+
The caller must ensure that *ml* outlives the :term:`callable`.
425+
Typically, *ml* is defined as a static variable.
426+
427+
The *self* parameter will be passed as the *self* argument
428+
to the C function in ``ml->ml_meth`` when invoked.
429+
*self* can be ``NULL``.
430+
431+
The :term:`callable` object's ``__module__`` attribute
432+
can be set from the given *module* argument.
433+
*module* should be a Python string,
434+
which will be used as name of the module the function is defined in.
435+
If unavailable, it can be set to :const:`None` or ``NULL``.
436+
437+
.. seealso:: :attr:`function.__module__`
438+
439+
The *cls* parameter will be passed as the *defining_class*
440+
argument to the C function.
441+
Must be set if :c:macro:`METH_METHOD` is set on ``ml->ml_flags``.
442+
443+
.. versionadded:: 3.9
444+
445+
446+
.. c:function:: PyObject * PyCFunction_NewEx(PyMethodDef *ml, PyObject *self, PyObject *module)
447+
448+
Equivalent to ``PyCMethod_New(ml, self, module, NULL)``.
449+
450+
451+
.. c:function:: PyObject * PyCFunction_New(PyMethodDef *ml, PyObject *self)
452+
453+
Equivalent to ``PyCMethod_New(ml, self, NULL, NULL)``.
454+
421455
422456
Accessing attributes of extension types
423457
---------------------------------------

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)