Skip to content

Commit

Permalink
Define missing import APIs
Browse files Browse the repository at this point in the history
I need some of these APIs for the pyembed crate (used as part of
PyOxidizer). I figured I might as well define them all.

All these APIs are limited.
  • Loading branch information
indygreg committed Mar 6, 2021
1 parent fa50c11 commit 9821882
Show file tree
Hide file tree
Showing 2 changed files with 68 additions and 0 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Expand Up @@ -11,6 +11,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.
- Add #[pyo3(from_py_with = "...")]` attribute for function arguments and struct fields to override the default from-Python conversion. [#1411](https://github.com/PyO3/pyo3/pull/1411)
- Add FFI definition `PyCFunction_CheckExact` for Python 3.9 and later. [#1425](https://github.com/PyO3/pyo3/pull/1425)
- Add FFI definition `Py_IS_TYPE`. [#1429](https://github.com/PyO3/pyo3/pull/1429)
- Add FFI definitions for limited APIs `PyImport_ExtendInittab` and missing `_PyImport_*` functions.

### Changed
- Change `PyTimeAcces::get_fold()` to return a `bool` instead of a `u8`. [#1397](https://github.com/PyO3/pyo3/pull/1397)
Expand Down
67 changes: 67 additions & 0 deletions src/ffi/import.rs
@@ -1,4 +1,6 @@
use crate::ffi::object::PyObject;
#[cfg(not(Py_LIMITED_API))]
use std::os::raw::c_uchar;
use std::os::raw::{c_char, c_int, c_long};

extern "C" {
Expand Down Expand Up @@ -82,3 +84,68 @@ extern "C" {
initfunc: Option<extern "C" fn() -> *mut PyObject>,
) -> c_int;
}

#[repr(C)]
#[derive(Copy, Clone)]
#[cfg(not(Py_LIMITED_API))]
pub struct _inittab {
pub name: *mut c_char,
pub initfunc: Option<unsafe extern "C" fn()>,
}

#[repr(C)]
#[derive(Copy, Clone)]
#[cfg(not(Py_LIMITED_API))]
pub struct _frozen {
pub name: *const c_char,
pub code: *const c_uchar,
pub size: c_int,
}

#[cfg(not(Py_LIMITED_API))]
extern "C" {
pub static mut PyImport_FrozenModules: *const _frozen;
pub static mut PyImport_Inittab: *mut _inittab;

pub fn PyImport_ExtendInittab(newtab: *const _inittab) -> c_int;

#[cfg(not(Py_3_7))]
pub fn _PyImport_FindBuiltin(name: *const c_char) -> *mut PyObject;
#[cfg(all(Py_3_7, not(Py_3_9)))]
pub fn _PyImport_FindBuiltin(name: *const c_char, modules: *mut PyObject) -> *mut PyObject;

pub fn _PyImport_FindExtensionObject(
name: *mut PyObject,
filename: *mut PyObject,
) -> *mut PyObject;

#[cfg(all(Py_3_7, not(Py_3_9)))]
pub fn _PyImport_FindExtensionObjectEx(
name: *mut PyObject,
filename: *mut PyObject,
modules: *mut PyObject,
) -> *mut PyObject;

#[cfg(not(Py_3_7))]
pub fn _PyImport_FixupBuiltin(module: *mut PyObject, name: *const c_char) -> c_int;
#[cfg(Py_3_7)]
pub fn _PyImport_FixupBuiltin(
module: *mut PyObject,
name: *const c_char,
modules: *mut PyObject,
) -> c_int;

#[cfg(not(Py_3_7))]
pub fn _PyImport_FixupExtensionObject(
module: *mut PyObject,
name: *mut PyObject,
filename: *mut PyObject,
) -> c_int;
#[cfg(Py_3_7)]
pub fn _PyImport_FixupExtensionObject(
module: *mut PyObject,
name: *mut PyObject,
filename: *mut PyObject,
modules: *mut PyObject,
) -> c_int;
}

0 comments on commit 9821882

Please sign in to comment.