Skip to content
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

gh-102468: Document PyCFunction_New* and PyCMethod_New #112557

Merged
merged 23 commits into from
Jan 16, 2024
Merged
Show file tree
Hide file tree
Changes from 11 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 31 additions & 0 deletions Doc/c-api/structures.rst
Original file line number Diff line number Diff line change
Expand Up @@ -399,6 +399,37 @@ definition with the same method name.
slot. This is helpful because calls to PyCFunctions are optimized more
than wrapper object calls.

.. c:function:: PyObject * PyCFunction_New(PyMethodDef *ml, PyObject *self)

Turn *ml* into a Python callable object. The *self* parameter will be
aisk marked this conversation as resolved.
Show resolved Hide resolved
passed as *self* parameter to the C function in ``ml->ml_meth`` when
invoked, can be ``NULL``.
aisk marked this conversation as resolved.
Show resolved Hide resolved

.. note::

This function "steals" a reference to *ml*.
aisk marked this conversation as resolved.
Show resolved Hide resolved

.. c:function:: PyObject * PyCFunction_NewEx(PyMethodDef *ml, PyObject *self, PyObject *module)

Same as :c:func:`PyCFunction_New`, but also allows setting the function
object's ``__module__`` attribute. :attr:`!__module__` should be the name
of the module the function is defined in or ``None`` if unavailable.
See :attr:`function.__module__`.
aisk marked this conversation as resolved.
Show resolved Hide resolved

.. note::

This function "steals" a reference to *ml*.
aisk marked this conversation as resolved.
Show resolved Hide resolved

.. c:function:: PyObject * PyCMethod_New(PyMethodDef *ml, PyObject *self, PyObject *module, PyTypeObject *cls)

Same as :c:func:`PyCFunction_NewEx`, but accept a **cls** parameter, which
will be passed as ``defining_class`` parameter to the C function. Must be
set if :c:macro:`METH_METHOD` is set on ``ml->ml_flags``.
aisk marked this conversation as resolved.
Show resolved Hide resolved

.. note::

This function "steals" a reference to *ml*.
aisk marked this conversation as resolved.
Show resolved Hide resolved


Accessing attributes of extension types
---------------------------------------
Expand Down
15 changes: 15 additions & 0 deletions Doc/data/refcounts.dat
Original file line number Diff line number Diff line change
Expand Up @@ -402,6 +402,21 @@ PyContextVar_Reset:int:::
PyContextVar_Reset:PyObject*:var:0:
PyContextVar_Reset:PyObject*:token:-1:

PyCFunction_New:PyObject*::+1:
PyCFunction_New:PyObject*:ml:0:
aisk marked this conversation as resolved.
Show resolved Hide resolved
PyCFunction_New:PyObject*:self:+1:

PyCFunction_NewEx:PyObject*::+1:
PyCFunction_NewEx:PyObject*:ml:0:
aisk marked this conversation as resolved.
Show resolved Hide resolved
PyCFunction_NewEx:PyObject*:self:+1:
PyCFunction_NewEx:PyObject*:module:+1:

PyCMethod_New:PyObject*::+1:
PyCMethod_New:PyObject*:ml:0:
aisk marked this conversation as resolved.
Show resolved Hide resolved
PyCMethod_New:PyObject*:self:+1:
PyCMethod_New:PyObject*:module:+1:
PyCMethod_New:PyObject*:cls:+1:

PyDate_Check:int:::
PyDate_Check:PyObject*:ob:0:

Expand Down
Loading