From 36ac916f8071fab7bd5da20d84bb08cab73a2815 Mon Sep 17 00:00:00 2001 From: Petr Viktorin Date: Wed, 21 Oct 2020 19:44:58 +0200 Subject: [PATCH 1/5] Add PEP 573 functions and PyModule_AddType to Windows stable ABI --- PC/python3dll.c | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/PC/python3dll.c b/PC/python3dll.c index 7e4a510177304d1..dc57d3fef4c3581 100644 --- a/PC/python3dll.c +++ b/PC/python3dll.c @@ -342,6 +342,7 @@ EXPORT_FUNC(PyModule_AddFunctions) EXPORT_FUNC(PyModule_AddIntConstant) EXPORT_FUNC(PyModule_AddObject) EXPORT_FUNC(PyModule_AddStringConstant) +EXPORT_FUNC(PyModule_AddType) EXPORT_FUNC(PyModule_Create2) EXPORT_FUNC(PyModule_ExecDef) EXPORT_FUNC(PyModule_FromDefAndSpec2) @@ -545,9 +546,12 @@ EXPORT_FUNC(PyTuple_Size) EXPORT_FUNC(PyType_ClearCache) EXPORT_FUNC(PyType_FromSpec) EXPORT_FUNC(PyType_FromSpecWithBases) +EXPORT_FUNC(PyType_FromModuleAndSpec) EXPORT_FUNC(PyType_GenericAlloc) EXPORT_FUNC(PyType_GenericNew) EXPORT_FUNC(PyType_GetFlags) +EXPORT_FUNC(PyType_GetModule) +EXPORT_FUNC(PyType_GetModuleState) EXPORT_FUNC(PyType_GetSlot) EXPORT_FUNC(PyType_IsSubtype) EXPORT_FUNC(PyType_Modified) From aabe38c6eb21f9c70b30acb7deb404794e620278 Mon Sep 17 00:00:00 2001 From: Petr Viktorin Date: Wed, 21 Oct 2020 20:59:58 +0200 Subject: [PATCH 2/5] Add METH_METHOD_ARGS_KWD for the limited API --- Doc/c-api/structures.rst | 6 ++++-- Include/methodobject.h | 6 ++++++ 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/Doc/c-api/structures.rst b/Doc/c-api/structures.rst index a9e1c6fbcc3f943..6e23be677ac95d4 100644 --- a/Doc/c-api/structures.rst +++ b/Doc/c-api/structures.rst @@ -191,7 +191,7 @@ Implementing functions and methods .. c:type:: PyCMethod Type of the functions used to implement Python callables in C - with signature :const:`METH_METHOD | METH_FASTCALL | METH_KEYWORDS`. + with signature :const:`METH_METHOD_ARGS_KWD`. The function signature is:: PyObject *PyCMethod(PyObject *self, @@ -285,7 +285,9 @@ There are these calling conventions: .. versionadded:: 3.7 -.. data:: METH_METHOD | METH_FASTCALL | METH_KEYWORDS +.. data:: METH_METHOD_ARGS_KWD + + Equivalent to ``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. diff --git a/Include/methodobject.h b/Include/methodobject.h index 12e049b4043ba59..f3776fe61af22da 100644 --- a/Include/methodobject.h +++ b/Include/methodobject.h @@ -89,11 +89,17 @@ PyAPI_FUNC(PyObject *) PyCMethod_New(PyMethodDef *, PyObject *, * both self and class are passed to it. * It uses PyCMethodObject instead of PyCFunctionObject. * May not be combined with METH_NOARGS, METH_O, METH_CLASS or METH_STATIC. + * + * METH_METHOD_ARGS_KWD exports a specific combination of flags + * for the limited API. */ #if !defined(Py_LIMITED_API) || Py_LIMITED_API+0 >= 0x03090000 #define METH_METHOD 0x0200 #endif +#if !defined(Py_LIMITED_API) || Py_LIMITED_API+0 >= 0x03100000 +#define METH_METHOD_ARGS_KWD (METH_METHOD | 0x0080 | METH_KEYWORDS) +#endif #ifndef Py_LIMITED_API From e66701551cebb86ac99b5f87522e9f470430f994 Mon Sep 17 00:00:00 2001 From: Petr Viktorin Date: Tue, 27 Oct 2020 21:10:22 +0100 Subject: [PATCH 3/5] Add a blurb --- .../next/C API/2020-10-27-21-10-14.bpo-42171.S3FWTP.rst | 5 +++++ 1 file changed, 5 insertions(+) create mode 100644 Misc/NEWS.d/next/C API/2020-10-27-21-10-14.bpo-42171.S3FWTP.rst diff --git a/Misc/NEWS.d/next/C API/2020-10-27-21-10-14.bpo-42171.S3FWTP.rst b/Misc/NEWS.d/next/C API/2020-10-27-21-10-14.bpo-42171.S3FWTP.rst new file mode 100644 index 000000000000000..16b0b49d2c72cde --- /dev/null +++ b/Misc/NEWS.d/next/C API/2020-10-27-21-10-14.bpo-42171.S3FWTP.rst @@ -0,0 +1,5 @@ +The :c:data:`METH_METHOD_ARGS_KWD` calling convention is added to allow +using :pep:`573` module state access from methods fron the limited API. The +functions :c:func:`PyModule_AddType`, :c:func:`PyType_FromModuleAndSpec`, +:c:func:`PyType_GetModule` and :c:func:`PyType_GetModuleState` are added to +the limited API on Windows. From ba438289b23a8fe98093e5b5b8f95936c608aa4c Mon Sep 17 00:00:00 2001 From: Petr Viktorin Date: Tue, 3 Nov 2020 23:54:50 +0100 Subject: [PATCH 4/5] Revert "Add METH_METHOD_ARGS_KWD for the limited API" This reverts commit aabe38c6eb21f9c70b30acb7deb404794e620278. --- Doc/c-api/structures.rst | 6 ++---- Include/methodobject.h | 6 ------ 2 files changed, 2 insertions(+), 10 deletions(-) diff --git a/Doc/c-api/structures.rst b/Doc/c-api/structures.rst index 6e23be677ac95d4..a9e1c6fbcc3f943 100644 --- a/Doc/c-api/structures.rst +++ b/Doc/c-api/structures.rst @@ -191,7 +191,7 @@ Implementing functions and methods .. c:type:: PyCMethod Type of the functions used to implement Python callables in C - with signature :const:`METH_METHOD_ARGS_KWD`. + with signature :const:`METH_METHOD | METH_FASTCALL | METH_KEYWORDS`. The function signature is:: PyObject *PyCMethod(PyObject *self, @@ -285,9 +285,7 @@ There are these calling conventions: .. versionadded:: 3.7 -.. data:: METH_METHOD_ARGS_KWD - - Equivalent to ``METH_METHOD | METH_FASTCALL | METH_KEYWORDS``. +.. 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. diff --git a/Include/methodobject.h b/Include/methodobject.h index f3776fe61af22da..12e049b4043ba59 100644 --- a/Include/methodobject.h +++ b/Include/methodobject.h @@ -89,17 +89,11 @@ PyAPI_FUNC(PyObject *) PyCMethod_New(PyMethodDef *, PyObject *, * both self and class are passed to it. * It uses PyCMethodObject instead of PyCFunctionObject. * May not be combined with METH_NOARGS, METH_O, METH_CLASS or METH_STATIC. - * - * METH_METHOD_ARGS_KWD exports a specific combination of flags - * for the limited API. */ #if !defined(Py_LIMITED_API) || Py_LIMITED_API+0 >= 0x03090000 #define METH_METHOD 0x0200 #endif -#if !defined(Py_LIMITED_API) || Py_LIMITED_API+0 >= 0x03100000 -#define METH_METHOD_ARGS_KWD (METH_METHOD | 0x0080 | METH_KEYWORDS) -#endif #ifndef Py_LIMITED_API From 1b1ca477d3994192120ecc7891ee3cc2332a9d1f Mon Sep 17 00:00:00 2001 From: Petr Viktorin Date: Tue, 3 Nov 2020 23:58:40 +0100 Subject: [PATCH 5/5] Add METH_FASTCALL to the limited API --- Doc/c-api/structures.rst | 6 ++++-- Include/methodobject.h | 2 +- .../next/C API/2020-10-27-21-10-14.bpo-42171.S3FWTP.rst | 5 ++--- 3 files changed, 7 insertions(+), 6 deletions(-) diff --git a/Doc/c-api/structures.rst b/Doc/c-api/structures.rst index a9e1c6fbcc3f943..eb8a0f2de7221f5 100644 --- a/Doc/c-api/structures.rst +++ b/Doc/c-api/structures.rst @@ -263,10 +263,12 @@ There are these calling conventions: of :c:type:`PyObject*` values indicating the arguments and the third parameter is the number of arguments (the length of the array). - This is not part of the :ref:`limited API `. - .. versionadded:: 3.7 + .. versionchanged:: 3.10 + + ``METH_FASTCALL`` is now part of the stable ABI. + .. data:: METH_FASTCALL | METH_KEYWORDS diff --git a/Include/methodobject.h b/Include/methodobject.h index 12e049b4043ba59..5d06d7691ba324a 100644 --- a/Include/methodobject.h +++ b/Include/methodobject.h @@ -73,7 +73,7 @@ PyAPI_FUNC(PyObject *) PyCMethod_New(PyMethodDef *, PyObject *, #define METH_COEXIST 0x0040 -#ifndef Py_LIMITED_API +#if !defined(Py_LIMITED_API) || Py_LIMITED_API+0 >= 0x03100000 #define METH_FASTCALL 0x0080 #endif diff --git a/Misc/NEWS.d/next/C API/2020-10-27-21-10-14.bpo-42171.S3FWTP.rst b/Misc/NEWS.d/next/C API/2020-10-27-21-10-14.bpo-42171.S3FWTP.rst index 16b0b49d2c72cde..5dfbb23a6a39a4d 100644 --- a/Misc/NEWS.d/next/C API/2020-10-27-21-10-14.bpo-42171.S3FWTP.rst +++ b/Misc/NEWS.d/next/C API/2020-10-27-21-10-14.bpo-42171.S3FWTP.rst @@ -1,5 +1,4 @@ -The :c:data:`METH_METHOD_ARGS_KWD` calling convention is added to allow -using :pep:`573` module state access from methods fron the limited API. The -functions :c:func:`PyModule_AddType`, :c:func:`PyType_FromModuleAndSpec`, +The :c:data:`METH_FASTCALL` calling convention is added to the limited API. +The functions :c:func:`PyModule_AddType`, :c:func:`PyType_FromModuleAndSpec`, :c:func:`PyType_GetModule` and :c:func:`PyType_GetModuleState` are added to the limited API on Windows.