Skip to content

Commit

Permalink
Merge pull request #3295 from davidhewitt/pypy-pystate
Browse files Browse the repository at this point in the history
add PyState_*Module definitions for PyPy
  • Loading branch information
davidhewitt authored Jul 4, 2023
2 parents ce0de3f + 6666c33 commit b441e0b
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 4 deletions.
1 change: 1 addition & 0 deletions newsfragments/3295.added.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Add FFI definitions `PyState_AddModule`, `PyState_RemoveModule` and `PyState_FindModule` for PyPy 3.9 and up.
12 changes: 8 additions & 4 deletions pyo3-ffi/src/pystate.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#[cfg(not(PyPy))]
#[cfg(any(not(PyPy), Py_3_9))]
use crate::moduleobject::PyModuleDef;
use crate::object::PyObject;
use std::os::raw::c_int;
Expand Down Expand Up @@ -28,13 +28,17 @@ extern "C" {
#[cfg(not(PyPy))]
pub fn PyInterpreterState_GetID(arg1: *mut PyInterpreterState) -> i64;

#[cfg(not(PyPy))]
#[cfg(any(not(PyPy), Py_3_9))] // only on PyPy since 3.9
#[cfg_attr(PyPy, link_name = "PyPyState_AddModule")]
pub fn PyState_AddModule(arg1: *mut PyObject, arg2: *mut PyModuleDef) -> c_int;

#[cfg(not(PyPy))]
#[cfg(any(not(PyPy), Py_3_9))] // only on PyPy since 3.9
#[cfg_attr(PyPy, link_name = "PyPyState_RemoveModule")]
pub fn PyState_RemoveModule(arg1: *mut PyModuleDef) -> c_int;

#[cfg(not(PyPy))]
#[cfg(any(not(PyPy), Py_3_9))] // only on PyPy since 3.9
// only has PyPy prefix since 3.10
#[cfg_attr(all(PyPy, Py_3_10), link_name = "PyPyState_FindModule")]
pub fn PyState_FindModule(arg1: *mut PyModuleDef) -> *mut PyObject;

#[cfg_attr(PyPy, link_name = "PyPyThreadState_New")]
Expand Down

0 comments on commit b441e0b

Please sign in to comment.