Skip to content

Commit

Permalink
Merge pull request #2250 from messense/pep573-fns
Browse files Browse the repository at this point in the history
Add FFI definitions for PEP 573 functions
  • Loading branch information
davidhewitt committed Mar 28, 2022
2 parents 9dca5cf + 733a2c6 commit de06057
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 5 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Expand Up @@ -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

Expand Down
2 changes: 1 addition & 1 deletion pyo3-ffi/src/methodobject.rs
Expand Up @@ -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
Expand Down
7 changes: 6 additions & 1 deletion pyo3-ffi/src/modsupport.rs
Expand Up @@ -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;
Expand Down
18 changes: 15 additions & 3 deletions pyo3-ffi/src/object.rs
Expand Up @@ -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" {
Expand Down

0 comments on commit de06057

Please sign in to comment.