pypy: update some definitions and fixes

This commit is contained in:
David Hewitt 2020-12-20 06:32:29 +00:00
parent 1f64f98a33
commit 8936f538e3
3 changed files with 9 additions and 22 deletions

View File

@ -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;
}

View File

@ -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())
}

View File

@ -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<ffi::allocfunc> {
(*tp).tp_alloc
}
#[cfg(not(PyPy))]
#[inline]
unsafe fn get_type_alloc(tp: *mut ffi::PyTypeObject) -> Option<ffi::allocfunc> {
mem::transmute(ffi::PyType_GetSlot(tp, ffi::Py_tp_alloc))
}
#[cfg(PyPy)]
pub(crate) unsafe fn get_type_free(tp: *mut ffi::PyTypeObject) -> Option<ffi::freefunc> {
(*tp).tp_free
}
#[cfg(not(PyPy))]
#[inline]
pub(crate) unsafe fn get_type_free(tp: *mut ffi::PyTypeObject) -> Option<ffi::freefunc> {
mem::transmute(ffi::PyType_GetSlot(tp, ffi::Py_tp_free))
}