mirror of
https://github.com/python/cpython.git
synced 2025-08-04 00:48:58 +00:00
bpo-38787: C API for module state access from extension methods (PEP 573) (GH-19936)
Module C state is now accessible from C-defined heap type methods (PEP 573). Patch by Marcel Plch and Petr Viktorin. Co-authored-by: Marcel Plch <mplch@redhat.com> Co-authored-by: Victor Stinner <vstinner@python.org>
This commit is contained in:
parent
4638c64295
commit
e1becf46b4
19 changed files with 797 additions and 51 deletions
|
@ -147,23 +147,56 @@ Implementing functions and methods
|
|||
value of the function as exposed in Python. The function must return a new
|
||||
reference.
|
||||
|
||||
The function signature is::
|
||||
|
||||
PyObject *PyCFunction(PyObject *self,
|
||||
PyObject *const *args);
|
||||
|
||||
.. c:type:: PyCFunctionWithKeywords
|
||||
|
||||
Type of the functions used to implement Python callables in C
|
||||
with signature :const:`METH_VARARGS | METH_KEYWORDS`.
|
||||
The function signature is::
|
||||
|
||||
PyObject *PyCFunctionWithKeywords(PyObject *self,
|
||||
PyObject *const *args,
|
||||
PyObject *kwargs);
|
||||
|
||||
|
||||
.. c:type:: _PyCFunctionFast
|
||||
|
||||
Type of the functions used to implement Python callables in C
|
||||
with signature :const:`METH_FASTCALL`.
|
||||
The function signature is::
|
||||
|
||||
PyObject *_PyCFunctionFast(PyObject *self,
|
||||
PyObject *const *args,
|
||||
Py_ssize_t nargs);
|
||||
|
||||
.. c:type:: _PyCFunctionFastWithKeywords
|
||||
|
||||
Type of the functions used to implement Python callables in C
|
||||
with signature :const:`METH_FASTCALL | METH_KEYWORDS`.
|
||||
The function signature is::
|
||||
|
||||
PyObject *_PyCFunctionFastWithKeywords(PyObject *self,
|
||||
PyObject *const *args,
|
||||
Py_ssize_t nargs,
|
||||
PyObject *kwnames);
|
||||
|
||||
.. c:type:: PyCMethod
|
||||
|
||||
Type of the functions used to implement Python callables in C
|
||||
with signature :const:`METH_METHOD | METH_FASTCALL | METH_KEYWORDS`.
|
||||
The function signature is::
|
||||
|
||||
PyObject *PyCMethod(PyObject *self,
|
||||
PyTypeObject *defining_class,
|
||||
PyObject *const *args,
|
||||
Py_ssize_t nargs,
|
||||
PyObject *kwnames)
|
||||
|
||||
.. versionadded:: 3.9
|
||||
|
||||
|
||||
.. c:type:: PyMethodDef
|
||||
|
@ -197,9 +230,7 @@ The :attr:`ml_flags` field is a bitfield which can include the following flags.
|
|||
The individual flags indicate either a calling convention or a binding
|
||||
convention.
|
||||
|
||||
There are four basic calling conventions for positional arguments
|
||||
and two of them can be combined with :const:`METH_KEYWORDS` to support
|
||||
also keyword arguments. So there are a total of 6 calling conventions:
|
||||
There are these calling conventions:
|
||||
|
||||
.. data:: METH_VARARGS
|
||||
|
||||
|
@ -250,6 +281,19 @@ also keyword arguments. So there are a total of 6 calling conventions:
|
|||
.. versionadded:: 3.7
|
||||
|
||||
|
||||
.. data:: METH_METHOD | METH_FASTCALL | METH_KEYWORDS
|
||||
|
||||
Extension of :const:`METH_FASTCALL | METH_KEYWORDS` supporting the *defining
|
||||
class*, that is, the class that contains the method in question.
|
||||
The defining class might be a superclass of ``Py_TYPE(self)``.
|
||||
|
||||
The method needs to be of type :c:type:`PyCMethod`, the same as for
|
||||
``METH_FASTCALL | METH_KEYWORDS`` with ``defining_class`` argument added after
|
||||
``self``.
|
||||
|
||||
.. versionadded:: 3.9
|
||||
|
||||
|
||||
.. data:: METH_NOARGS
|
||||
|
||||
Methods without parameters don't need to check whether arguments are given if
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue