Skip to content

Commit b000dc1

Browse files
authored
sync import.rs FFI definitions with Python 3.14 (#5737)
* sync import.rs FFI definitions with Python 3.14 * newsfragments * fix imports on PyPy
1 parent 49e8772 commit b000dc1

7 files changed

Lines changed: 25 additions & 36 deletions

File tree

newsfragments/5737.added.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Add FFI definitions `PyImport_ImportModuleAttr` and `PyImport_ImportModuleAttrString` on Python 3.14+.

newsfragments/5737.changed.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Deprecate FFI definition `PyImport_ImportModuleNoBlock` (deprecated in Python 3.13).

newsfragments/5737.fixed.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Fix FFI definition `PyImport_GetModule` on PyPy.

newsfragments/5737.removed.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Remove private FFI definitions `_PyImport_IsInitialized`, `_PyImport_SetModule`, `_PyImport_SetModuleString`, `_PyImport_AcquireLock`, `_PyImport_ReleaseLock`, `_PyImport_FindBuiltin`, `_PyImport_FindExtensionObject`, `_PyImport_FixupBuiltin`, and `_PyImport_FixupExtensionObject`.

pyo3-ffi/src/cpython/import.rs

Lines changed: 16 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -1,33 +1,9 @@
1-
use crate::{PyInterpreterState, PyObject};
1+
#[cfg(any(not(PyPy), Py_3_14))]
2+
use crate::PyObject;
3+
#[cfg(any(not(PyPy), Py_3_14))]
4+
use std::ffi::c_char;
25
#[cfg(not(PyPy))]
3-
use std::ffi::c_uchar;
4-
use std::ffi::{c_char, c_int};
5-
6-
// skipped PyInit__imp
7-
8-
extern "C" {
9-
pub fn _PyImport_IsInitialized(state: *mut PyInterpreterState) -> c_int;
10-
// skipped _PyImport_GetModuleId
11-
pub fn _PyImport_SetModule(name: *mut PyObject, module: *mut PyObject) -> c_int;
12-
pub fn _PyImport_SetModuleString(name: *const c_char, module: *mut PyObject) -> c_int;
13-
pub fn _PyImport_AcquireLock();
14-
pub fn _PyImport_ReleaseLock() -> c_int;
15-
#[cfg(not(Py_3_9))]
16-
pub fn _PyImport_FindBuiltin(name: *const c_char, modules: *mut PyObject) -> *mut PyObject;
17-
#[cfg(not(Py_3_11))]
18-
pub fn _PyImport_FindExtensionObject(a: *mut PyObject, b: *mut PyObject) -> *mut PyObject;
19-
pub fn _PyImport_FixupBuiltin(
20-
module: *mut PyObject,
21-
name: *const c_char,
22-
modules: *mut PyObject,
23-
) -> c_int;
24-
pub fn _PyImport_FixupExtensionObject(
25-
a: *mut PyObject,
26-
b: *mut PyObject,
27-
c: *mut PyObject,
28-
d: *mut PyObject,
29-
) -> c_int;
30-
}
6+
use std::ffi::{c_int, c_uchar};
317

328
#[cfg(not(PyPy))]
339
#[repr(C)]
@@ -41,9 +17,7 @@ pub struct _inittab {
4117
extern "C" {
4218
#[cfg(not(PyPy))]
4319
pub static mut PyImport_Inittab: *mut _inittab;
44-
}
4520

46-
extern "C" {
4721
#[cfg(not(PyPy))]
4822
pub fn PyImport_ExtendInittab(newtab: *mut _inittab) -> c_int;
4923
}
@@ -65,8 +39,15 @@ pub struct _frozen {
6539
extern "C" {
6640
#[cfg(not(PyPy))]
6741
pub static mut PyImport_FrozenModules: *const _frozen;
68-
}
6942

70-
// skipped _PyImport_FrozenBootstrap
71-
// skipped _PyImport_FrozenStdlib
72-
// skipped _PyImport_FrozenTest
43+
#[cfg(Py_3_14)]
44+
pub fn PyImport_ImportModuleAttr(
45+
mod_name: *mut PyObject,
46+
attr_name: *mut PyObject,
47+
) -> *mut PyObject;
48+
#[cfg(Py_3_14)]
49+
pub fn PyImport_ImportModuleAttrString(
50+
mod_name: *const c_char,
51+
attr_name: *const c_char,
52+
) -> *mut PyObject;
53+
}

pyo3-ffi/src/cpython/mod.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ pub(crate) mod dictobject;
1515
pub(crate) mod frameobject;
1616
pub(crate) mod funcobject;
1717
pub(crate) mod genobject;
18+
#[cfg(any(not(PyPy), Py_3_14))]
1819
pub(crate) mod import;
1920
#[cfg(all(Py_3_8, not(PyPy)))]
2021
pub(crate) mod initconfig;
@@ -57,6 +58,7 @@ pub use self::floatobject::*;
5758
pub use self::frameobject::*;
5859
pub use self::funcobject::*;
5960
pub use self::genobject::*;
61+
#[cfg(any(not(PyPy), Py_3_14))]
6062
pub use self::import::*;
6163
#[cfg(all(Py_3_8, not(PyPy)))]
6264
pub use self::initconfig::*;

pyo3-ffi/src/import.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,8 @@ extern "C" {
2626
) -> *mut PyObject;
2727
#[cfg_attr(PyPy, link_name = "PyPyImport_GetModuleDict")]
2828
pub fn PyImport_GetModuleDict() -> *mut PyObject;
29-
// skipped Python 3.7 / ex-non-limited PyImport_GetModule
29+
#[cfg_attr(PyPy, link_name = "PyPyImport_GetModule")]
30+
pub fn PyImport_GetModule(name: *mut PyObject) -> *mut PyObject;
3031
pub fn PyImport_AddModuleObject(name: *mut PyObject) -> *mut PyObject;
3132
#[cfg_attr(PyPy, link_name = "PyPyImport_AddModule")]
3233
pub fn PyImport_AddModule(name: *const c_char) -> *mut PyObject;
@@ -35,6 +36,7 @@ extern "C" {
3536
pub fn PyImport_AddModuleRef(name: *const c_char) -> *mut PyObject;
3637
#[cfg_attr(PyPy, link_name = "PyPyImport_ImportModule")]
3738
pub fn PyImport_ImportModule(name: *const c_char) -> *mut PyObject;
39+
#[deprecated(note = "Python 3.13")]
3840
#[cfg_attr(PyPy, link_name = "PyPyImport_ImportModuleNoBlock")]
3941
pub fn PyImport_ImportModuleNoBlock(name: *const c_char) -> *mut PyObject;
4042
#[cfg_attr(PyPy, link_name = "PyPyImport_ImportModuleLevel")]

0 commit comments

Comments
 (0)