Skip to content

Add Python 3.9 support #243

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

Merged
merged 1 commit into from
Nov 8, 2020
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 .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ python:
- "3.6"
- "3.7"
- "3.8"
- "3.9"
env:
- RUST_VERSION=1.32.0
- RUST_VERSION=stable
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ Python is licensed under the [Python License](https://docs.python.org/2/license.

Supported Python versions:
* Python 2.7
* Python 3.3 to 3.8
* Python 3.3 to 3.9

Requires Rust 1.32.0 or later.

Expand Down
1 change: 1 addition & 0 deletions python3-sys/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@ python-3-5 = []
python-3-6 = []
python-3-7 = []
python-3-8 = []
python-3-9 = []

# Restrict to PEP-384 stable ABI
pep-384 = []
Expand Down
16 changes: 13 additions & 3 deletions python3-sys/src/ceval.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ use crate::pystate::PyThreadState;

#[cfg_attr(windows, link(name = "pythonXY"))]
extern "C" {
#[deprecated(since = "0.5.2", note = "Deprecated since Python 3.9")]
pub fn PyEval_CallObjectWithKeywords(
callable: *mut PyObject,
obj: *mut PyObject,
Expand All @@ -13,17 +14,21 @@ extern "C" {
}

#[inline]
#[deprecated(since = "0.5.2", note = "Deprecated since Python 3.9")]
pub unsafe fn PyEval_CallObject(callable: *mut PyObject, arg: *mut PyObject) -> *mut PyObject {
#[allow(deprecated)]
PyEval_CallObjectWithKeywords(callable, arg, core::ptr::null_mut())
}

#[cfg_attr(windows, link(name = "pythonXY"))]
extern "C" {
#[deprecated(since = "0.5.2", note = "Deprecated since Python 3.9")]
pub fn PyEval_CallFunction(
callable: *mut PyObject,
format: *const c_char,
...
) -> *mut PyObject;
#[deprecated(since = "0.5.2", note = "Deprecated since Python 3.9")]
pub fn PyEval_CallMethod(
obj: *mut PyObject,
name: *const c_char,
Expand All @@ -42,11 +47,16 @@ extern "C" {
pub fn Py_SetRecursionLimit(arg1: c_int) -> ();
pub fn Py_GetRecursionLimit() -> c_int;

fn _Py_CheckRecursiveCall(_where: *mut c_char) -> c_int;
static mut _Py_CheckRecursionLimit: c_int;
//fn _Py_CheckRecursiveCall(_where: *mut c_char) -> c_int;
//static mut _Py_CheckRecursionLimit: c_int;

#[cfg(Py_3_9)]
pub fn Py_EnterRecursiveCall(_where: *const c_char) -> c_int;
#[cfg(Py_3_9)]
pub fn Py_LeaveRecursiveCall() -> c_void;
}

// TODO: Py_EnterRecursiveCall etc.
// TODO: Py_EnterRecursiveCall for Python <3.9

#[cfg_attr(windows, link(name = "pythonXY"))]
extern "C" {
Expand Down
2 changes: 2 additions & 0 deletions python3-sys/src/compile.rs
Original file line number Diff line number Diff line change
Expand Up @@ -75,3 +75,5 @@ pub const Py_file_input: c_int = 257;
pub const Py_eval_input: c_int = 258;
#[cfg(Py_3_8)]
pub const Py_func_type_input: c_int = 345;
#[cfg(Py_3_9)]
pub const Py_fstring_input: c_int = 800;
16 changes: 16 additions & 0 deletions python3-sys/src/frameobject.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ use crate::code::{PyCodeObject, CO_MAXBLOCKS};
use crate::object::*;
use crate::pystate::PyThreadState;

#[cfg(not(Py_LIMITED_API))]
#[repr(C)]
#[derive(Copy, Clone)]
pub struct PyTryBlock {
Expand All @@ -12,6 +13,10 @@ pub struct PyTryBlock {
pub b_level: c_int,
}

#[cfg(Py_LIMITED_API)]
pub enum PyFrameObject {}

#[cfg(not(Py_LIMITED_API))]
#[repr(C)]
#[derive(Copy, Clone)]
pub struct PyFrameObject {
Expand Down Expand Up @@ -60,16 +65,19 @@ pub struct PyFrameObject {
pub f_localsplus: [*mut PyObject; 1], /* locals+stack, dynamically sized */
}

#[cfg(not(Py_LIMITED_API))]
#[cfg_attr(windows, link(name = "pythonXY"))]
extern "C" {
pub static mut PyFrame_Type: PyTypeObject;
}

#[cfg(not(Py_LIMITED_API))]
#[inline]
pub unsafe fn PyFrame_Check(op: *mut PyObject) -> c_int {
(Py_TYPE(op) == &mut PyFrame_Type) as c_int
}

#[cfg(not(Py_LIMITED_API))]
#[cfg_attr(windows, link(name = "pythonXY"))]
extern "C" {
pub fn PyFrame_New(
Expand All @@ -92,6 +100,14 @@ extern "C" {
pub fn PyFrame_FastToLocalsWithError(f: *mut PyFrameObject) -> c_int;
pub fn PyFrame_FastToLocals(f: *mut PyFrameObject) -> ();

#[cfg(not(Py_3_9))]
pub fn PyFrame_ClearFreeList() -> c_int;
}

#[cfg_attr(windows, link(name = "pythonXY"))]
extern "C" {
pub fn PyFrame_GetLineNumber(f: *mut PyFrameObject) -> c_int;

#[cfg(Py_3_9)]
pub fn PyFrame_GetCode(frame: *mut PyFrameObject) -> *mut PyCodeObject;
}
7 changes: 3 additions & 4 deletions python3-sys/src/import.rs
Original file line number Diff line number Diff line change
Expand Up @@ -62,12 +62,11 @@ extern "C" {
pub fn PyImport_GetImporter(path: *mut PyObject) -> *mut PyObject;
pub fn PyImport_Import(name: *mut PyObject) -> *mut PyObject;
pub fn PyImport_ReloadModule(m: *mut PyObject) -> *mut PyObject;
#[cfg(not(Py_3_9))]
pub fn PyImport_Cleanup() -> ();
pub fn PyImport_ImportFrozenModuleObject(name: *mut PyObject) -> c_int;
pub fn PyImport_ImportFrozenModule(name: *const c_char) -> c_int;

// pub static mut PyNullImporter_Type: PyTypeObject; -- does not actually exist in shared library

pub fn PyImport_AppendInittab(
name: *const c_char,
initfunc: Option<unsafe extern "C" fn() -> *mut PyObject>,
Expand Down Expand Up @@ -101,15 +100,15 @@ extern "C" {

#[cfg(not(Py_3_7))]
pub fn _PyImport_FindBuiltin(name: *const c_char) -> *mut PyObject;
#[cfg(Py_3_7)]
#[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(Py_3_7)]
#[cfg(all(Py_3_7, not(Py_3_9)))]
pub fn _PyImport_FindExtensionObjectEx(
name: *mut PyObject,
filename: *mut PyObject,
Expand Down
14 changes: 14 additions & 0 deletions python3-sys/src/initconfig.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

use crate::pyport::Py_ssize_t;
use libc::{c_char, c_int, c_ulong, wchar_t};
#[cfg(Py_3_9)]
use libc::c_void;

#[repr(C)]
#[derive(Copy, Clone)]
Expand Down Expand Up @@ -102,9 +104,12 @@ pub struct PyConfig {
pub use_hash_seed: c_int,
pub hash_seed: c_ulong,
pub faulthandler: c_int,
#[cfg(Py_3_9)]
pub _use_peg_parser: c_int,
pub tracemalloc: c_int,
pub import_time: c_int,
pub show_ref_count: c_int,
#[cfg(not(Py_3_9))]
pub show_alloc_count: c_int,
pub dump_refs: c_int,
pub malloc_stats: c_int,
Expand Down Expand Up @@ -144,12 +149,18 @@ 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)]
pub platlibdir: *mut wchar_t,
pub skip_source_first_line: c_int,
pub run_command: *mut wchar_t,
pub run_module: *mut wchar_t,
pub run_filename: *mut wchar_t,
pub _install_importlib: c_int,
pub _init_main: c_int,
#[cfg(Py_3_9)]
pub _isolated_interpreter: c_int,
#[cfg(Py_3_9)]
pub _orig_argv: PyWideStringList,
}

impl Default for PyConfig {
Expand Down Expand Up @@ -190,4 +201,7 @@ extern "C" {
length: Py_ssize_t,
items: *mut *mut wchar_t,
) -> PyStatus;

#[cfg(Py_3_9)]
pub fn Py_GetArgcArgv(argc: *mut c_int, argv: *mut *mut *mut wchar_t) -> c_void;
}
6 changes: 0 additions & 6 deletions python3-sys/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -277,14 +277,8 @@ mod fileutils;
// TODO supports PEP-384 only; needs adjustment for Python 3.3 and 3.5
pub mod structmember;

#[cfg(not(Py_LIMITED_API))]
pub mod frameobject;

#[cfg(Py_LIMITED_API)]
pub mod frameobject {
pub enum PyFrameObject {}
}

mod marshal;

#[cfg(all(Py_3_8, not(Py_LIMITED_API)))]
Expand Down
18 changes: 17 additions & 1 deletion python3-sys/src/methodobject.rs
Original file line number Diff line number Diff line change
Expand Up @@ -45,13 +45,15 @@ pub type _PyCFunctionFastWithKeywords = unsafe extern "C" fn(
kwnames: *mut PyObject,
) -> *mut PyObject;

#[cfg(not(Py_3_9))]
pub type PyNoArgsFunction = unsafe extern "C" fn(slf: *mut PyObject) -> *mut PyObject;

#[cfg_attr(windows, link(name = "pythonXY"))]
extern "C" {
pub fn PyCFunction_GetFunction(f: *mut PyObject) -> Option<PyCFunction>;
pub fn PyCFunction_GetSelf(f: *mut PyObject) -> *mut PyObject;
pub fn PyCFunction_GetFlags(f: *mut PyObject) -> c_int;
#[deprecated(since = "0.5.2", note = "Deprecated since Python 3.9")]
pub fn PyCFunction_Call(
f: *mut PyObject,
args: *mut PyObject,
Expand Down Expand Up @@ -92,6 +94,14 @@ extern "C" {
arg2: *mut PyObject,
arg3: *mut PyObject,
) -> *mut PyObject;

#[cfg(Py_3_9)]
pub fn PyCMethod_New(
arg1: *mut PyMethodDef,
arg2: *mut PyObject,
arg3: *mut PyObject,
arg4: *mut PyTypeObject,
) -> *mut PyObject;
}

/* Flag passed to newmethodobject */
Expand All @@ -115,8 +125,14 @@ slot like sq_contains. */
pub const METH_COEXIST: c_int = 0x0040;

#[cfg(all(Py_3_6, not(Py_LIMITED_API)))]
pub const METHOD_FASTCALL: c_int = 0x0080;
pub const METH_FASTCALL: c_int = 0x0080;

// METH_STACKLESS: This bit is preserved for Stackless Python

#[cfg(all(Py_3_9))]
pub const METH_METHOD: c_int = 0x0200;

#[cfg(not(Py_3_9))]
#[cfg_attr(windows, link(name = "pythonXY"))]
extern "C" {
pub fn PyCFunction_ClearFreeList() -> c_int;
Expand Down
4 changes: 4 additions & 0 deletions python3-sys/src/modsupport.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ use libc::{c_char, c_int, c_long};

#[cfg(Py_3_5)]
use crate::methodobject::PyMethodDef;
#[cfg(Py_3_9)]
use crate::object::PyTypeObject;
use crate::moduleobject::PyModuleDef;
use crate::object::PyObject;
use crate::pyport::Py_ssize_t;
Expand Down Expand Up @@ -42,6 +44,8 @@ extern "C" {
arg2: *const c_char,
arg3: *const c_char,
) -> c_int;
#[cfg(Py_3_9)]
pub fn PyModule_AddType(module: *mut PyObject, ty: *mut PyTypeObject) -> c_int;
#[cfg(Py_3_5)]
pub fn PyModule_SetDocString(arg1: *mut PyObject, arg2: *const c_char) -> c_int;
#[cfg(Py_3_5)]
Expand Down
Loading