From 92c132569f7e5ae3bda5fb944728f28a9be5e1e2 Mon Sep 17 00:00:00 2001 From: messense Date: Sat, 26 Mar 2022 20:41:05 +0800 Subject: [PATCH 1/4] Add FFI definitions for PEP 573 functions --- pyo3-ffi/src/object.rs | 18 +++++++++++++++--- 1 file changed, 15 insertions(+), 3 deletions(-) diff --git a/pyo3-ffi/src/object.rs b/pyo3-ffi/src/object.rs index 7db82a42..408ce861 100644 --- a/pyo3-ffi/src/object.rs +++ b/pyo3-ffi/src/object.rs @@ -205,9 +205,21 @@ extern "C" { #[cfg_attr(PyPy, link_name = "PyPyType_GetSlot")] pub fn PyType_GetSlot(arg1: *mut PyTypeObject, arg2: c_int) -> *mut c_void; - // skipped non-limited / 3.9 PyType_FromModuleAndSpec - // skipped non-limited / 3.9 PyType_GetModule - // skipped non-limited / 3.9 PyType_GetModuleState + #[cfg(any(Py_3_10, all(Py_3_9, not(Py_LIMITED_API))))] + #[cfg_attr(PyPy, link_name = "PyPyType_FromModuleAndSpec")] + pub fn PyType_FromModuleAndSpec( + module: *mut PyObject, + spec: *mut PyType_Spec, + bases: *mut PyObject, + ) -> *mut PyObject; + + #[cfg(any(Py_3_10, all(Py_3_9, not(Py_LIMITED_API))))] + #[cfg_attr(PyPy, link_name = "PyPyType_GetModule")] + pub fn PyType_GetModule(arg1: *mut PyTypeObject) -> *mut PyObject; + + #[cfg(any(Py_3_10, all(Py_3_9, not(Py_LIMITED_API))))] + #[cfg_attr(PyPy, link_name = "PyPyType_GetModuleState")] + pub fn PyType_GetModuleState(arg1: *mut PyTypeObject) -> *mut c_void; } extern "C" { From f3f0a612d80dcc08b707bf7195bbf8e76b49fdee Mon Sep 17 00:00:00 2001 From: messense Date: Sat, 26 Mar 2022 20:50:26 +0800 Subject: [PATCH 2/4] Add FFI definition for `PyModule_AddType` --- pyo3-ffi/src/modsupport.rs | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/pyo3-ffi/src/modsupport.rs b/pyo3-ffi/src/modsupport.rs index fc0815a4..fa234016 100644 --- a/pyo3-ffi/src/modsupport.rs +++ b/pyo3-ffi/src/modsupport.rs @@ -77,7 +77,12 @@ extern "C" { name: *const c_char, value: *const c_char, ) -> c_int; - // skipped non-limited / 3.9 PyModule_AddType + #[cfg(any(Py_3_10, all(Py_3_9, not(Py_LIMITED_API))))] + #[cfg_attr(PyPy, link_name = "PyPyModule_AddType")] + pub fn PyModule_AddType( + module: *mut PyObject, + type_: *mut crate::object::PyTypeObject, + ) -> c_int; // skipped PyModule_AddIntMacro // skipped PyModule_AddStringMacro pub fn PyModule_SetDocString(arg1: *mut PyObject, arg2: *const c_char) -> c_int; From 23e220985af786bda171f7d2b991e47e00d68b01 Mon Sep 17 00:00:00 2001 From: messense Date: Sat, 26 Mar 2022 20:54:16 +0800 Subject: [PATCH 3/4] Mark `METH_FASTCALL` as limited API on Python 3.10+ https://github.com/python/cpython/commit/0b9c4c6fcf2b0673fa45ddfa092934a9d5479b8c#diff-adb492ab0eb13648d50d0d79e4b6e5517b27f983ab3b21b63e77f54132c98e9dR76 --- pyo3-ffi/src/methodobject.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pyo3-ffi/src/methodobject.rs b/pyo3-ffi/src/methodobject.rs index 72052735..d0afa6f5 100644 --- a/pyo3-ffi/src/methodobject.rs +++ b/pyo3-ffi/src/methodobject.rs @@ -179,7 +179,7 @@ pub const METH_COEXIST: c_int = 0x0040; /* METH_FASTCALL indicates the PEP 590 Vectorcall calling format. It may be specified alone or with METH_KEYWORDS. */ -#[cfg(not(Py_LIMITED_API))] +#[cfg(any(Py_3_10, not(Py_LIMITED_API)))] pub const METH_FASTCALL: c_int = 0x0080; // skipped METH_STACKLESS From 733a2c68f5284ffcb872ddd3113a76e2d9f17993 Mon Sep 17 00:00:00 2001 From: messense Date: Sat, 26 Mar 2022 21:27:31 +0800 Subject: [PATCH 4/4] Update changelog entry --- CHANGELOG.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 341ff240..60bba62f 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -12,10 +12,12 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 - Allow dependent crates to access config values from `pyo3-build-config` via cargo link dep env vars. [#2092](https://github.com/PyO3/pyo3/pull/2092) - Added methods on `InterpreterConfig` to run Python scripts using the configured executable. [#2092](https://github.com/PyO3/pyo3/pull/2092) +- Added FFI definitions for `PyType_FromModuleAndSpec`, `PyType_GetModule`, `PyType_GetModuleState` and `PyModule_AddType`. [#2250](https://github.com/PyO3/pyo3/pull/2250) ### Changed - Allow `#[pyo3(crate = "...", text_signature = "...")]` options to be used directly in `#[pyclass(crate = "...", text_signature = "...")]`. [#2234](https://github.com/PyO3/pyo3/pull/2234) +- Mark `METH_FASTCALL` calling convention as limited API on Python 3.10. [#2250](https://github.com/PyO3/pyo3/pull/2250) ### Fixed