Skip to content

Commit

Permalink
Merge pull request #3335 from davidhewitt/3.12-ffi-immortal
Browse files Browse the repository at this point in the history
update object.h definitions for Python 3.12
  • Loading branch information
davidhewitt committed Jul 30, 2023
2 parents 7e43894 + ef43731 commit 6c25b73
Show file tree
Hide file tree
Showing 12 changed files with 402 additions and 158 deletions.
1 change: 1 addition & 0 deletions newsfragments/3335.changed.md
@@ -0,0 +1 @@
Update FFI definitions of `object.h` for Python 3.12 and up.
1 change: 1 addition & 0 deletions newsfragments/3335.fixed.md
@@ -0,0 +1 @@
Fix reference counting of immortal objects on Python 3.12 betas.
12 changes: 3 additions & 9 deletions pyo3-ffi/src/cpython/object.rs
@@ -1,4 +1,6 @@
use crate::object;
#[cfg(Py_3_8)]
use crate::vectorcallfunc;
use crate::{PyObject, Py_ssize_t};
use std::mem;
use std::os::raw::{c_char, c_int, c_uint, c_ulong, c_void};
Expand Down Expand Up @@ -112,14 +114,6 @@ mod bufferinfo {
#[cfg(not(Py_3_11))]
pub use self::bufferinfo::*;

#[cfg(Py_3_8)]
pub type vectorcallfunc = unsafe extern "C" fn(
callable: *mut PyObject,
args: *const *mut PyObject,
nargsf: libc::size_t,
kwnames: *mut PyObject,
) -> *mut PyObject;

#[repr(C)]
#[derive(Copy, Clone)]
pub struct PyNumberMethods {
Expand Down Expand Up @@ -275,7 +269,7 @@ pub struct PyTypeObject {
pub tp_version_tag: c_uint,
pub tp_finalize: Option<object::destructor>,
#[cfg(Py_3_8)]
pub tp_vectorcall: Option<super::vectorcallfunc>,
pub tp_vectorcall: Option<vectorcallfunc>,
#[cfg(Py_3_12)]
pub tp_watched: c_char,
#[cfg(any(all(PyPy, Py_3_8, not(Py_3_10)), all(not(PyPy), Py_3_8, not(Py_3_9))))]
Expand Down
10 changes: 5 additions & 5 deletions pyo3-ffi/src/lib.rs
Expand Up @@ -259,8 +259,6 @@ macro_rules! opaque_struct {
pub use self::abstract_::*;
pub use self::bltinmodule::*;
pub use self::boolobject::*;
#[cfg(Py_3_11)]
pub use self::buffer::*;
pub use self::bytearrayobject::*;
pub use self::bytesobject::*;
pub use self::ceval::*;
Expand Down Expand Up @@ -293,6 +291,8 @@ pub use self::objimpl::*;
pub use self::osmodule::*;
#[cfg(not(any(PyPy, Py_LIMITED_API, Py_3_10)))]
pub use self::pyarena::*;
#[cfg(Py_3_11)]
pub use self::pybuffer::*;
pub use self::pycapsule::*;
pub use self::pyerrors::*;
pub use self::pyframe::*;
Expand Down Expand Up @@ -320,8 +320,6 @@ mod abstract_;
// skipped ast.h
mod bltinmodule;
mod boolobject;
#[cfg(Py_3_11)]
mod buffer;
mod bytearrayobject;
mod bytesobject;
// skipped cellobject.h
Expand Down Expand Up @@ -372,8 +370,9 @@ mod osmodule;
// skipped py_curses.h
#[cfg(not(any(PyPy, Py_LIMITED_API, Py_3_10)))]
mod pyarena;
#[cfg(Py_3_11)]
mod pybuffer;
mod pycapsule;
// skipped pydecimal.h
// skipped pydtrace.h
mod pyerrors;
// skipped pyexpat.h
Expand All @@ -387,6 +386,7 @@ mod pylifecycle;
mod pymem;
mod pyport;
mod pystate;
// skipped pystats.h
mod pythonrun;
// skipped pystrhex.h
// skipped pystrcmp.h
Expand Down

0 comments on commit 6c25b73

Please sign in to comment.