-
-
Notifications
You must be signed in to change notification settings - Fork 34.5k
bpo-38787: C API for module state access from extension methods (PEP 573) #19936
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
Merged
Merged
Changes from 1 commit
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
e47e21e
Include/methodobject.h: Move Py_LIMITED_API declarations to cpython/
encukou 0741598
Add ht_module to classes
d7c3551
Add PyType_GetModule and PyType_GetModuleState accessors
856f0a3
Add PyCMethod_* and machinery to call it
3053c42
Add defining_class converter to Clinic
c807aef
Add NEWS blurb
encukou 3e1aa3d
Add tests: with clinic and without clinic
a17a565
Add documentation for PEP 573
encukou f105aff
Update PEP link in NEWS entry
encukou File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Add documentation for PEP 573
Also adds the signatures for PyCFunction*: these were not summarized in the docs; instead and they were defined in prose with references to simpler signatures. That is hard to read.
- Loading branch information
commit a17a56500e6d2fddd352a709807489f222a7f8c6
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -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, | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Dittio. |
||
| 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 | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Inconsistent argument type compared to
typedef PyObject *(*PyCFunction)(PyObject *, PyObject *);https://github.com/python/cpython/blob/master/Include/methodobject.h#L18