Skip to content

Commit

Permalink
Merge #2709
Browse files Browse the repository at this point in the history
2709: ci: add Python 3.12-dev jobs r=davidhewitt a=davidhewitt

Separately to #2708, time to start testing 3.12 alphas on CI. I imagine this might also take a while for the packages to come available.

Co-authored-by: David Hewitt <[email protected]>
  • Loading branch information
bors[bot] and davidhewitt authored Dec 17, 2022
2 parents 203ac5d + 9d50c2b commit 18c4f3e
Show file tree
Hide file tree
Showing 10 changed files with 148 additions and 22 deletions.
1 change: 1 addition & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,7 @@ jobs:
"3.9",
"3.10",
"3.11",
"3.12-dev",
"pypy-3.7",
"pypy-3.8",
"pypy-3.9"
Expand Down
4 changes: 2 additions & 2 deletions pyo3-ffi-check/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,9 @@ fn main() {
pyo3_ffi_align,
bindgen_align
);
} else {
pyo3_ffi_check_macro::for_all_fields!($name, check_field);
}

pyo3_ffi_check_macro::for_all_fields!($name, check_field);
}};
}

Expand Down
25 changes: 24 additions & 1 deletion pyo3-ffi/src/cpython/code.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ use crate::object::*;
use crate::pyport::Py_ssize_t;

#[allow(unused_imports)]
use std::os::raw::{c_char, c_int, c_uchar, c_void};
use std::os::raw::{c_char, c_int, c_short, c_uchar, c_void};

// skipped _Py_CODEUNIT
// skipped _Py_OPCODE
Expand All @@ -11,6 +11,16 @@ use std::os::raw::{c_char, c_int, c_uchar, c_void};
#[cfg(all(Py_3_8, not(PyPy), not(Py_3_11)))]
opaque_struct!(_PyOpcache);

#[cfg(Py_3_12)]
#[repr(C)]
#[derive(Copy, Clone)]
pub struct _PyCoCached {
pub _co_code: *mut PyObject,
pub _co_varnames: *mut PyObject,
pub _co_cellvars: *mut PyObject,
pub _co_freevars: *mut PyObject,
}

#[cfg(all(not(PyPy), not(Py_3_7)))]
opaque_struct!(PyCodeObject);

Expand Down Expand Up @@ -83,27 +93,40 @@ pub struct PyCodeObject {
pub co_names: *mut PyObject,
pub co_exceptiontable: *mut PyObject,
pub co_flags: c_int,
#[cfg(not(Py_3_12))]
pub co_warmup: c_int,
#[cfg(Py_3_12)]
pub _co_linearray_entry_size: c_short,
pub co_argcount: c_int,
pub co_posonlyargcount: c_int,
pub co_kwonlyargcount: c_int,
pub co_stacksize: c_int,
pub co_firstlineno: c_int,

pub co_nlocalsplus: c_int,
#[cfg(Py_3_12)]
pub co_framesize: c_int,
pub co_nlocals: c_int,
pub co_nplaincellvars: c_int,
pub co_ncellvars: c_int,
pub co_nfreevars: c_int,

pub co_localsplusnames: *mut PyObject,
pub co_localspluskinds: *mut PyObject,
pub co_filename: *mut PyObject,
pub co_name: *mut PyObject,
pub co_qualname: *mut PyObject,
pub co_linetable: *mut PyObject,
pub co_weakreflist: *mut PyObject,
#[cfg(not(Py_3_12))]
pub _co_code: *mut PyObject,
#[cfg(Py_3_12)]
pub _co_cached: *mut _PyCoCached,
#[cfg(not(Py_3_12))]
pub _co_linearray: *mut c_char,
pub _co_firsttraceable: c_int,
#[cfg(Py_3_12)]
pub _co_linearray: *mut c_char,
pub co_extra: *mut c_void,
pub co_code_adaptive: [c_char; 1],
}
Expand Down
15 changes: 15 additions & 0 deletions pyo3-ffi/src/cpython/compile.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,12 +30,27 @@ pub struct PyCompilerFlags {

// skipped non-limited _PyCompilerFlags_INIT

#[cfg(all(Py_3_12, not(PyPy)))]
#[repr(C)]
#[derive(Copy, Clone)]
pub struct _PyCompilerSrcLocation {
pub lineno: c_int,
pub end_lineno: c_int,
pub col_offset: c_int,
pub end_col_offset: c_int,
}

// skipped SRC_LOCATION_FROM_AST

#[cfg(not(PyPy))]
#[repr(C)]
#[derive(Copy, Clone)]
pub struct PyFutureFeatures {
pub ff_features: c_int,
#[cfg(not(Py_3_12))]
pub ff_lineno: c_int,
#[cfg(Py_3_12)]
pub ff_location: _PyCompilerSrcLocation,
}

pub const FUTURE_NESTED_SCOPES: &str = "nested_scopes";
Expand Down
6 changes: 5 additions & 1 deletion pyo3-ffi/src/cpython/initconfig.rs
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,8 @@ pub struct PyConfig {
#[cfg(all(Py_3_9, not(Py_3_10)))]
pub _use_peg_parser: c_int,
pub tracemalloc: c_int,
#[cfg(Py_3_12)]
pub perf_profiling: c_int,
pub import_time: c_int,
#[cfg(Py_3_11)]
pub code_debug_ranges: c_int,
Expand Down Expand Up @@ -137,6 +139,8 @@ pub struct PyConfig {
pub use_frozen_modules: c_int,
#[cfg(Py_3_11)]
pub safe_path: c_int,
#[cfg(Py_3_12)]
pub int_max_str_digits: c_int,
pub pathconfig_warnings: c_int,
#[cfg(Py_3_10)]
pub program_name: *mut wchar_t,
Expand All @@ -163,7 +167,7 @@ pub struct PyConfig {
pub run_filename: *mut wchar_t,
pub _install_importlib: c_int,
pub _init_main: c_int,
#[cfg(Py_3_9)]
#[cfg(all(Py_3_9, not(Py_3_12)))]
pub _isolated_interpreter: c_int,
#[cfg(Py_3_11)]
pub _is_python_build: c_int,
Expand Down
2 changes: 2 additions & 0 deletions pyo3-ffi/src/cpython/object.rs
Original file line number Diff line number Diff line change
Expand Up @@ -276,6 +276,8 @@ pub struct PyTypeObject {
pub tp_finalize: Option<object::destructor>,
#[cfg(Py_3_8)]
pub tp_vectorcall: Option<super::vectorcallfunc>,
#[cfg(Py_3_12)]
pub tp_watched: c_char,
#[cfg(any(all(PyPy, Py_3_8), all(not(PyPy), Py_3_8, not(Py_3_9))))]
pub tp_print: Option<printfunc>,
#[cfg(PyPy)]
Expand Down
2 changes: 2 additions & 0 deletions pyo3-ffi/src/cpython/pyerrors.rs
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,8 @@ pub struct PyImportErrorObject {
pub msg: *mut PyObject,
pub name: *mut PyObject,
pub path: *mut PyObject,
#[cfg(Py_3_12)]
pub name_from: *mut PyObject,
}

#[cfg(not(PyPy))]
Expand Down
46 changes: 44 additions & 2 deletions pyo3-ffi/src/cpython/unicodeobject.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#[cfg(not(PyPy))]
use crate::Py_hash_t;
use crate::{PyObject, Py_UCS1, Py_UCS2, Py_UCS4, Py_UNICODE, Py_ssize_t};
#[cfg(not(Py_3_12))]
use libc::wchar_t;
use std::os::raw::{c_char, c_int, c_uint, c_void};

Expand Down Expand Up @@ -48,6 +49,7 @@ pub struct PyASCIIObject {
/// unsigned int ready:1;
/// unsigned int :24;
pub state: u32,
#[cfg(not(Py_3_12))]
pub wstr: *mut wchar_t,
}

Expand All @@ -56,6 +58,7 @@ pub struct PyASCIIObject {
/// In addition, they are disabled on big-endian architectures to restrict this to most "common"
/// platforms, which are at least tested on CI and appear to be sound.
#[cfg(target_endian = "little")]
#[cfg(not(Py_3_12))]
impl PyASCIIObject {
#[inline]
pub unsafe fn interned(&self) -> c_uint {
Expand Down Expand Up @@ -83,11 +86,35 @@ impl PyASCIIObject {
}
}

#[cfg(Py_3_12)]
impl PyASCIIObject {
#[inline]
pub unsafe fn interned(&self) -> c_uint {
self.state & 1
}

#[inline]
pub unsafe fn kind(&self) -> c_uint {
(self.state >> 1) & 7
}

#[inline]
pub unsafe fn compact(&self) -> c_uint {
(self.state >> 4) & 1
}

#[inline]
pub unsafe fn ascii(&self) -> c_uint {
(self.state >> 5) & 1
}
}

#[repr(C)]
pub struct PyCompactUnicodeObject {
pub _base: PyASCIIObject,
pub utf8_length: Py_ssize_t,
pub utf8: *mut c_char,
#[cfg(not(Py_3_12))]
pub wstr_length: Py_ssize_t,
}

Expand Down Expand Up @@ -123,6 +150,7 @@ pub const SSTATE_INTERNED_IMMORTAL: c_uint = 2;
#[cfg(target_endian = "little")]
pub unsafe fn PyUnicode_IS_ASCII(op: *mut PyObject) -> c_uint {
debug_assert!(crate::PyUnicode_Check(op) != 0);
#[cfg(not(Py_3_12))]
debug_assert!(PyUnicode_IS_READY(op) != 0);

(*(op as *mut PyASCIIObject)).ascii()
Expand All @@ -141,7 +169,7 @@ pub unsafe fn PyUnicode_IS_COMPACT_ASCII(op: *mut PyObject) -> c_uint {
}

#[cfg(not(Py_3_12))]
#[cfg_attr(Py_3_10, deprecated(note = "Python 3.10"))]
#[deprecated(note = "Removed in Python 3.12")]
pub const PyUnicode_WCHAR_KIND: c_uint = 0;

pub const PyUnicode_1BYTE_KIND: c_uint = 1;
Expand Down Expand Up @@ -170,6 +198,7 @@ pub unsafe fn PyUnicode_4BYTE_DATA(op: *mut PyObject) -> *mut Py_UCS4 {
#[cfg(target_endian = "little")]
pub unsafe fn PyUnicode_KIND(op: *mut PyObject) -> c_uint {
debug_assert!(crate::PyUnicode_Check(op) != 0);
#[cfg(not(Py_3_12))]
debug_assert!(PyUnicode_IS_READY(op) != 0);

(*(op as *mut PyASCIIObject)).kind()
Expand Down Expand Up @@ -213,19 +242,26 @@ pub unsafe fn PyUnicode_DATA(op: *mut PyObject) -> *mut c_void {
#[cfg(target_endian = "little")]
pub unsafe fn PyUnicode_GET_LENGTH(op: *mut PyObject) -> Py_ssize_t {
debug_assert!(crate::PyUnicode_Check(op) != 0);
#[cfg(not(Py_3_12))]
debug_assert!(PyUnicode_IS_READY(op) != 0);

(*(op as *mut PyASCIIObject)).length
}

#[inline]
#[cfg(not(Py_3_12))]
#[cfg(target_endian = "little")]
pub unsafe fn PyUnicode_IS_READY(op: *mut PyObject) -> c_uint {
(*(op as *mut PyASCIIObject)).ready()
}

#[inline]
#[cfg(Py_3_12)]
pub unsafe fn PyUnicode_IS_READY(_: *mut PyObject) -> c_uint {
1
}

#[cfg(not(Py_3_12))]
#[cfg_attr(Py_3_10, deprecated(note = "Python 3.10"))]
#[inline]
#[cfg(target_endian = "little")]
pub unsafe fn PyUnicode_READY(op: *mut PyObject) -> c_int {
Expand All @@ -238,6 +274,12 @@ pub unsafe fn PyUnicode_READY(op: *mut PyObject) -> c_int {
}
}

#[cfg(Py_3_12)]
#[inline]
pub unsafe fn PyUnicode_READY(_: *mut PyObject) -> c_int {
0
}

// skipped PyUnicode_MAX_CHAR_VALUE
// skipped _PyUnicode_get_wstr_length
// skipped PyUnicode_WSTR_LENGTH
Expand Down
2 changes: 2 additions & 0 deletions pyo3-ffi/src/unicodeobject.rs
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,8 @@ extern "C" {
pub fn PyUnicode_AsUCS4Copy(unicode: *mut PyObject) -> *mut Py_UCS4;
#[cfg_attr(PyPy, link_name = "PyPyUnicode_GetLength")]
pub fn PyUnicode_GetLength(unicode: *mut PyObject) -> Py_ssize_t;
#[cfg(not(Py_3_12))]
#[deprecated(note = "Removed in Python 3.12")]
#[cfg_attr(PyPy, link_name = "PyPyUnicode_GetSize")]
pub fn PyUnicode_GetSize(unicode: *mut PyObject) -> Py_ssize_t;
pub fn PyUnicode_ReadChar(unicode: *mut PyObject, index: Py_ssize_t) -> Py_UCS4;
Expand Down
Loading

0 comments on commit 18c4f3e

Please sign in to comment.