Skip to content

Commit e6f429c

Browse files
miss-islingtonZeroIntensitypicnixz
authored
[3.13] gh-141004: Document missing PyCFunction* and PyCMethod* APIs (GH-141253) (GH-141638)
gh-141004: Document missing `PyCFunction*` and `PyCMethod*` APIs (GH-141253) (cherry picked from commit be699d6) Co-authored-by: Peter Bierma <zintensitydev@gmail.com> Co-authored-by: Bénédikt Tran <10796600+picnixz@users.noreply.github.com>
1 parent 7b5c65a commit e6f429c

File tree

1 file changed

+93
-0
lines changed

1 file changed

+93
-0
lines changed

Doc/c-api/structures.rst

Lines changed: 93 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -404,6 +404,25 @@ definition with the same method name.
404404
slot. This is helpful because calls to PyCFunctions are optimized more
405405
than wrapper object calls.
406406
407+
408+
.. c:var:: PyTypeObject PyCMethod_Type
409+
410+
The type object corresponding to Python C method objects. This is
411+
available as :class:`types.BuiltinMethodType` in the Python layer.
412+
413+
414+
.. c:function:: int PyCMethod_Check(PyObject *op)
415+
416+
Return true if *op* is an instance of the :c:type:`PyCMethod_Type` type
417+
or a subtype of it. This function always succeeds.
418+
419+
420+
.. c:function:: int PyCMethod_CheckExact(PyObject *op)
421+
422+
This is the same as :c:func:`PyCMethod_Check`, but does not account for
423+
subtypes.
424+
425+
407426
.. c:function:: PyObject * PyCMethod_New(PyMethodDef *ml, PyObject *self, PyObject *module, PyTypeObject *cls)
408427
409428
Turn *ml* into a Python :term:`callable` object.
@@ -429,6 +448,24 @@ definition with the same method name.
429448
.. versionadded:: 3.9
430449
431450
451+
.. c:var:: PyTypeObject PyCFunction_Type
452+
453+
The type object corresponding to Python C function objects. This is
454+
available as :class:`types.BuiltinFunctionType` in the Python layer.
455+
456+
457+
.. c:function:: int PyCFunction_Check(PyObject *op)
458+
459+
Return true if *op* is an instance of the :c:type:`PyCFunction_Type` type
460+
or a subtype of it. This function always succeeds.
461+
462+
463+
.. c:function:: int PyCFunction_CheckExact(PyObject *op)
464+
465+
This is the same as :c:func:`PyCFunction_Check`, but does not account for
466+
subtypes.
467+
468+
432469
.. c:function:: PyObject * PyCFunction_NewEx(PyMethodDef *ml, PyObject *self, PyObject *module)
433470
434471
Equivalent to ``PyCMethod_New(ml, self, module, NULL)``.
@@ -439,6 +476,62 @@ definition with the same method name.
439476
Equivalent to ``PyCMethod_New(ml, self, NULL, NULL)``.
440477
441478
479+
.. c:function:: int PyCFunction_GetFlags(PyObject *func)
480+
481+
Get the function's flags on *func* as they were passed to
482+
:c:member:`~PyMethodDef.ml_flags`.
483+
484+
If *func* is not a C function object, this fails with an exception.
485+
*func* must not be ``NULL``.
486+
487+
This function returns the function's flags on success, and ``-1`` with an
488+
exception set on failure.
489+
490+
491+
.. c:function:: int PyCFunction_GET_FLAGS(PyObject *func)
492+
493+
This is the same as :c:func:`PyCFunction_GetFlags`, but without error
494+
or type checking.
495+
496+
497+
.. c:function:: PyCFunction PyCFunction_GetFunction(PyObject *func)
498+
499+
Get the function pointer on *func* as it was passed to
500+
:c:member:`~PyMethodDef.ml_meth`.
501+
502+
If *func* is not a C function object, this fails with an exception.
503+
*func* must not be ``NULL``.
504+
505+
This function returns the function pointer on success, and ``NULL`` with an
506+
exception set on failure.
507+
508+
509+
.. c:function:: int PyCFunction_GET_FUNCTION(PyObject *func)
510+
511+
This is the same as :c:func:`PyCFunction_GetFunction`, but without error
512+
or type checking.
513+
514+
515+
.. c:function:: PyObject *PyCFunction_GetSelf(PyObject *func)
516+
517+
Get the "self" object on *func*. This is the object that would be passed
518+
to the first argument of a :c:type:`PyCFunction`. For C function objects
519+
created through a :c:type:`PyMethodDef` on a :c:type:`PyModuleDef`, this
520+
is the resulting module object.
521+
522+
If *func* is not a C function object, this fails with an exception.
523+
*func* must not be ``NULL``.
524+
525+
This function returns a :term:`borrowed reference` to the "self" object
526+
on success, and ``NULL`` with an exception set on failure.
527+
528+
529+
.. c:function:: PyObject *PyCFunction_GET_SELF(PyObject *func)
530+
531+
This is the same as :c:func:`PyCFunction_GetSelf`, but without error or
532+
type checking.
533+
534+
442535
Accessing attributes of extension types
443536
---------------------------------------
444537

0 commit comments

Comments
 (0)