Skip to content

Commit 78df489

Browse files
committed
Fix Python 3.7 support.
Closes #144, #147.
1 parent 5309f8d commit 78df489

File tree

16 files changed

+97
-35
lines changed

16 files changed

+97
-35
lines changed

python3-sys/src/ceval.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ pub unsafe fn PyEval_CallObject(callable: *mut PyObject, arg: *mut PyObject) ->
1919
format: *const c_char, ...)
2020
-> *mut PyObject;
2121
pub fn PyEval_CallMethod(obj: *mut PyObject,
22-
methodname: *const c_char,
22+
name: *const c_char,
2323
format: *const c_char, ...)
2424
-> *mut PyObject;
2525
pub fn PyEval_GetBuiltins() -> *mut PyObject;
@@ -51,7 +51,7 @@ pub unsafe fn PyEval_CallObject(callable: *mut PyObject, arg: *mut PyObject) ->
5151
pub fn PyEval_RestoreThread(arg1: *mut PyThreadState) -> ();
5252
}
5353

54-
#[cfg(py_sys_config = "WITH_THREAD")]
54+
#[cfg(any(Py_3_7, py_sys_config = "WITH_THREAD"))]
5555
#[cfg_attr(windows, link(name="pythonXY"))] extern "C" {
5656
pub fn PyEval_ThreadsInitialized() -> c_int;
5757
pub fn PyEval_InitThreads() -> ();

python3-sys/src/descrobject.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,10 +16,16 @@ pub type setter =
1616
#[repr(C)]
1717
#[derive(Copy)]
1818
pub struct PyGetSetDef {
19+
#[cfg(not(Py_3_7))]
1920
pub name: *mut c_char,
21+
#[cfg(Py_3_7)]
22+
pub name: *const c_char,
2023
pub get: Option<getter>,
2124
pub set: Option<setter>,
25+
#[cfg(not(Py_3_7))]
2226
pub doc: *mut c_char,
27+
#[cfg(Py_3_7)]
28+
pub doc: *const c_char,
2329
pub closure: *mut c_void,
2430
}
2531

python3-sys/src/eval.rs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,10 @@ use object::PyObject;
44
#[cfg_attr(windows, link(name="pythonXY"))] extern "C" {
55
pub fn PyEval_EvalCode(arg1: *mut PyObject, arg2: *mut PyObject,
66
arg3: *mut PyObject) -> *mut PyObject;
7-
pub fn PyEval_EvalCodeEx(co: *mut PyObject, globals: *mut PyObject,
8-
locals: *mut PyObject, args: *mut *mut PyObject,
9-
argc: c_int, kwds: *mut *mut PyObject,
10-
kwdc: c_int, defs: *mut *mut PyObject,
11-
defc: c_int, kwdefs: *mut PyObject,
12-
closure: *mut PyObject) -> *mut PyObject;
7+
pub fn PyEval_EvalCodeEx(co: *mut PyObject,
8+
globals: *mut PyObject, locals: *mut PyObject,
9+
args: *const *mut PyObject, argc: c_int,
10+
kwds: *const *mut PyObject, kwdc: c_int,
11+
defs: *const *mut PyObject, defc: c_int,
12+
kwdefs: *mut PyObject, closure: *mut PyObject) -> *mut PyObject;
1313
}

python3-sys/src/fileobject.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,5 +21,7 @@ pub const PY_STDIOTEXTMODE : &'static str = "b";
2121
#[cfg(Py_3_6)]
2222
pub static mut Py_FileSystemDefaultEncodeErrors: *const c_char;
2323
pub static mut Py_HasFileSystemDefaultEncoding: c_int;
24+
#[cfg(Py_3_7)]
25+
pub static mut Py_UTF8Mode: c_int;
2426
}
2527

python3-sys/src/frameobject.rs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,10 +27,18 @@ pub struct PyFrameObject {
2727
pub f_stacktop: *mut *mut PyObject,
2828
pub f_trace: *mut PyObject, /* Trace function */
2929

30+
#[cfg(not(Py_3_7))]
3031
pub f_exc_type: *mut PyObject,
32+
#[cfg(not(Py_3_7))]
3133
pub f_exc_value: *mut PyObject,
34+
#[cfg(not(Py_3_7))]
3235
pub f_exc_traceback: *mut PyObject,
3336

37+
#[cfg(Py_3_7)]
38+
pub f_trace_lines: c_char,
39+
#[cfg(Py_3_7)]
40+
pub f_trace_opcodes: c_char,
41+
3442
#[cfg(not(Py_3_4))]
3543
pub f_tstate: *mut PyThreadState,
3644

python3-sys/src/import.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,8 @@ use object::PyObject;
2323
cpathname: *mut PyObject)
2424
-> *mut PyObject;
2525
pub fn PyImport_GetModuleDict() -> *mut PyObject;
26+
#[cfg(Py_3_7)]
27+
pub fn PyImport_GetModule(name: *mut PyObject) -> *mut PyObject;
2628
pub fn PyImport_AddModuleObject(name: *mut PyObject) -> *mut PyObject;
2729
pub fn PyImport_AddModule(name: *const c_char) -> *mut PyObject;
2830
pub fn PyImport_ImportModule(name: *const c_char)
@@ -61,6 +63,8 @@ pub unsafe fn PyImport_ImportModuleEx(name: *const c_char,
6163
pub fn PyImport_ImportFrozenModule(name: *const c_char)
6264
-> c_int;
6365

66+
// pub static mut PyNullImporter_Type: PyTypeObject; -- does not actually exist in shared library
67+
6468
pub fn PyImport_AppendInittab(name: *const c_char,
6569
initfunc: Option<extern "C" fn() -> *mut PyObject>)
6670
-> c_int;

python3-sys/src/intrcheck.rs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,13 @@
11
use libc::c_int;
22

33
#[cfg_attr(windows, link(name="pythonXY"))] extern "C" {
4+
#[cfg(all(unix, Py_3_7))]
5+
pub fn PyOS_BeforeFork() -> ();
6+
#[cfg(all(unix, Py_3_7))]
7+
pub fn PyOS_AfterFork_Parent() -> ();
8+
#[cfg(all(unix, Py_3_7))]
9+
pub fn PyOS_AfterFork_Child() -> ();
10+
411
pub fn PyOS_InterruptOccurred() -> c_int;
512
pub fn PyOS_InitInterrupts() -> ();
613
pub fn PyOS_AfterFork() -> ();

python3-sys/src/methodobject.rs

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,17 +16,33 @@ pub type PyCFunction =
1616
(slf: *mut PyObject, args: *mut PyObject)
1717
-> *mut PyObject;
1818

19-
#[cfg(all(Py_3_6, not(Py_LIMITED_API)))]
19+
#[cfg(all(Py_3_6, not(Py_LIMITED_API), not(Py_3_7)))]
2020
pub type _PyCFunctionFast =
2121
unsafe extern "C" fn
2222
(slf: *mut PyObject, args: *mut *mut PyObject,
2323
nargs: ::pyport::Py_ssize_t, kwnames: *mut PyObject)
2424
-> *mut PyObject;
2525

26+
#[cfg(all(Py_3_7, not(Py_LIMITED_API)))]
27+
pub type _PyCFunctionFast =
28+
unsafe extern "C" fn(
29+
slf: *mut PyObject,
30+
args: *const *mut PyObject, nargs: ::pyport::Py_ssize_t
31+
) -> *mut PyObject;
32+
2633
pub type PyCFunctionWithKeywords =
2734
unsafe extern "C" fn
2835
(slf: *mut PyObject, args: *mut PyObject,
2936
kwds: *mut PyObject) -> *mut PyObject;
37+
38+
#[cfg(all(Py_3_7, not(Py_LIMITED_API)))]
39+
pub type _PyCFunctionFastWithKeywords =
40+
unsafe extern "C" fn(
41+
slf: *mut PyObject,
42+
args: *const *mut PyObject, nargs: ::pyport::Py_ssize_t,
43+
kwnames: *mut PyObject
44+
) -> *mut PyObject;
45+
3046
pub type PyNoArgsFunction =
3147
unsafe extern "C" fn(slf: *mut PyObject)
3248
-> *mut PyObject;

python3-sys/src/objectabstract.rs

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -14,23 +14,23 @@ pub unsafe fn PyObject_DelAttr(o: *mut PyObject, attr_name: *mut PyObject) -> c_
1414
}
1515

1616
#[cfg_attr(windows, link(name="pythonXY"))] extern "C" {
17-
pub fn PyObject_Call(callable_object: *mut PyObject, args: *mut PyObject,
18-
kw: *mut PyObject) -> *mut PyObject;
19-
pub fn PyObject_CallObject(callable_object: *mut PyObject,
17+
pub fn PyObject_Call(callable: *mut PyObject, args: *mut PyObject,
18+
kwargs: *mut PyObject) -> *mut PyObject;
19+
pub fn PyObject_CallObject(callable: *mut PyObject,
2020
args: *mut PyObject) -> *mut PyObject;
21-
pub fn PyObject_CallFunction(callable_object: *mut PyObject,
21+
pub fn PyObject_CallFunction(callable: *mut PyObject,
2222
format: *const c_char, ...)
2323
-> *mut PyObject;
24-
pub fn PyObject_CallMethod(o: *mut PyObject,
25-
method: *const c_char,
24+
pub fn PyObject_CallMethod(obj: *mut PyObject,
25+
name: *const c_char,
2626
format: *const c_char, ...)
2727
-> *mut PyObject;
28-
28+
2929

3030
pub fn PyObject_CallFunctionObjArgs(callable: *mut PyObject, ...)
3131
-> *mut PyObject;
32-
pub fn PyObject_CallMethodObjArgs(o: *mut PyObject,
33-
method: *mut PyObject, ...)
32+
pub fn PyObject_CallMethodObjArgs(obj: *mut PyObject,
33+
name: *mut PyObject, ...)
3434
-> *mut PyObject;
3535
pub fn PyObject_Type(o: *mut PyObject) -> *mut PyObject;
3636
pub fn PyObject_Size(o: *mut PyObject) -> Py_ssize_t;

python3-sys/src/pydebug.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ use libc::c_int;
1010
pub static mut Py_OptimizeFlag: c_int;
1111
pub static mut Py_NoSiteFlag: c_int;
1212
pub static mut Py_BytesWarningFlag: c_int;
13+
#[cfg(not(Py_3_7))]
1314
pub static mut Py_UseClassExceptionsFlag: c_int;
1415
pub static mut Py_FrozenFlag: c_int;
1516
pub static mut Py_IgnoreEnvironmentFlag: c_int;
@@ -19,6 +20,8 @@ use libc::c_int;
1920
pub static mut Py_HashRandomizationFlag: c_int;
2021
#[cfg(Py_3_4)]
2122
pub static mut Py_IsolatedFlag: c_int;
23+
#[cfg(all(Py_3_7, windows))]
24+
pub static mut Py_LegacyWindowsFSEncodingFlag: c_int;
2225
#[cfg(all(Py_3_6, windows))]
2326
pub static mut Py_LegacyWindowsStdioFlag: c_int;
2427
}

0 commit comments

Comments
 (0)