Skip to content

Commit fb6515d

Browse files
authored
Python 3.11 support (#514)
1 parent 1050036 commit fb6515d

File tree

11 files changed

+6493
-109
lines changed

11 files changed

+6493
-109
lines changed

.github/workflows/build.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -164,7 +164,7 @@ jobs:
164164
strategy:
165165
fail-fast: false
166166
matrix:
167-
python-version: [2.7.17, 2.7.18, 3.5.4, 3.5.9, 3.5.10, 3.6.7, 3.6.8, 3.6.9, 3.6.10, 3.6.11, 3.6.12, 3.6.13, 3.6.14, 3.6.15, 3.7.1, 3.7.5, 3.7.6, 3.7.7, 3.7.8, 3.7.9, 3.7.10, 3.7.11, 3.7.12, 3.7.13, 3.8.0, 3.8.1, 3.8.2, 3.8.3, 3.8.4, 3.8.5, 3.8.6, 3.8.7, 3.8.8, 3.8.9, 3.8.10, 3.8.11, 3.8.12, 3.8.13, 3.9.0, 3.9.1, 3.9.2, 3.9.3, 3.9.4, 3.9.5, 3.9.6, 3.9.7, 3.9.8, 3.9.9, 3.9.10, 3.9.11, 3.9.12, 3.9.13, 3.10.0, 3.10.1, 3.10.2, 3.10.3, 3.10.4, 3.10.5, 3.10.6]
167+
python-version: [2.7.17, 2.7.18, 3.5.4, 3.5.9, 3.5.10, 3.6.7, 3.6.8, 3.6.9, 3.6.10, 3.6.11, 3.6.12, 3.6.13, 3.6.14, 3.6.15, 3.7.1, 3.7.5, 3.7.6, 3.7.7, 3.7.8, 3.7.9, 3.7.10, 3.7.11, 3.7.12, 3.7.13, 3.8.0, 3.8.1, 3.8.2, 3.8.3, 3.8.4, 3.8.5, 3.8.6, 3.8.7, 3.8.8, 3.8.9, 3.8.10, 3.8.11, 3.8.12, 3.8.13, 3.9.0, 3.9.1, 3.9.2, 3.9.3, 3.9.4, 3.9.5, 3.9.6, 3.9.7, 3.9.8, 3.9.9, 3.9.10, 3.9.11, 3.9.12, 3.9.13, 3.10.0, 3.10.1, 3.10.2, 3.10.3, 3.10.4, 3.10.5, 3.10.6, 3.11.0-beta.5]
168168
# TODO: also test windows
169169
os: [ubuntu-latest, macos-latest]
170170
steps:

ci/update_python_test_versions.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,8 @@ def get_github_python_versions():
1414
versions_json = requests.get(_VERSIONS_URL).json()
1515
raw_versions = [v["version"] for v in versions_json]
1616
versions = []
17-
for version_str in raw_versions:
18-
if "-" in version_str:
17+
for version_str in raw_versions:
18+
if "-" in version_str and version_str != "3.11.0-beta.5":
1919
continue
2020

2121
major, minor, patch = parse_version(version_str)

generate_bindings.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -109,10 +109,10 @@ def extract_bindings(cpython_path, version, configure=False):
109109
110110
cat Include/Python.h > bindgen_input.h
111111
cat Include/frameobject.h >> bindgen_input.h
112-
cat Objects/dict-common.h >> bindgen_input.h
113112
echo '#define Py_BUILD_CORE 1\n' >> bindgen_input.h
114113
cat Include/internal/pycore_pystate.h >> bindgen_input.h
115114
cat Include/internal/pycore_interp.h >> bindgen_input.h
115+
cat Include/internal/pycore_frame.h >> bindgen_input.h
116116
117117
bindgen bindgen_input.h -o bindgen_output.rs \
118118
--with-derive-default \
@@ -126,17 +126,17 @@ def extract_bindings(cpython_path, version, configure=False):
126126
--whitelist-type PyASCIIObject \
127127
--whitelist-type PyUnicodeObject \
128128
--whitelist-type PyCompactUnicodeObject \
129-
--whitelist-type PyStringObject \
130129
--whitelist-type PyTupleObject \
131130
--whitelist-type PyListObject \
132-
--whitelist-type PyIntObject \
133131
--whitelist-type PyLongObject \
134132
--whitelist-type PyFloatObject \
135133
--whitelist-type PyDictObject \
136134
--whitelist-type PyDictKeysObject \
137135
--whitelist-type PyDictKeyEntry \
136+
--whitelist-type PyDictUnicodeEntry \
138137
--whitelist-type PyObject \
139138
--whitelist-type PyTypeObject \
139+
--whitelist-type PyHeapTypeObject \
140140
-- -I . -I ./Include -I ./Include/internal
141141
""")
142142
if ret:

src/python_bindings/mod.rs

Lines changed: 16 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ pub mod v3_7_0;
66
pub mod v3_8_0;
77
pub mod v3_9_5;
88
pub mod v3_10_0;
9+
pub mod v3_11_0;
910

1011
// currently the PyRuntime struct used from Python 3.7 on really can't be
1112
// exposed in a cross platform way using bindgen. PyRuntime has several mutex's
@@ -52,6 +53,7 @@ pub mod pyruntime {
5253
}
5354
},
5455
Version{major: 3, minor: 8..=10, ..} => 32,
56+
Version{major: 3, minor: 11, ..} => 40,
5557
_ => 24
5658
}
5759
}
@@ -62,19 +64,20 @@ pub mod pyruntime {
6264
#[cfg(target_os="macos")]
6365
pub fn get_tstate_current_offset(version: &Version) -> Option<usize> {
6466
match version {
65-
Version{major: 3, minor: 7, patch: 0..=3, ..} => Some(1440),
66-
Version{major: 3, minor: 7, ..} => Some(1528),
67-
Version{major: 3, minor: 8, patch: 0, ..} => {
68-
match version.release_flags.as_ref() {
67+
Version{major: 3, minor: 7, patch: 0..=3, ..} => Some(1440),
68+
Version{major: 3, minor: 7, ..} => Some(1528),
69+
Version{major: 3, minor: 8, patch: 0, ..} => {
70+
match version.release_flags.as_ref() {
6971
"a1" => Some(1432),
7072
"a2" => Some(888),
7173
"a3" | "a4" => Some(1448),
7274
_ => Some(1416),
7375
}
74-
},
75-
Version{major: 3, minor: 8, ..} => { Some(1416) },
76-
Version{major: 3, minor: 9..=10, ..} => { Some(616) },
77-
_ => None
76+
},
77+
Version{major: 3, minor: 8, ..} => { Some(1416) },
78+
Version{major: 3, minor: 9..=10, ..} => { Some(616) },
79+
Version{major: 3, minor: 11, ..} => Some(624),
80+
_ => None
7881
}
7982
}
8083

@@ -101,7 +104,7 @@ pub mod pyruntime {
101104
match version {
102105
Version{major: 3, minor: 7, ..} => Some(828),
103106
Version{major: 3, minor: 8, ..} => Some(804),
104-
Version{major: 3, minor: 9..=10, ..} => Some(364),
107+
Version{major: 3, minor: 9..=11, ..} => Some(364),
105108
_ => None
106109
}
107110
}
@@ -113,6 +116,7 @@ pub mod pyruntime {
113116
Version{major: 3, minor: 7, ..} => Some(1496),
114117
Version{major: 3, minor: 8, ..} => Some(1384),
115118
Version{major: 3, minor: 9..=10, ..} => Some(584),
119+
Version{major: 3, minor: 11, ..} => Some(592),
116120
_ => None
117121
}
118122
}
@@ -132,6 +136,7 @@ pub mod pyruntime {
132136
},
133137
Version{major: 3, minor: 8, ..} => Some(1368),
134138
Version{major: 3, minor: 9..=10, ..} => Some(568),
139+
Version{major: 3, minor: 11, ..} => Some(576),
135140
_ => None
136141
}
137142
}
@@ -155,6 +160,7 @@ pub mod pyruntime {
155160
},
156161
Version{major: 3, minor: 8, ..} => Some(1296),
157162
Version{major: 3, minor: 9..=10, ..} => Some(496),
163+
Version{major: 3, minor: 11, ..} => Some(504),
158164
_ => None
159165
}
160166
}
@@ -174,6 +180,7 @@ pub mod pyruntime {
174180
},
175181
Version{major: 3, minor: 8, ..} => Some(1224),
176182
Version{major: 3, minor: 9..=10, ..} => Some(424),
183+
Version{major: 3, minor: 11, ..} => Some(432),
177184
_ => None
178185
}
179186
}

0 commit comments

Comments
 (0)