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

ffi: move initconfig.rs to cpython/initconfig.rs #1473

Merged
merged 3 commits into from
Mar 8, 2021
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 CHANGELOG.md
Original file line number Diff line number Diff line change
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 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)
Expand Down
17 changes: 10 additions & 7 deletions src/ffi/initconfig.rs → src/ffi/cpython/initconfig.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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(
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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,
Expand All @@ -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,
Expand All @@ -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,
Expand All @@ -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);
Expand Down Expand Up @@ -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);
}
9 changes: 8 additions & 1 deletion src/ffi/cpython/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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))]
Expand All @@ -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::*;
48 changes: 48 additions & 0 deletions src/ffi/cpython/pylifecycle.rs
Original file line number Diff line number Diff line change
@@ -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
}
4 changes: 0 additions & 4 deletions src/ffi/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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::*;
Expand Down Expand Up @@ -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;
Expand Down
23 changes: 0 additions & 23 deletions src/ffi/pylifecycle.rs
Original file line number Diff line number Diff line change
@@ -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};
Expand Down Expand Up @@ -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;
}