Skip to content

Commit 2c732a7

Browse files
mattipIcxolu
andauthored
Add PyPy3.11 (PyO3#4760)
* allow pypy3.11 * run CI on pypy3.11 * change const declaration * change link name for PyExc_BaseExceptionGroup * PyObject_DelAttr* are inline functions on pypy3.11 * use nightly until official release * DOC: add a news fragment * conditionally compile 'use' statements * fix format * changes from review * pypy 3.11 released * fixes for PyPy * typo * exclude _PyInterpreterFrame on PyPy * more pypy fixes * more excluding _PyFrameEvalFunction on PyPy * fixes for PyPy struct differences * format * fix test --------- Co-authored-by: Icxolu <[email protected]>
1 parent ded1600 commit 2c732a7

17 files changed

+35
-22
lines changed

.github/workflows/ci.yml

+1
Original file line numberDiff line numberDiff line change
@@ -254,6 +254,7 @@ jobs:
254254
"3.13",
255255
"pypy3.9",
256256
"pypy3.10",
257+
"pypy3.11",
257258
"graalpy24.0",
258259
"graalpy24.1",
259260
]

newsfragments/4760.packaging.md

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
add support for PyPy3.11

noxfile.py

+3-3
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@
4242
PYO3_GUIDE_TARGET = PYO3_TARGET / "guide"
4343
PYO3_DOCS_TARGET = PYO3_TARGET / "doc"
4444
PY_VERSIONS = ("3.7", "3.8", "3.9", "3.10", "3.11", "3.12", "3.13")
45-
PYPY_VERSIONS = ("3.9", "3.10")
45+
PYPY_VERSIONS = ("3.9", "3.10", "3.11")
4646
FREE_THREADED_BUILD = bool(sysconfig.get_config_var("Py_GIL_DISABLED"))
4747

4848

@@ -689,8 +689,8 @@ def test_version_limits(session: nox.Session):
689689
config_file.set("PyPy", "3.8")
690690
_run_cargo(session, "check", env=env, expect_error=True)
691691

692-
assert "3.11" not in PYPY_VERSIONS
693-
config_file.set("PyPy", "3.11")
692+
assert "3.12" not in PYPY_VERSIONS
693+
config_file.set("PyPy", "3.12")
694694
_run_cargo(session, "check", env=env, expect_error=True)
695695

696696

pyo3-ffi/build.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ const SUPPORTED_VERSIONS_PYPY: SupportedVersions = SupportedVersions {
2525
min: PythonVersion { major: 3, minor: 9 },
2626
max: PythonVersion {
2727
major: 3,
28-
minor: 10,
28+
minor: 11,
2929
},
3030
};
3131

pyo3-ffi/src/abstract_.rs

+8-2
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,19 @@ use libc::size_t;
55
use std::os::raw::{c_char, c_int};
66

77
#[inline]
8-
#[cfg(all(not(Py_3_13), not(PyPy)))] // CPython exposed as a function in 3.13, in object.h
8+
#[cfg(all(
9+
not(Py_3_13), // CPython exposed as a function in 3.13, in object.h
10+
not(all(PyPy, not(Py_3_11))) // PyPy exposed as a function until PyPy 3.10, macro in 3.11+
11+
))]
912
pub unsafe fn PyObject_DelAttrString(o: *mut PyObject, attr_name: *const c_char) -> c_int {
1013
PyObject_SetAttrString(o, attr_name, std::ptr::null_mut())
1114
}
1215

1316
#[inline]
14-
#[cfg(all(not(Py_3_13), not(PyPy)))] // CPython exposed as a function in 3.13, in object.h
17+
#[cfg(all(
18+
not(Py_3_13), // CPython exposed as a function in 3.13, in object.h
19+
not(all(PyPy, not(Py_3_11))) // PyPy exposed as a function until PyPy 3.10, macro in 3.11+
20+
))]
1521
pub unsafe fn PyObject_DelAttr(o: *mut PyObject, attr_name: *mut PyObject) -> c_int {
1622
PyObject_SetAttr(o, attr_name, std::ptr::null_mut())
1723
}

pyo3-ffi/src/cpython/abstract_.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
use crate::{PyObject, Py_ssize_t};
2-
#[cfg(not(all(Py_3_11, GraalPy)))]
2+
#[cfg(any(all(Py_3_8, not(any(PyPy, GraalPy))), not(Py_3_11)))]
33
use std::os::raw::c_char;
44
use std::os::raw::c_int;
55

pyo3-ffi/src/cpython/genobject.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ use crate::object::*;
22
use crate::PyFrameObject;
33
#[cfg(not(any(PyPy, GraalPy)))]
44
use crate::_PyErr_StackItem;
5-
#[cfg(all(Py_3_11, not(GraalPy)))]
5+
#[cfg(all(Py_3_11, not(any(PyPy, GraalPy))))]
66
use std::os::raw::c_char;
77
use std::os::raw::c_int;
88
use std::ptr::addr_of_mut;

pyo3-ffi/src/cpython/mod.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ pub use self::object::*;
7171
pub use self::objimpl::*;
7272
pub use self::pydebug::*;
7373
pub use self::pyerrors::*;
74-
#[cfg(Py_3_11)]
74+
#[cfg(all(Py_3_11, not(PyPy)))]
7575
pub use self::pyframe::*;
7676
#[cfg(all(Py_3_8, not(PyPy)))]
7777
pub use self::pylifecycle::*;

pyo3-ffi/src/cpython/object.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -310,9 +310,9 @@ pub struct PyHeapTypeObject {
310310
pub ht_cached_keys: *mut c_void,
311311
#[cfg(Py_3_9)]
312312
pub ht_module: *mut object::PyObject,
313-
#[cfg(Py_3_11)]
313+
#[cfg(all(Py_3_11, not(PyPy)))]
314314
_ht_tpname: *mut c_char,
315-
#[cfg(Py_3_11)]
315+
#[cfg(all(Py_3_11, not(PyPy)))]
316316
_spec_cache: _specialization_cache,
317317
}
318318

pyo3-ffi/src/cpython/objimpl.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
#[cfg(not(all(Py_3_11, GraalPy)))]
1+
#[cfg(not(all(Py_3_11, any(PyPy, GraalPy))))]
22
use libc::size_t;
33
use std::os::raw::c_int;
44

pyo3-ffi/src/cpython/pyframe.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
1-
#[cfg(Py_3_11)]
1+
#[cfg(all(Py_3_11, not(PyPy)))]
22
opaque_struct!(_PyInterpreterFrame);

pyo3-ffi/src/cpython/pystate.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -69,21 +69,21 @@ extern "C" {
6969
pub fn PyThreadState_DeleteCurrent();
7070
}
7171

72-
#[cfg(all(Py_3_9, not(Py_3_11)))]
72+
#[cfg(all(Py_3_9, not(any(Py_3_11, PyPy))))]
7373
pub type _PyFrameEvalFunction = extern "C" fn(
7474
*mut crate::PyThreadState,
7575
*mut crate::PyFrameObject,
7676
c_int,
7777
) -> *mut crate::object::PyObject;
7878

79-
#[cfg(Py_3_11)]
79+
#[cfg(all(Py_3_11, not(PyPy)))]
8080
pub type _PyFrameEvalFunction = extern "C" fn(
8181
*mut crate::PyThreadState,
8282
*mut crate::_PyInterpreterFrame,
8383
c_int,
8484
) -> *mut crate::object::PyObject;
8585

86-
#[cfg(Py_3_9)]
86+
#[cfg(all(Py_3_9, not(PyPy)))]
8787
extern "C" {
8888
/// Get the frame evaluation function.
8989
pub fn _PyInterpreterState_GetEvalFrameFunc(

pyo3-ffi/src/cpython/unicodeobject.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
#[cfg(not(PyPy))]
1+
#[cfg(any(Py_3_11, not(PyPy)))]
22
use crate::Py_hash_t;
33
use crate::{PyObject, Py_UCS1, Py_UCS2, Py_UCS4, Py_ssize_t};
44
use libc::wchar_t;
@@ -251,7 +251,7 @@ impl From<PyASCIIObjectState> for u32 {
251251
pub struct PyASCIIObject {
252252
pub ob_base: PyObject,
253253
pub length: Py_ssize_t,
254-
#[cfg(not(PyPy))]
254+
#[cfg(any(Py_3_11, not(PyPy)))]
255255
pub hash: Py_hash_t,
256256
/// A bit field with various properties.
257257
///

pyo3-ffi/src/object.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -436,7 +436,7 @@ extern "C" {
436436
arg2: *const c_char,
437437
arg3: *mut PyObject,
438438
) -> c_int;
439-
#[cfg(any(Py_3_13, PyPy))] // CPython defined in 3.12 as an inline function in abstract.h
439+
#[cfg(any(Py_3_13, all(PyPy, not(Py_3_11))))] // CPython defined in 3.12 as an inline function in abstract.h
440440
#[cfg_attr(PyPy, link_name = "PyPyObject_DelAttrString")]
441441
pub fn PyObject_DelAttrString(arg1: *mut PyObject, arg2: *const c_char) -> c_int;
442442
#[cfg_attr(PyPy, link_name = "PyPyObject_HasAttrString")]
@@ -460,7 +460,7 @@ extern "C" {
460460
#[cfg_attr(PyPy, link_name = "PyPyObject_SetAttr")]
461461
pub fn PyObject_SetAttr(arg1: *mut PyObject, arg2: *mut PyObject, arg3: *mut PyObject)
462462
-> c_int;
463-
#[cfg(any(Py_3_13, PyPy))] // CPython defined in 3.12 as an inline function in abstract.h
463+
#[cfg(any(Py_3_13, all(PyPy, not(Py_3_11))))] // CPython defined in 3.12 as an inline function in abstract.h
464464
#[cfg_attr(PyPy, link_name = "PyPyObject_DelAttr")]
465465
pub fn PyObject_DelAttr(arg1: *mut PyObject, arg2: *mut PyObject) -> c_int;
466466
#[cfg_attr(PyPy, link_name = "PyPyObject_HasAttr")]

pyo3-ffi/src/pybuffer.rs

+5-1
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,11 @@ extern "C" {
103103
}
104104

105105
/// Maximum number of dimensions
106-
pub const PyBUF_MAX_NDIM: c_int = if cfg!(PyPy) { 36 } else { 64 };
106+
pub const PyBUF_MAX_NDIM: usize = if cfg!(all(PyPy, not(Py_3_11))) {
107+
36
108+
} else {
109+
64
110+
};
107111

108112
/* Flags for getting buffers */
109113
pub const PyBUF_SIMPLE: c_int = 0;

pyo3-ffi/src/pyerrors.rs

+1
Original file line numberDiff line numberDiff line change
@@ -116,6 +116,7 @@ extern "C" {
116116
#[cfg_attr(PyPy, link_name = "PyPyExc_BaseException")]
117117
pub static mut PyExc_BaseException: *mut PyObject;
118118
#[cfg(Py_3_11)]
119+
#[cfg_attr(PyPy, link_name = "PyPyExc_BaseExceptionGroup")]
119120
pub static mut PyExc_BaseExceptionGroup: *mut PyObject;
120121
#[cfg_attr(PyPy, link_name = "PyPyExc_Exception")]
121122
pub static mut PyExc_Exception: *mut PyObject;

src/ffi/tests.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,7 @@ fn ascii_object_bitfield() {
121121
let mut o = PyASCIIObject {
122122
ob_base,
123123
length: 0,
124-
#[cfg(not(PyPy))]
124+
#[cfg(any(Py_3_11, not(PyPy)))]
125125
hash: 0,
126126
state: 0u32,
127127
#[cfg(not(Py_3_12))]

0 commit comments

Comments
 (0)