adjust vectorcall symbols for pypy

This commit is contained in:
David Hewitt 2022-12-17 07:49:51 +00:00
parent 7180a0b77c
commit 4a6b24ea07
3 changed files with 9 additions and 4 deletions

View file

@ -0,0 +1 @@
Add FFI definitions `PyVectorcall_NARGS` and `PY_VECTORCALL_ARGUMENTS_OFFSET` for PyPy 3.8 and up.

View file

@ -0,0 +1 @@
Fix unresolved symbol for `PyObject_Vectorcall` on PyPy 3.9 and up.

View file

@ -4,10 +4,12 @@ use std::os::raw::{c_char, c_int};
#[cfg(not(Py_3_11))] #[cfg(not(Py_3_11))]
use crate::Py_buffer; use crate::Py_buffer;
#[cfg(Py_3_8)]
use crate::pyport::PY_SSIZE_T_MAX;
#[cfg(all(Py_3_8, not(PyPy)))] #[cfg(all(Py_3_8, not(PyPy)))]
use crate::{ use crate::{
pyport::PY_SSIZE_T_MAX, vectorcallfunc, PyCallable_Check, PyThreadState, PyThreadState_GET, vectorcallfunc, PyCallable_Check, PyThreadState, PyThreadState_GET, PyTuple_Check,
PyTuple_Check, PyType_HasFeature, Py_TPFLAGS_HAVE_VECTORCALL, PyType_HasFeature, Py_TPFLAGS_HAVE_VECTORCALL,
}; };
#[cfg(Py_3_8)] #[cfg(Py_3_8)]
use libc::size_t; use libc::size_t;
@ -39,11 +41,11 @@ extern "C" {
) -> *mut PyObject; ) -> *mut PyObject;
} }
#[cfg(all(Py_3_8, not(PyPy)))] #[cfg(all(Py_3_8))]
const PY_VECTORCALL_ARGUMENTS_OFFSET: Py_ssize_t = const PY_VECTORCALL_ARGUMENTS_OFFSET: Py_ssize_t =
1 << (8 * std::mem::size_of::<Py_ssize_t>() as Py_ssize_t - 1); 1 << (8 * std::mem::size_of::<Py_ssize_t>() as Py_ssize_t - 1);
#[cfg(all(Py_3_8, not(PyPy)))] #[cfg(all(Py_3_8))]
#[inline(always)] #[inline(always)]
pub unsafe fn PyVectorcall_NARGS(n: size_t) -> Py_ssize_t { pub unsafe fn PyVectorcall_NARGS(n: size_t) -> Py_ssize_t {
assert!(n <= (PY_SSIZE_T_MAX as size_t)); assert!(n <= (PY_SSIZE_T_MAX as size_t));
@ -103,6 +105,7 @@ pub unsafe fn PyObject_Vectorcall(
extern "C" { extern "C" {
#[cfg(all(PyPy, Py_3_8))] #[cfg(all(PyPy, Py_3_8))]
#[cfg_attr(not(Py_3_9), link_name = "_PyPyObject_Vectorcall")] #[cfg_attr(not(Py_3_9), link_name = "_PyPyObject_Vectorcall")]
#[cfg_attr(Py_3_9, link_name = "PyPyObject_Vectorcall")]
pub fn PyObject_Vectorcall( pub fn PyObject_Vectorcall(
callable: *mut PyObject, callable: *mut PyObject,
args: *const *mut PyObject, args: *const *mut PyObject,