Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions newsfragments/5737.added.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Add FFI definitions `PyImport_ImportModuleAttr` and `PyImport_ImportModuleAttrString` on Python 3.14+.
1 change: 1 addition & 0 deletions newsfragments/5737.changed.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Deprecate FFI definition `PyImport_ImportModuleNoBlock` (deprecated in Python 3.13).
1 change: 1 addition & 0 deletions newsfragments/5737.fixed.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Fix FFI definition `PyImport_GetModule` on PyPy.
1 change: 1 addition & 0 deletions newsfragments/5737.removed.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Remove private FFI definitions `_PyImport_IsInitialized`, `_PyImport_SetModule`, `_PyImport_SetModuleString`, `_PyImport_AcquireLock`, `_PyImport_ReleaseLock`, `_PyImport_FindBuiltin`, `_PyImport_FindExtensionObject`, `_PyImport_FixupBuiltin`, and `_PyImport_FixupExtensionObject`.
45 changes: 12 additions & 33 deletions pyo3-ffi/src/cpython/import.rs
Original file line number Diff line number Diff line change
@@ -1,34 +1,8 @@
use crate::{PyInterpreterState, PyObject};
use crate::PyObject;
#[cfg(not(PyPy))]
use std::ffi::c_uchar;
use std::ffi::{c_char, c_int};

// skipped PyInit__imp

extern "C" {
pub fn _PyImport_IsInitialized(state: *mut PyInterpreterState) -> c_int;
// skipped _PyImport_GetModuleId
pub fn _PyImport_SetModule(name: *mut PyObject, module: *mut PyObject) -> c_int;
pub fn _PyImport_SetModuleString(name: *const c_char, module: *mut PyObject) -> c_int;
pub fn _PyImport_AcquireLock();
pub fn _PyImport_ReleaseLock() -> c_int;
#[cfg(not(Py_3_9))]
pub fn _PyImport_FindBuiltin(name: *const c_char, modules: *mut PyObject) -> *mut PyObject;
#[cfg(not(Py_3_11))]
pub fn _PyImport_FindExtensionObject(a: *mut PyObject, b: *mut PyObject) -> *mut PyObject;
pub fn _PyImport_FixupBuiltin(
module: *mut PyObject,
name: *const c_char,
modules: *mut PyObject,
) -> c_int;
pub fn _PyImport_FixupExtensionObject(
a: *mut PyObject,
b: *mut PyObject,
c: *mut PyObject,
d: *mut PyObject,
) -> c_int;
}

#[cfg(not(PyPy))]
#[repr(C)]
#[derive(Copy, Clone)]
Expand All @@ -41,9 +15,7 @@ pub struct _inittab {
extern "C" {
#[cfg(not(PyPy))]
pub static mut PyImport_Inittab: *mut _inittab;
}

extern "C" {
#[cfg(not(PyPy))]
pub fn PyImport_ExtendInittab(newtab: *mut _inittab) -> c_int;
}
Expand All @@ -65,8 +37,15 @@ pub struct _frozen {
extern "C" {
#[cfg(not(PyPy))]
pub static mut PyImport_FrozenModules: *const _frozen;
}

// skipped _PyImport_FrozenBootstrap
// skipped _PyImport_FrozenStdlib
// skipped _PyImport_FrozenTest
#[cfg(Py_3_14)]
pub fn PyImport_ImportModuleAttr(
mod_name: *mut PyObject,
attr_name: *mut PyObject,
) -> *mut PyObject;
#[cfg(Py_3_14)]
pub fn PyImport_ImportModuleAttrString(
mod_name: *const c_char,
attr_name: *const c_char,
) -> *mut PyObject;
}
4 changes: 3 additions & 1 deletion pyo3-ffi/src/import.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,8 @@ extern "C" {
) -> *mut PyObject;
#[cfg_attr(PyPy, link_name = "PyPyImport_GetModuleDict")]
pub fn PyImport_GetModuleDict() -> *mut PyObject;
// skipped Python 3.7 / ex-non-limited PyImport_GetModule
#[cfg_attr(PyPy, link_name = "PyPyImport_GetModule")]
pub fn PyImport_GetModule(name: *mut PyObject) -> *mut PyObject;
pub fn PyImport_AddModuleObject(name: *mut PyObject) -> *mut PyObject;
#[cfg_attr(PyPy, link_name = "PyPyImport_AddModule")]
pub fn PyImport_AddModule(name: *const c_char) -> *mut PyObject;
Expand All @@ -35,6 +36,7 @@ extern "C" {
pub fn PyImport_AddModuleRef(name: *const c_char) -> *mut PyObject;
#[cfg_attr(PyPy, link_name = "PyPyImport_ImportModule")]
pub fn PyImport_ImportModule(name: *const c_char) -> *mut PyObject;
#[deprecated(note = "Python 3.13")]
#[cfg_attr(PyPy, link_name = "PyPyImport_ImportModuleNoBlock")]
pub fn PyImport_ImportModuleNoBlock(name: *const c_char) -> *mut PyObject;
#[cfg_attr(PyPy, link_name = "PyPyImport_ImportModuleLevel")]
Expand Down
Loading