Skip to content

Commit

Permalink
ffi: move initconfig.rs to cpython/initconfig.rs
Browse files Browse the repository at this point in the history
  • Loading branch information
davidhewitt committed Mar 6, 2021
1 parent fa50c11 commit 53db425
Show file tree
Hide file tree
Showing 5 changed files with 56 additions and 33 deletions.
7 changes: 2 additions & 5 deletions src/ffi/initconfig.rs → src/ffi/cpython/initconfig.rs
@@ -1,3 +1,5 @@
#![cfg(all(Py_3_8, not(PyPy)))]

/* --- PyStatus ----------------------------------------------- */

use crate::ffi::Py_ssize_t;
Expand All @@ -19,7 +21,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 +40,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 +70,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 @@ -150,7 +149,6 @@ pub struct PyConfig {
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 +184,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);
}
5 changes: 4 additions & 1 deletion src/ffi/cpython/mod.rs
Expand Up @@ -9,10 +9,11 @@ pub mod dictobject;
// skipped fileobject.h
pub mod frameobject;
// skipped import.h
// skipped initconfig.h
pub mod initconfig;
// skipped interpreteridobject.h
pub mod listobject;
pub mod object;
pub mod pylifecycle;

pub use self::abstract_::*;
#[cfg(not(PyPy))]
Expand All @@ -22,5 +23,7 @@ pub use self::code::*;
#[cfg(not(PyPy))]
pub use self::dictobject::*;
pub use self::frameobject::*;
pub use self::initconfig::*;
pub use self::listobject::*;
pub use self::object::*;
pub use self::pylifecycle::*;
50 changes: 50 additions & 0 deletions src/ffi/cpython/pylifecycle.rs
@@ -0,0 +1,50 @@
#![cfg(all(Py_3_8, not(PyPy)))]

use libc::wchar_t;
use std::os::raw::{c_int, c_char};
use crate::ffi::{Py_ssize_t, PyPreConfig, PyConfig, PyStatus};

// "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;
// skipped _Py_InitializeMain

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
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
@@ -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;
}

0 comments on commit 53db425

Please sign in to comment.