Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

pypy: update some definitions and fixes #1329

Merged
merged 1 commit into from
Dec 20, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions src/ffi/object.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand Down
12 changes: 5 additions & 7 deletions src/ffi/pythonrun.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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())
}

Expand Down
18 changes: 3 additions & 15 deletions src/pyclass.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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))
}
Expand Down