Skip to content

Commit 28ccef2

Browse files
authored
Merge pull request #1475 from indygreg/more-import-ffis
Define missing import APIs
2 parents eed1b1a + 754c27f commit 28ccef2

File tree

3 files changed

+74
-1
lines changed

3 files changed

+74
-1
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.
1818
- Add FFI definition `PyCFunction_CheckExact` for Python 3.9 and later. [#1425](https://github.com/PyO3/pyo3/pull/1425)
1919
- Add FFI definition `Py_IS_TYPE`. [#1429](https://github.com/PyO3/pyo3/pull/1429)
2020
- Add FFI definition `_Py_InitializeMain`. [#1473](https://github.com/PyO3/pyo3/pull/1473)
21+
- Add FFI definitions from `cpython/import.h`.[#1475](https://github.com/PyO3/pyo3/pull/1475)
2122
- Add tuple and unit struct support for `#[pyclass]` macro. [#1504](https://github.com/PyO3/pyo3/pull/1504)
2223

2324
### Changed

src/ffi/cpython/import.rs

Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
use crate::ffi::{PyInterpreterState, PyObject};
2+
use std::os::raw::{c_char, c_int, c_uchar};
3+
4+
// skipped PyInit__imp
5+
6+
extern "C" {
7+
pub fn _PyImport_IsInitialized(state: *mut PyInterpreterState) -> c_int;
8+
// skipped _PyImport_GetModuleId
9+
#[cfg(Py_3_7)]
10+
pub fn _PyImport_SetModule(name: *mut PyObject, module: *mut PyObject) -> c_int;
11+
#[cfg(Py_3_7)]
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_7))]
16+
pub fn _PyImport_FindBuiltin(name: *const c_char) -> *mut PyObject;
17+
#[cfg(all(Py_3_7, not(Py_3_9)))]
18+
pub fn _PyImport_FindBuiltin(name: *const c_char, modules: *mut PyObject) -> *mut PyObject;
19+
#[cfg(not(Py_3_10))]
20+
pub fn _PyImport_FindExtensionObject(a: *mut PyObject, b: *mut PyObject) -> *mut PyObject;
21+
#[cfg(not(Py_3_7))]
22+
pub fn _PyImport_FixupBuiltin(module: *mut PyObject, name: *const c_char) -> c_int;
23+
#[cfg(Py_3_7)]
24+
pub fn _PyImport_FixupBuiltin(
25+
module: *mut PyObject,
26+
name: *const c_char,
27+
modules: *mut PyObject,
28+
) -> c_int;
29+
#[cfg(not(Py_3_7))]
30+
pub fn _PyImport_FixupExtensionObject(
31+
a: *mut PyObject,
32+
b: *mut PyObject,
33+
c: *mut PyObject,
34+
) -> c_int;
35+
#[cfg(Py_3_7)]
36+
pub fn _PyImport_FixupExtensionObject(
37+
a: *mut PyObject,
38+
b: *mut PyObject,
39+
c: *mut PyObject,
40+
d: *mut PyObject,
41+
) -> c_int;
42+
}
43+
44+
#[repr(C)]
45+
#[derive(Copy, Clone)]
46+
pub struct _inittab {
47+
pub name: *const c_char,
48+
pub initfun: Option<unsafe extern "C" fn() -> *mut PyObject>,
49+
}
50+
51+
#[cfg_attr(windows, link(name = "pythonXY"))]
52+
extern "C" {
53+
pub static mut PyImport_Inittab: *mut _inittab;
54+
}
55+
56+
extern "C" {
57+
pub fn PyImport_ExtendInittab(newtab: *mut _inittab) -> c_int;
58+
}
59+
60+
#[repr(C)]
61+
#[derive(Copy, Clone)]
62+
pub struct _frozen {
63+
name: *const c_char,
64+
code: *const c_uchar,
65+
size: c_int,
66+
}
67+
68+
#[cfg_attr(windows, link(name = "pythonXY"))]
69+
extern "C" {
70+
pub static mut PyImport_FrozenModules: *const _frozen;
71+
}

src/ffi/cpython/mod.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ pub mod compile;
99
pub mod dictobject;
1010
// skipped fileobject.h
1111
pub mod frameobject;
12-
// skipped import.h
12+
pub mod import;
1313
#[cfg(all(Py_3_8, not(PyPy)))]
1414
pub mod initconfig;
1515
// skipped interpreteridobject.h
@@ -28,6 +28,7 @@ pub use self::compile::*;
2828
#[cfg(not(PyPy))]
2929
pub use self::dictobject::*;
3030
pub use self::frameobject::*;
31+
pub use self::import::*;
3132
#[cfg(all(Py_3_8, not(PyPy)))]
3233
pub use self::initconfig::*;
3334
pub use self::listobject::*;

0 commit comments

Comments
 (0)