Merge pull request #1473 from davidhewitt/initconfig-limited-api

ffi: move initconfig.rs to cpython/initconfig.rs
This commit is contained in:
David Hewitt 2021-03-08 21:59:58 +00:00 committed by GitHub
commit 5e44c2b0d6
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
6 changed files with 67 additions and 35 deletions

View file

@ -14,6 +14,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 definition `_Py_InitializeMain`. [#1473](https://github.com/PyO3/pyo3/pull/1473)
### Changed
- Change `PyTimeAcces::get_fold()` to return a `bool` instead of a `u8`. [#1397](https://github.com/PyO3/pyo3/pull/1397)

View file

@ -19,7 +19,6 @@ pub struct PyStatus {
pub exitcode: c_int,
}
#[cfg_attr(windows, link(name = "pythonXY"))]
extern "C" {
pub fn PyStatus_Ok() -> PyStatus;
pub fn PyStatus_Error(err_msg: *const c_char) -> PyStatus;
@ -39,7 +38,6 @@ pub struct PyWideStringList {
pub items: *mut *mut wchar_t,
}
#[cfg_attr(windows, link(name = "pythonXY"))]
extern "C" {
pub fn PyWideStringList_Append(list: *mut PyWideStringList, item: *const wchar_t) -> PyStatus;
pub fn PyWideStringList_Insert(
@ -70,7 +68,6 @@ pub struct PyPreConfig {
pub allocator: c_int,
}
#[cfg_attr(windows, link(name = "pythonXY"))]
extern "C" {
pub fn PyPreConfig_InitPythonConfig(config: *mut PyPreConfig);
pub fn PyPreConfig_InitIsolatedConfig(config: *mut PyPreConfig);
@ -102,7 +99,10 @@ pub struct PyConfig {
pub filesystem_errors: *mut wchar_t,
pub pycache_prefix: *mut wchar_t,
pub parse_argv: c_int,
#[cfg(Py_3_10)]
pub orig_argv: PyWideStringList,
pub argv: PyWideStringList,
#[cfg(not(Py_3_10))]
pub program_name: *mut wchar_t,
pub xoptions: PyWideStringList,
pub warnoptions: PyWideStringList,
@ -125,9 +125,14 @@ pub struct PyConfig {
pub legacy_windows_stdio: c_int,
pub check_hash_pycs_mode: *mut wchar_t,
#[cfg(Py_3_10)]
pub program_name: *mut wchar_t,
pub pathconfig_warnings: c_int,
pub pythonpath_env: *mut wchar_t,
pub home: *mut wchar_t,
#[cfg(Py_3_10)]
pub platlibdir: *mut wchar_t,
pub module_search_paths_set: c_int,
pub module_search_paths: PyWideStringList,
pub executable: *mut wchar_t,
@ -136,7 +141,7 @@ pub struct PyConfig {
pub base_prefix: *mut wchar_t,
pub exec_prefix: *mut wchar_t,
pub base_exec_prefix: *mut wchar_t,
#[cfg(Py_3_9)]
#[cfg(all(Py_3_9, not(Py_3_10)))]
pub platlibdir: *mut wchar_t,
pub skip_source_first_line: c_int,
pub run_command: *mut wchar_t,
@ -146,11 +151,10 @@ pub struct PyConfig {
pub _init_main: c_int,
#[cfg(Py_3_9)]
pub _isolated_interpreter: c_int,
#[cfg(Py_3_9)]
#[cfg(all(Py_3_9, not(Py_3_10)))]
pub orig_argv: PyWideStringList,
}
#[cfg_attr(windows, link(name = "pythonXY"))]
extern "C" {
pub fn PyConfig_InitPythonConfig(config: *mut PyConfig);
pub fn PyConfig_InitIsolatedConfig(config: *mut PyConfig);
@ -186,7 +190,6 @@ extern "C" {
/* --- Helper functions --------------------------------------- */
#[cfg_attr(windows, link(name = "pythonXY"))]
extern "C" {
pub fn Py_GetArgcArgv(argc: *mut c_int, argv: *mut *mut *mut wchar_t);
}

View file

@ -9,10 +9,13 @@ pub mod dictobject;
// skipped fileobject.h
pub mod frameobject;
// skipped import.h
// skipped initconfig.h
#[cfg(all(Py_3_8, not(PyPy)))]
pub mod initconfig;
// skipped interpreteridobject.h
pub mod listobject;
pub mod object;
#[cfg(all(Py_3_8, not(PyPy)))]
pub mod pylifecycle;
pub use self::abstract_::*;
#[cfg(not(PyPy))]
@ -22,5 +25,9 @@ pub use self::code::*;
#[cfg(not(PyPy))]
pub use self::dictobject::*;
pub use self::frameobject::*;
#[cfg(all(Py_3_8, not(PyPy)))]
pub use self::initconfig::*;
pub use self::listobject::*;
pub use self::object::*;
#[cfg(all(Py_3_8, not(PyPy)))]
pub use self::pylifecycle::*;

View file

@ -0,0 +1,48 @@
use crate::ffi::{PyConfig, PyPreConfig, PyStatus, Py_ssize_t};
use libc::wchar_t;
use std::os::raw::{c_char, c_int};
// "private" functions in cpython/pylifecycle.h accepted in PEP 587
extern "C" {
// skipped _Py_SetStandardStreamEncoding;
pub fn Py_PreInitialize(src_config: *const PyPreConfig) -> PyStatus;
pub fn Py_PreInitializeFromBytesArgs(
src_config: *const PyPreConfig,
argc: Py_ssize_t,
argv: *mut *mut c_char,
) -> PyStatus;
pub fn Py_PreInitializeFromArgs(
src_config: *const PyPreConfig,
argc: Py_ssize_t,
argv: *mut *mut wchar_t,
) -> PyStatus;
pub fn _Py_IsCoreInitialized() -> c_int;
pub fn Py_InitializeFromConfig(config: *const PyConfig) -> PyStatus;
pub fn _Py_InitializeMain() -> PyStatus;
pub fn Py_RunMain() -> c_int;
// skipped Py_ExitStatusException
// skipped _Py_RestoreSignals
// skipped Py_FdIsInteractive
// skipped _Py_FdIsInteractive
// skipped _Py_SetProgramFullPath
// skipped _Py_gitidentifier
// skipped _Py_getversion
// skipped _Py_IsFinalizing
// skipped _PyOS_URandom
// skipped _PyOS_URandomNonblock
// skipped _Py_CoerceLegacyLocale
// skipped _Py_LegacyLocaleDetected
// skipped _Py_SetLocaleFromEnv
// skipped _Py_NewInterpreter
}

View file

@ -36,8 +36,6 @@ pub use self::funcobject::*;
#[cfg(not(Py_LIMITED_API))]
pub use self::genobject::*;
pub use self::import::*;
#[cfg(all(Py_3_8, not(any(PY_LIMITED_API, PyPy))))]
pub use self::initconfig::*;
pub use self::intrcheck::*;
pub use self::iterobject::*;
pub use self::listobject::*;
@ -164,8 +162,6 @@ mod pyport;
// [cfg(not(Py_LIMITED_API))]
// mod pytime; contains nothing of interest
#[cfg(all(Py_3_8, not(any(PY_LIMITED_API, PyPy))))]
mod initconfig;
mod objimpl;
mod pydebug;
mod pyhash;

View file

@ -1,6 +1,4 @@
use crate::ffi::pystate::PyThreadState;
#[cfg(all(Py_3_8, not(any(PY_LIMITED_API, PyPy))))]
use crate::ffi::{PyConfig, PyPreConfig, PyStatus, Py_ssize_t};
use libc::wchar_t;
use std::os::raw::{c_char, c_int};
@ -53,24 +51,3 @@ extern "C" {
pub fn PyOS_getsig(arg1: c_int) -> PyOS_sighandler_t;
pub fn PyOS_setsig(arg1: c_int, arg2: PyOS_sighandler_t) -> PyOS_sighandler_t;
}
// "private" functions in cpython/pylifecycle.h accepted in PEP 587
#[cfg(all(Py_3_8, not(any(PY_LIMITED_API, PyPy))))]
#[cfg_attr(windows, link(name = "pythonXY"))]
extern "C" {
pub fn Py_PreInitialize(src_config: *const PyPreConfig) -> PyStatus;
pub fn Py_PreInitializeFromBytesArgs(
src_config: *const PyPreConfig,
argc: Py_ssize_t,
argv: *mut *mut c_char,
) -> PyStatus;
pub fn Py_PreInitializeFromArgs(
src_config: *const PyPreConfig,
argc: Py_ssize_t,
argv: *mut *mut wchar_t,
) -> PyStatus;
pub fn Py_InitializeFromConfig(config: *const PyConfig) -> PyStatus;
pub fn Py_RunMain() -> c_int;
}