From 8936f538e32717a84acdee70c6f61501ba687068 Mon Sep 17 00:00:00 2001 From: David Hewitt <1939362+davidhewitt@users.noreply.github.com> Date: Sun, 20 Dec 2020 06:32:29 +0000 Subject: [PATCH] pypy: update some definitions and fixes --- src/ffi/object.rs | 1 + src/ffi/pythonrun.rs | 12 +++++------- src/pyclass.rs | 18 +++--------------- 3 files changed, 9 insertions(+), 22 deletions(-) diff --git a/src/ffi/object.rs b/src/ffi/object.rs index 5cd0aef6640..048b82afbaf 100644 --- a/src/ffi/object.rs +++ b/src/ffi/object.rs @@ -611,6 +611,7 @@ extern "C" { #[cfg_attr(PyPy, link_name = "PyPyType_FromSpecWithBases")] pub fn PyType_FromSpecWithBases(arg1: *mut PyType_Spec, arg2: *mut PyObject) -> *mut PyObject; + #[cfg_attr(PyPy, link_name = "PyPyType_GetSlot")] pub fn PyType_GetSlot(arg1: *mut PyTypeObject, arg2: c_int) -> *mut c_void; } diff --git a/src/ffi/pythonrun.rs b/src/ffi/pythonrun.rs index e403bd028cd..2f41759c2b6 100644 --- a/src/ffi/pythonrun.rs +++ b/src/ffi/pythonrun.rs @@ -155,16 +155,14 @@ extern "C" { f: *mut PyCompilerFlags, ) -> *mut PyObject; } -#[cfg(not(Py_LIMITED_API))] -#[inline] -#[cfg(not(PyPy))] -pub unsafe fn Py_CompileString(string: *const c_char, p: *const c_char, s: c_int) -> *mut PyObject { - Py_CompileStringExFlags(string, p, s, ptr::null_mut(), -1) -} #[inline] -#[cfg(PyPy)] +#[cfg(not(Py_LIMITED_API))] pub unsafe fn Py_CompileString(string: *const c_char, p: *const c_char, s: c_int) -> *mut PyObject { + #[cfg(not(PyPy))] + return Py_CompileStringExFlags(string, p, s, ptr::null_mut(), -1); + + #[cfg(PyPy)] Py_CompileStringFlags(string, p, s, ptr::null_mut()) } diff --git a/src/pyclass.rs b/src/pyclass.rs index d25b17dc9a4..f927eb113be 100644 --- a/src/pyclass.rs +++ b/src/pyclass.rs @@ -10,27 +10,15 @@ use crate::{ffi, PyCell, PyErr, PyNativeType, PyResult, PyTypeInfo, Python}; use std::convert::TryInto; use std::ffi::CString; use std::marker::PhantomData; -#[cfg(not(PyPy))] -use std::mem; use std::os::raw::{c_char, c_int, c_uint, c_void}; -use std::{ptr, thread}; +use std::{mem, ptr, thread}; -#[cfg(PyPy)] -unsafe fn get_type_alloc(tp: *mut ffi::PyTypeObject) -> Option { - (*tp).tp_alloc -} - -#[cfg(not(PyPy))] +#[inline] unsafe fn get_type_alloc(tp: *mut ffi::PyTypeObject) -> Option { mem::transmute(ffi::PyType_GetSlot(tp, ffi::Py_tp_alloc)) } -#[cfg(PyPy)] -pub(crate) unsafe fn get_type_free(tp: *mut ffi::PyTypeObject) -> Option { - (*tp).tp_free -} - -#[cfg(not(PyPy))] +#[inline] pub(crate) unsafe fn get_type_free(tp: *mut ffi::PyTypeObject) -> Option { mem::transmute(ffi::PyType_GetSlot(tp, ffi::Py_tp_free)) }