-
Notifications
You must be signed in to change notification settings - Fork 791
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #3403 from davidhewitt/ffi-objimpl
update definitions for objimpl.h
- Loading branch information
Showing
5 changed files
with
106 additions
and
55 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
Add FFI definitions `PyObject_GC_IsTracked` and `PyObject_GC_IsFinalized` on Python 3.9 and up (PyPy 3.10 and up). |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
Disable removed FFI definitions `_Py_GetAllocatedBlocks`, `_PyObject_GC_Malloc`, and `_PyObject_GC_Calloc` on Python 3.11 and up. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
use libc::size_t; | ||
use std::os::raw::c_int; | ||
|
||
#[cfg(not(PyPy))] | ||
use std::os::raw::c_void; | ||
|
||
use crate::object::*; | ||
|
||
// skipped _PyObject_SIZE | ||
// skipped _PyObject_VAR_SIZE | ||
|
||
#[cfg(not(Py_3_11))] | ||
extern "C" { | ||
pub fn _Py_GetAllocatedBlocks() -> crate::Py_ssize_t; | ||
} | ||
|
||
#[cfg(not(PyPy))] | ||
#[repr(C)] | ||
#[derive(Copy, Clone)] | ||
pub struct PyObjectArenaAllocator { | ||
pub ctx: *mut c_void, | ||
pub alloc: Option<extern "C" fn(ctx: *mut c_void, size: size_t) -> *mut c_void>, | ||
pub free: Option<extern "C" fn(ctx: *mut c_void, ptr: *mut c_void, size: size_t)>, | ||
} | ||
|
||
#[cfg(not(PyPy))] | ||
impl Default for PyObjectArenaAllocator { | ||
#[inline] | ||
fn default() -> Self { | ||
unsafe { std::mem::zeroed() } | ||
} | ||
} | ||
|
||
extern "C" { | ||
#[cfg(not(PyPy))] | ||
pub fn PyObject_GetArenaAllocator(allocator: *mut PyObjectArenaAllocator); | ||
#[cfg(not(PyPy))] | ||
pub fn PyObject_SetArenaAllocator(allocator: *mut PyObjectArenaAllocator); | ||
|
||
#[cfg(Py_3_9)] | ||
pub fn PyObject_IS_GC(o: *mut PyObject) -> c_int; | ||
} | ||
|
||
#[inline] | ||
#[cfg(not(Py_3_9))] | ||
pub unsafe fn PyObject_IS_GC(o: *mut PyObject) -> c_int { | ||
(crate::PyType_IS_GC(Py_TYPE(o)) != 0 | ||
&& match (*Py_TYPE(o)).tp_is_gc { | ||
Some(tp_is_gc) => tp_is_gc(o) != 0, | ||
None => true, | ||
}) as c_int | ||
} | ||
|
||
#[cfg(not(Py_3_11))] | ||
extern "C" { | ||
pub fn _PyObject_GC_Malloc(size: size_t) -> *mut PyObject; | ||
pub fn _PyObject_GC_Calloc(size: size_t) -> *mut PyObject; | ||
} | ||
|
||
#[inline] | ||
pub unsafe fn PyType_SUPPORTS_WEAKREFS(t: *mut PyTypeObject) -> c_int { | ||
((*t).tp_weaklistoffset > 0) as c_int | ||
} | ||
|
||
#[inline] | ||
pub unsafe fn PyObject_GET_WEAKREFS_LISTPTR(o: *mut PyObject) -> *mut *mut PyObject { | ||
let weaklistoffset = (*Py_TYPE(o)).tp_weaklistoffset; | ||
o.offset(weaklistoffset) as *mut *mut PyObject | ||
} | ||
|
||
// skipped PyUnstable_Object_GC_NewWithExtraData |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters