Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add PyInterpreterConfig api #3502

Merged
merged 1 commit into from
Oct 8, 2023
Merged
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/3502.added.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Added the `PyInterpreterConfig` struct, its constants and `Py_NewInterpreterFromConfig`.
53 changes: 52 additions & 1 deletion pyo3-ffi/src/cpython/pylifecycle.rs
Original file line number Diff line number Diff line change
Expand Up @@ -44,5 +44,56 @@ extern "C" {
// skipped _Py_LegacyLocaleDetected
// skipped _Py_SetLocaleFromEnv

// skipped _Py_NewInterpreter
}

#[cfg(Py_3_12)]
pub const PyInterpreterConfig_DEFAULT_GIL: c_int = 0;
#[cfg(Py_3_12)]
pub const PyInterpreterConfig_SHARED_GIL: c_int = 1;
#[cfg(Py_3_12)]
pub const PyInterpreterConfig_OWN_GIL: c_int = 2;

#[cfg(Py_3_12)]
#[repr(C)]
pub struct PyInterpreterConfig {
pub use_main_obmalloc: c_int,
pub allow_fork: c_int,
pub allow_exec: c_int,
pub allow_threads: c_int,
pub allow_daemon_threads: c_int,
pub check_multi_interp_extensions: c_int,
pub gil: c_int,
}

#[cfg(Py_3_12)]
pub const _PyInterpreterConfig_INIT: PyInterpreterConfig = PyInterpreterConfig {
use_main_obmalloc: 0,
allow_fork: 0,
allow_exec: 0,
allow_threads: 1,
allow_daemon_threads: 0,
check_multi_interp_extensions: 1,
gil: PyInterpreterConfig_OWN_GIL,
};

#[cfg(Py_3_12)]
pub const _PyInterpreterConfig_LEGACY_INIT: PyInterpreterConfig = PyInterpreterConfig {
use_main_obmalloc: 1,
allow_fork: 1,
allow_exec: 1,
allow_threads: 1,
allow_daemon_threads: 1,
check_multi_interp_extensions: 0,
gil: PyInterpreterConfig_SHARED_GIL,
};

extern "C" {
#[cfg(Py_3_12)]
pub fn Py_NewInterpreterFromConfig(
tstate_p: *mut *mut crate::PyThreadState,
config: *const PyInterpreterConfig,
) -> PyStatus;
}

// skipped atexit_datacallbackfunc
// skipped _Py_AtExit