Skip to content

Commit 4fe0dc7

Browse files
committed
python3-sys: port Py_3_12 changes from pyo3-ffi
I looked at all Py_3_12 changes in pyo3-ffi/src/cpython and ported them back. Functions, structs, and fields in the code object not already defined in python3-sys are ignored. For PyUnicode_READY, I kept a dummy version so the cpython crate does not need change.
1 parent e815555 commit 4fe0dc7

File tree

5 files changed

+56
-11
lines changed

5 files changed

+56
-11
lines changed

python3-sys/src/code.rs

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,18 +23,23 @@ pub struct PyCodeObject {
2323
pub co_names: *mut PyObject,
2424
pub co_exceptiontable: *mut PyObject,
2525
pub co_flags: c_int,
26+
#[cfg(not(Py_3_12))]
2627
pub co_warmup: c_short,
27-
co_linearray_entry_size: c_short,
2828
pub co_argcount: c_int,
2929
pub co_posonlyargcount: c_int,
3030
pub co_kwonlyargcount: c_int,
3131
pub co_stacksize: c_int,
3232
pub co_firstlineno: c_int,
3333
pub co_nlocalsplus: c_int,
34+
#[cfg(Py_3_12)]
35+
pub co_framesize: c_int,
3436
pub co_nlocals: c_int,
37+
#[cfg(not(Py_3_12))]
3538
pub co_nplaincellvars: c_int,
3639
pub co_ncellvars: c_int,
3740
pub co_nfreevars: c_int,
41+
#[cfg(Py_3_12)]
42+
pub co_version: u32,
3843
pub co_localsplusnames: *mut PyObject,
3944
pub co_localspluskinds: *mut PyObject,
4045
pub co_filename: *mut PyObject,

python3-sys/src/compile.rs

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,25 @@ use crate::object::PyObject;
77
use crate::pyarena::*;
88
use crate::pythonrun::*;
99

10+
#[repr(C)]
11+
#[derive(Copy, Clone)]
12+
#[cfg(Py_3_12)]
13+
pub struct _PyCompilerSrcLocation {
14+
pub lineno: c_int,
15+
pub end_lineno: c_int,
16+
pub col_offset: c_int,
17+
pub end_col_offset: c_int,
18+
}
19+
1020
#[repr(C)]
1121
#[derive(Copy, Clone)]
1222
#[cfg(not(Py_LIMITED_API))]
1323
pub struct PyFutureFeatures {
1424
pub ff_features: c_int,
25+
#[cfg(not(Py_3_12))]
1526
pub ff_lineno: c_int,
27+
#[cfg(Py_3_12)]
28+
pub ff_location: _PyCompilerSrcLocation,
1629
}
1730

1831
// TODO: PyCF_MASK etc. constants

python3-sys/src/initconfig.rs

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,8 @@ pub struct PyConfig {
107107
#[cfg(all(Py_3_9, not(Py_3_10)))]
108108
pub _use_peg_parser: c_int,
109109
pub tracemalloc: c_int,
110+
#[cfg(Py_3_12)]
111+
pub perf_profiling: c_int,
110112
pub import_time: c_int,
111113
#[cfg(Py_3_11)]
112114
pub code_debug_ranges: c_int,
@@ -151,6 +153,8 @@ pub struct PyConfig {
151153
pub use_frozen_modules: c_int,
152154
#[cfg(Py_3_11)]
153155
pub safe_path: c_int,
156+
#[cfg(Py_3_12)]
157+
pub int_max_str_digits: c_int,
154158
// Path configuration inputs:
155159
pub pathconfig_warnings: c_int,
156160
#[cfg(Py_3_10)]
@@ -180,12 +184,12 @@ pub struct PyConfig {
180184
// Private fields
181185
pub _install_importlib: c_int,
182186
pub _init_main: c_int,
183-
#[cfg(Py_3_9)]
187+
#[cfg(all(Py_3_9, not(Py_3_12)))]
184188
pub _isolated_interpreter: c_int,
185-
#[cfg(all(Py_3_9, not(Py_3_10)))]
186-
pub _orig_argv: PyWideStringList,
187189
#[cfg(Py_3_11)]
188190
pub _is_python_build: c_int,
191+
#[cfg(all(Py_3_9, not(Py_3_10)))]
192+
pub _orig_argv: PyWideStringList,
189193
}
190194

191195
impl Default for PyConfig {

python3-sys/src/object.rs

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -436,6 +436,8 @@ mod typeobject {
436436
pub tp_finalize: Option<crate::object::destructor>,
437437
#[cfg(Py_3_8)]
438438
pub tp_vectorcall: Option<crate::object::vectorcallfunc>,
439+
#[cfg(Py_3_12)]
440+
pub tp_watched: c_char,
439441
#[cfg(all(Py_3_8, not(Py_3_9)))]
440442
pub tp_print: Option<crate::object::printfunc>,
441443
#[cfg(all(py_sys_config = "COUNT_ALLOCS", not(Py_3_9)))]
@@ -535,7 +537,16 @@ mod typeobject {
535537
}
536538
}
537539

538-
#[cfg(Py_3_9)]
540+
#[cfg(Py_3_12)]
541+
pub const PyTypeObject_INIT: PyTypeObject = py_type_object_init_with_count_allocs!(
542+
tp_as_async: 0 as *mut PyAsyncMethods,
543+
tp_vectorcall_offset: 0,
544+
tp_vectorcall: None,
545+
tp_finalize: None,
546+
tp_watched: 0,
547+
);
548+
549+
#[cfg(all(Py_3_9, not(Py_3_12)))]
539550
pub const PyTypeObject_INIT: PyTypeObject = py_type_object_init_with_count_allocs!(
540551
tp_as_async: 0 as *mut PyAsyncMethods,
541552
tp_vectorcall_offset: 0,

python3-sys/src/unicodeobject.rs

Lines changed: 18 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -435,7 +435,7 @@ extern "C" {
435435
#[deprecated(since = "0.6.1", note = "Deprecated since Python 3.3; removed in 3.10")]
436436
pub fn PyUnicode_AsUnicodeCopy(unicode: *mut PyObject) -> *mut Py_UNICODE;
437437

438-
#[cfg(not(Py_LIMITED_API))]
438+
#[cfg(not(any(Py_LIMITED_API, Py_3_12)))]
439439
fn _PyUnicode_Ready(o: *mut PyObject) -> c_int;
440440
}
441441

@@ -446,6 +446,7 @@ pub struct PyASCIIObject {
446446
pub length: Py_ssize_t,
447447
pub hash: Py_hash_t,
448448
pub state: u32,
449+
#[cfg(not(Py_3_12))]
449450
pub wstr: *mut c_void,
450451
}
451452

@@ -455,6 +456,7 @@ pub struct PyCompactUnicodeObject {
455456
_base: PyASCIIObject,
456457
utf8_length: Py_ssize_t,
457458
utf8: *mut u8,
459+
#[cfg(not(Py_3_12))]
458460
wstr_length: Py_ssize_t,
459461
}
460462

@@ -494,6 +496,7 @@ pub const PyUnicode_4BYTE_KIND: u32 = 4;
494496
#[inline]
495497
pub unsafe fn PyUnicode_KIND(o: *mut PyObject) -> u32 {
496498
debug_assert!(PyUnicode_Check(o) > 0);
499+
#[cfg(not(Py_3_12))]
497500
debug_assert!(PyUnicode_IS_READY(o));
498501
let state = (*(o as *mut PyASCIIObject)).state;
499502
(state >> 2) & 7
@@ -502,6 +505,7 @@ pub unsafe fn PyUnicode_KIND(o: *mut PyObject) -> u32 {
502505
#[cfg(not(Py_LIMITED_API))]
503506
pub unsafe fn PyUnicode_DATA(o: *mut PyObject) -> *mut c_void {
504507
debug_assert!(PyUnicode_Check(o) > 0);
508+
#[cfg(not(Py_3_12))]
505509
debug_assert!(PyUnicode_IS_READY(o));
506510
if PyUnicode_IS_COMPACT(o) {
507511
// fn _PyUnicode_COMPACT_DATA
@@ -522,11 +526,12 @@ pub unsafe fn PyUnicode_DATA(o: *mut PyObject) -> *mut c_void {
522526
#[inline]
523527
pub unsafe fn PyUnicode_GET_LENGTH(o: *mut PyObject) -> Py_ssize_t {
524528
debug_assert!(PyUnicode_Check(o) > 0);
529+
#[cfg(not(Py_3_12))]
525530
debug_assert!(PyUnicode_IS_READY(o));
526531
(*(o as *mut PyASCIIObject)).length
527532
}
528533

529-
#[cfg(not(Py_LIMITED_API))]
534+
#[cfg(not(any(Py_LIMITED_API, Py_3_12)))]
530535
#[inline]
531536
unsafe fn PyUnicode_IS_READY(o: *mut PyObject) -> bool {
532537
let ready_bit = 1 << 7;
@@ -538,9 +543,16 @@ unsafe fn PyUnicode_IS_READY(o: *mut PyObject) -> bool {
538543
#[inline]
539544
pub unsafe fn PyUnicode_READY(o: *mut PyObject) -> c_int {
540545
debug_assert!(PyUnicode_Check(o) > 0);
541-
if PyUnicode_IS_READY(o) {
542-
0
543-
} else {
544-
_PyUnicode_Ready(o)
546+
#[cfg(Py_3_12)]
547+
{
548+
return 0;
549+
}
550+
#[cfg(not(Py_3_12))]
551+
{
552+
if PyUnicode_IS_READY(o) {
553+
0
554+
} else {
555+
_PyUnicode_Ready(o)
556+
}
545557
}
546558
}

0 commit comments

Comments
 (0)