Skip to content

Commit 7f0d976

Browse files
authored
Merge pull request #243 from dgrunwald/py3.9
Add Python 3.9 support
2 parents 77044b9 + 6a3a4d8 commit 7f0d976

18 files changed

+150
-29
lines changed

.travis.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ python:
66
- "3.6"
77
- "3.7"
88
- "3.8"
9+
- "3.9"
910
env:
1011
- RUST_VERSION=1.32.0
1112
- RUST_VERSION=stable

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ Python is licensed under the [Python License](https://docs.python.org/2/license.
1414

1515
Supported Python versions:
1616
* Python 2.7
17-
* Python 3.3 to 3.8
17+
* Python 3.3 to 3.9
1818

1919
Requires Rust 1.32.0 or later.
2020

python3-sys/Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,7 @@ python-3-5 = []
7171
python-3-6 = []
7272
python-3-7 = []
7373
python-3-8 = []
74+
python-3-9 = []
7475

7576
# Restrict to PEP-384 stable ABI
7677
pep-384 = []

python3-sys/src/ceval.rs

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ use crate::pystate::PyThreadState;
55

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

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

2023
#[cfg_attr(windows, link(name = "pythonXY"))]
2124
extern "C" {
25+
#[deprecated(since = "0.5.2", note = "Deprecated since Python 3.9")]
2226
pub fn PyEval_CallFunction(
2327
callable: *mut PyObject,
2428
format: *const c_char,
2529
...
2630
) -> *mut PyObject;
31+
#[deprecated(since = "0.5.2", note = "Deprecated since Python 3.9")]
2732
pub fn PyEval_CallMethod(
2833
obj: *mut PyObject,
2934
name: *const c_char,
@@ -42,11 +47,16 @@ extern "C" {
4247
pub fn Py_SetRecursionLimit(arg1: c_int) -> ();
4348
pub fn Py_GetRecursionLimit() -> c_int;
4449

45-
fn _Py_CheckRecursiveCall(_where: *mut c_char) -> c_int;
46-
static mut _Py_CheckRecursionLimit: c_int;
50+
//fn _Py_CheckRecursiveCall(_where: *mut c_char) -> c_int;
51+
//static mut _Py_CheckRecursionLimit: c_int;
52+
53+
#[cfg(Py_3_9)]
54+
pub fn Py_EnterRecursiveCall(_where: *const c_char) -> c_int;
55+
#[cfg(Py_3_9)]
56+
pub fn Py_LeaveRecursiveCall() -> c_void;
4757
}
4858

49-
// TODO: Py_EnterRecursiveCall etc.
59+
// TODO: Py_EnterRecursiveCall for Python <3.9
5060

5161
#[cfg_attr(windows, link(name = "pythonXY"))]
5262
extern "C" {

python3-sys/src/compile.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,3 +75,5 @@ pub const Py_file_input: c_int = 257;
7575
pub const Py_eval_input: c_int = 258;
7676
#[cfg(Py_3_8)]
7777
pub const Py_func_type_input: c_int = 345;
78+
#[cfg(Py_3_9)]
79+
pub const Py_fstring_input: c_int = 800;

python3-sys/src/frameobject.rs

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ use crate::code::{PyCodeObject, CO_MAXBLOCKS};
44
use crate::object::*;
55
use crate::pystate::PyThreadState;
66

7+
#[cfg(not(Py_LIMITED_API))]
78
#[repr(C)]
89
#[derive(Copy, Clone)]
910
pub struct PyTryBlock {
@@ -12,6 +13,10 @@ pub struct PyTryBlock {
1213
pub b_level: c_int,
1314
}
1415

16+
#[cfg(Py_LIMITED_API)]
17+
pub enum PyFrameObject {}
18+
19+
#[cfg(not(Py_LIMITED_API))]
1520
#[repr(C)]
1621
#[derive(Copy, Clone)]
1722
pub struct PyFrameObject {
@@ -60,16 +65,19 @@ pub struct PyFrameObject {
6065
pub f_localsplus: [*mut PyObject; 1], /* locals+stack, dynamically sized */
6166
}
6267

68+
#[cfg(not(Py_LIMITED_API))]
6369
#[cfg_attr(windows, link(name = "pythonXY"))]
6470
extern "C" {
6571
pub static mut PyFrame_Type: PyTypeObject;
6672
}
6773

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

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

103+
#[cfg(not(Py_3_9))]
95104
pub fn PyFrame_ClearFreeList() -> c_int;
105+
}
106+
107+
#[cfg_attr(windows, link(name = "pythonXY"))]
108+
extern "C" {
96109
pub fn PyFrame_GetLineNumber(f: *mut PyFrameObject) -> c_int;
110+
111+
#[cfg(Py_3_9)]
112+
pub fn PyFrame_GetCode(frame: *mut PyFrameObject) -> *mut PyCodeObject;
97113
}

python3-sys/src/import.rs

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -62,12 +62,11 @@ extern "C" {
6262
pub fn PyImport_GetImporter(path: *mut PyObject) -> *mut PyObject;
6363
pub fn PyImport_Import(name: *mut PyObject) -> *mut PyObject;
6464
pub fn PyImport_ReloadModule(m: *mut PyObject) -> *mut PyObject;
65+
#[cfg(not(Py_3_9))]
6566
pub fn PyImport_Cleanup() -> ();
6667
pub fn PyImport_ImportFrozenModuleObject(name: *mut PyObject) -> c_int;
6768
pub fn PyImport_ImportFrozenModule(name: *const c_char) -> c_int;
6869

69-
// pub static mut PyNullImporter_Type: PyTypeObject; -- does not actually exist in shared library
70-
7170
pub fn PyImport_AppendInittab(
7271
name: *const c_char,
7372
initfunc: Option<unsafe extern "C" fn() -> *mut PyObject>,
@@ -101,15 +100,15 @@ extern "C" {
101100

102101
#[cfg(not(Py_3_7))]
103102
pub fn _PyImport_FindBuiltin(name: *const c_char) -> *mut PyObject;
104-
#[cfg(Py_3_7)]
103+
#[cfg(all(Py_3_7, not(Py_3_9)))]
105104
pub fn _PyImport_FindBuiltin(name: *const c_char, modules: *mut PyObject) -> *mut PyObject;
106105

107106
pub fn _PyImport_FindExtensionObject(
108107
name: *mut PyObject,
109108
filename: *mut PyObject,
110109
) -> *mut PyObject;
111110

112-
#[cfg(Py_3_7)]
111+
#[cfg(all(Py_3_7, not(Py_3_9)))]
113112
pub fn _PyImport_FindExtensionObjectEx(
114113
name: *mut PyObject,
115114
filename: *mut PyObject,

python3-sys/src/initconfig.rs

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22

33
use crate::pyport::Py_ssize_t;
44
use libc::{c_char, c_int, c_ulong, wchar_t};
5+
#[cfg(Py_3_9)]
6+
use libc::c_void;
57

68
#[repr(C)]
79
#[derive(Copy, Clone)]
@@ -102,9 +104,12 @@ pub struct PyConfig {
102104
pub use_hash_seed: c_int,
103105
pub hash_seed: c_ulong,
104106
pub faulthandler: c_int,
107+
#[cfg(Py_3_9)]
108+
pub _use_peg_parser: c_int,
105109
pub tracemalloc: c_int,
106110
pub import_time: c_int,
107111
pub show_ref_count: c_int,
112+
#[cfg(not(Py_3_9))]
108113
pub show_alloc_count: c_int,
109114
pub dump_refs: c_int,
110115
pub malloc_stats: c_int,
@@ -144,12 +149,18 @@ pub struct PyConfig {
144149
pub base_prefix: *mut wchar_t,
145150
pub exec_prefix: *mut wchar_t,
146151
pub base_exec_prefix: *mut wchar_t,
152+
#[cfg(Py_3_9)]
153+
pub platlibdir: *mut wchar_t,
147154
pub skip_source_first_line: c_int,
148155
pub run_command: *mut wchar_t,
149156
pub run_module: *mut wchar_t,
150157
pub run_filename: *mut wchar_t,
151158
pub _install_importlib: c_int,
152159
pub _init_main: c_int,
160+
#[cfg(Py_3_9)]
161+
pub _isolated_interpreter: c_int,
162+
#[cfg(Py_3_9)]
163+
pub _orig_argv: PyWideStringList,
153164
}
154165

155166
impl Default for PyConfig {
@@ -190,4 +201,7 @@ extern "C" {
190201
length: Py_ssize_t,
191202
items: *mut *mut wchar_t,
192203
) -> PyStatus;
204+
205+
#[cfg(Py_3_9)]
206+
pub fn Py_GetArgcArgv(argc: *mut c_int, argv: *mut *mut *mut wchar_t) -> c_void;
193207
}

python3-sys/src/lib.rs

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -277,14 +277,8 @@ mod fileutils;
277277
// TODO supports PEP-384 only; needs adjustment for Python 3.3 and 3.5
278278
pub mod structmember;
279279

280-
#[cfg(not(Py_LIMITED_API))]
281280
pub mod frameobject;
282281

283-
#[cfg(Py_LIMITED_API)]
284-
pub mod frameobject {
285-
pub enum PyFrameObject {}
286-
}
287-
288282
mod marshal;
289283

290284
#[cfg(all(Py_3_8, not(Py_LIMITED_API)))]

python3-sys/src/methodobject.rs

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,13 +45,15 @@ pub type _PyCFunctionFastWithKeywords = unsafe extern "C" fn(
4545
kwnames: *mut PyObject,
4646
) -> *mut PyObject;
4747

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

5051
#[cfg_attr(windows, link(name = "pythonXY"))]
5152
extern "C" {
5253
pub fn PyCFunction_GetFunction(f: *mut PyObject) -> Option<PyCFunction>;
5354
pub fn PyCFunction_GetSelf(f: *mut PyObject) -> *mut PyObject;
5455
pub fn PyCFunction_GetFlags(f: *mut PyObject) -> c_int;
56+
#[deprecated(since = "0.5.2", note = "Deprecated since Python 3.9")]
5557
pub fn PyCFunction_Call(
5658
f: *mut PyObject,
5759
args: *mut PyObject,
@@ -92,6 +94,14 @@ extern "C" {
9294
arg2: *mut PyObject,
9395
arg3: *mut PyObject,
9496
) -> *mut PyObject;
97+
98+
#[cfg(Py_3_9)]
99+
pub fn PyCMethod_New(
100+
arg1: *mut PyMethodDef,
101+
arg2: *mut PyObject,
102+
arg3: *mut PyObject,
103+
arg4: *mut PyTypeObject,
104+
) -> *mut PyObject;
95105
}
96106

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

117127
#[cfg(all(Py_3_6, not(Py_LIMITED_API)))]
118-
pub const METHOD_FASTCALL: c_int = 0x0080;
128+
pub const METH_FASTCALL: c_int = 0x0080;
129+
130+
// METH_STACKLESS: This bit is preserved for Stackless Python
131+
132+
#[cfg(all(Py_3_9))]
133+
pub const METH_METHOD: c_int = 0x0200;
119134

135+
#[cfg(not(Py_3_9))]
120136
#[cfg_attr(windows, link(name = "pythonXY"))]
121137
extern "C" {
122138
pub fn PyCFunction_ClearFreeList() -> c_int;

python3-sys/src/modsupport.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@ use libc::{c_char, c_int, c_long};
22

33
#[cfg(Py_3_5)]
44
use crate::methodobject::PyMethodDef;
5+
#[cfg(Py_3_9)]
6+
use crate::object::PyTypeObject;
57
use crate::moduleobject::PyModuleDef;
68
use crate::object::PyObject;
79
use crate::pyport::Py_ssize_t;
@@ -42,6 +44,8 @@ extern "C" {
4244
arg2: *const c_char,
4345
arg3: *const c_char,
4446
) -> c_int;
47+
#[cfg(Py_3_9)]
48+
pub fn PyModule_AddType(module: *mut PyObject, ty: *mut PyTypeObject) -> c_int;
4549
#[cfg(Py_3_5)]
4650
pub fn PyModule_SetDocString(arg1: *mut PyObject, arg2: *const c_char) -> c_int;
4751
#[cfg(Py_3_5)]

0 commit comments

Comments
 (0)