Skip to content
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
2 changes: 1 addition & 1 deletion pyo3-build-config/src/impl_.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1772,7 +1772,7 @@ fn default_lib_name_unix(
},

PythonImplementation::GraalPy => Ok("python-native".to_string()),
PythonImplementation::RustPython => Ok("rustpython-capi".to_string()),
PythonImplementation::RustPython => Ok("rustpython_capi".to_string()),
}
}

Expand Down
4 changes: 4 additions & 0 deletions pyo3-ffi/src/boolobject.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,15 @@ use crate::object::*;
use std::ffi::{c_int, c_long};

#[inline]
#[cfg(not(RustPython))]
pub unsafe fn PyBool_Check(op: *mut PyObject) -> c_int {
Py_IS_TYPE(op, &raw mut PyBool_Type)
}

extern_libpython! {
#[cfg(RustPython)]
pub fn PyBool_Check(op: *mut PyObject) -> c_int;

#[cfg(all(not(GraalPy), not(all(Py_3_13, Py_LIMITED_API))))]
#[cfg_attr(PyPy, link_name = "_PyPy_FalseStruct")]
static mut _Py_FalseStruct: PyLongObject;
Expand Down
8 changes: 8 additions & 0 deletions pyo3-ffi/src/bytearrayobject.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ use crate::object::*;
use crate::pyport::Py_ssize_t;
use std::ffi::{c_char, c_int};

#[cfg(not(RustPython))]
extern_libpython! {
#[cfg_attr(PyPy, link_name = "PyPyByteArray_Type")]
pub static mut PyByteArray_Type: PyTypeObject;
Expand All @@ -10,16 +11,23 @@ extern_libpython! {
}

#[inline]
#[cfg(not(RustPython))]
pub unsafe fn PyByteArray_Check(op: *mut PyObject) -> c_int {
PyObject_TypeCheck(op, &raw mut PyByteArray_Type)
}

#[inline]
#[cfg(not(RustPython))]
pub unsafe fn PyByteArray_CheckExact(op: *mut PyObject) -> c_int {
Py_IS_TYPE(op, &raw mut PyByteArray_Type)
}

extern_libpython! {
#[cfg(RustPython)]
pub fn PyByteArray_Check(op: *mut PyObject) -> c_int;
#[cfg(RustPython)]
pub fn PyByteArray_CheckExact(op: *mut PyObject) -> c_int;

#[cfg_attr(PyPy, link_name = "PyPyByteArray_FromObject")]
pub fn PyByteArray_FromObject(o: *mut PyObject) -> *mut PyObject;
#[cfg_attr(PyPy, link_name = "PyPyByteArray_Concat")]
Expand Down
8 changes: 8 additions & 0 deletions pyo3-ffi/src/bytesobject.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,23 +2,31 @@ use crate::object::*;
use crate::pyport::Py_ssize_t;
use std::ffi::{c_char, c_int};

#[cfg(not(RustPython))]
extern_libpython! {
#[cfg_attr(PyPy, link_name = "PyPyBytes_Type")]
pub static mut PyBytes_Type: PyTypeObject;
pub static mut PyBytesIter_Type: PyTypeObject;
}

#[inline]
#[cfg(not(RustPython))]
pub unsafe fn PyBytes_Check(op: *mut PyObject) -> c_int {
PyType_FastSubclass(Py_TYPE(op), Py_TPFLAGS_BYTES_SUBCLASS)
}

#[inline]
#[cfg(not(RustPython))]
pub unsafe fn PyBytes_CheckExact(op: *mut PyObject) -> c_int {
Py_IS_TYPE(op, &raw mut PyBytes_Type)
}

extern_libpython! {
#[cfg(RustPython)]
pub fn PyBytes_Check(op: *mut PyObject) -> c_int;
#[cfg(RustPython)]
pub fn PyBytes_CheckExact(op: *mut PyObject) -> c_int;

#[cfg_attr(PyPy, link_name = "PyPyBytes_FromStringAndSize")]
pub fn PyBytes_FromStringAndSize(arg1: *const c_char, arg2: Py_ssize_t) -> *mut PyObject;
pub fn PyBytes_FromString(arg1: *const c_char) -> *mut PyObject;
Expand Down
8 changes: 8 additions & 0 deletions pyo3-ffi/src/complexobject.rs
Original file line number Diff line number Diff line change
@@ -1,22 +1,30 @@
use crate::object::*;
use std::ffi::{c_double, c_int};

#[cfg(not(RustPython))]
extern_libpython! {
#[cfg_attr(PyPy, link_name = "PyPyComplex_Type")]
pub static mut PyComplex_Type: PyTypeObject;
}

#[inline]
#[cfg(not(RustPython))]
pub unsafe fn PyComplex_Check(op: *mut PyObject) -> c_int {
PyObject_TypeCheck(op, &raw mut PyComplex_Type)
}

#[inline]
#[cfg(not(RustPython))]
pub unsafe fn PyComplex_CheckExact(op: *mut PyObject) -> c_int {
Py_IS_TYPE(op, &raw mut PyComplex_Type)
}

extern_libpython! {
#[cfg(RustPython)]
pub fn PyComplex_Check(op: *mut PyObject) -> c_int;
#[cfg(RustPython)]
pub fn PyComplex_CheckExact(op: *mut PyObject) -> c_int;

// skipped non-limited PyComplex_FromCComplex
#[cfg_attr(PyPy, link_name = "PyPyComplex_FromDoubles")]
pub fn PyComplex_FromDoubles(real: c_double, imag: c_double) -> *mut PyObject;
Expand Down
16 changes: 15 additions & 1 deletion pyo3-ffi/src/context.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,11 @@
use crate::object::{PyObject, PyTypeObject};
use crate::object::PyObject;
#[cfg(not(RustPython))]
use crate::object::PyTypeObject;
#[cfg(not(RustPython))]
use crate::Py_IS_TYPE;
use std::ffi::{c_char, c_int};

#[cfg(not(RustPython))]
extern_libpython! {
pub static mut PyContext_Type: PyTypeObject;
// skipped non-limited opaque PyContext
Expand All @@ -12,21 +16,31 @@ extern_libpython! {
}

#[inline]
#[cfg(not(RustPython))]
pub unsafe fn PyContext_CheckExact(op: *mut PyObject) -> c_int {
Py_IS_TYPE(op, &raw mut PyContext_Type)
}

#[inline]
#[cfg(not(RustPython))]
pub unsafe fn PyContextVar_CheckExact(op: *mut PyObject) -> c_int {
Py_IS_TYPE(op, &raw mut PyContextVar_Type)
}

#[inline]
#[cfg(not(RustPython))]
pub unsafe fn PyContextToken_CheckExact(op: *mut PyObject) -> c_int {
Py_IS_TYPE(op, &raw mut PyContextToken_Type)
}

extern_libpython! {
#[cfg(RustPython)]
pub fn PyContext_CheckExact(op: *mut PyObject) -> c_int;
#[cfg(RustPython)]
pub fn PyContextVar_CheckExact(op: *mut PyObject) -> c_int;
#[cfg(RustPython)]
pub fn PyContextToken_CheckExact(op: *mut PyObject) -> c_int;

pub fn PyContext_New() -> *mut PyObject;
pub fn PyContext_Copy(ctx: *mut PyObject) -> *mut PyObject;
pub fn PyContext_CopyCurrent() -> *mut PyObject;
Expand Down
1 change: 1 addition & 0 deletions pyo3-ffi/src/descrobject.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ impl Default for PyGetSetDef {
}
}

#[cfg(not(RustPython))]
extern_libpython! {
#[cfg_attr(PyPy, link_name = "PyPyClassMethodDescr_Type")]
pub static mut PyClassMethodDescr_Type: PyTypeObject;
Expand Down
22 changes: 22 additions & 0 deletions pyo3-ffi/src/dictobject.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,22 +2,30 @@ use crate::object::*;
use crate::pyport::Py_ssize_t;
use std::ffi::{c_char, c_int};

#[cfg(not(RustPython))]
extern_libpython! {
#[cfg_attr(PyPy, link_name = "PyPyDict_Type")]
pub static mut PyDict_Type: PyTypeObject;
}

#[inline]
#[cfg(not(RustPython))]
pub unsafe fn PyDict_Check(op: *mut PyObject) -> c_int {
PyType_FastSubclass(Py_TYPE(op), Py_TPFLAGS_DICT_SUBCLASS)
}

#[inline]
#[cfg(not(RustPython))]
pub unsafe fn PyDict_CheckExact(op: *mut PyObject) -> c_int {
Py_IS_TYPE(op, &raw mut PyDict_Type)
}

extern_libpython! {
#[cfg(RustPython)]
pub fn PyDict_Check(op: *mut PyObject) -> c_int;
#[cfg(RustPython)]
pub fn PyDict_CheckExact(op: *mut PyObject) -> c_int;

#[cfg_attr(PyPy, link_name = "PyPyDict_New")]
pub fn PyDict_New() -> *mut PyObject;
#[cfg_attr(PyPy, link_name = "PyPyDict_GetItem")]
Expand Down Expand Up @@ -88,32 +96,46 @@ extern_libpython! {
// skipped 3.10 / ex-non-limited PyObject_GenericGetDict
}

#[cfg(not(RustPython))]
extern_libpython! {
pub static mut PyDictKeys_Type: PyTypeObject;
pub static mut PyDictValues_Type: PyTypeObject;
pub static mut PyDictItems_Type: PyTypeObject;
}

#[inline]
#[cfg(not(RustPython))]
pub unsafe fn PyDictKeys_Check(op: *mut PyObject) -> c_int {
PyObject_TypeCheck(op, &raw mut PyDictKeys_Type)
}

#[inline]
#[cfg(not(RustPython))]
pub unsafe fn PyDictValues_Check(op: *mut PyObject) -> c_int {
PyObject_TypeCheck(op, &raw mut PyDictValues_Type)
}

#[inline]
#[cfg(not(RustPython))]
pub unsafe fn PyDictItems_Check(op: *mut PyObject) -> c_int {
PyObject_TypeCheck(op, &raw mut PyDictItems_Type)
}

extern_libpython! {
#[cfg(RustPython)]
pub fn PyDictKeys_Check(op: *mut PyObject) -> c_int;
#[cfg(RustPython)]
pub fn PyDictValues_Check(op: *mut PyObject) -> c_int;
#[cfg(RustPython)]
pub fn PyDictItems_Check(op: *mut PyObject) -> c_int;
}

#[inline]
pub unsafe fn PyDictViewSet_Check(op: *mut PyObject) -> c_int {
(PyDictKeys_Check(op) != 0 || PyDictItems_Check(op) != 0) as c_int
}

#[cfg(not(RustPython))]
extern_libpython! {
pub static mut PyDictIterKey_Type: PyTypeObject;
pub static mut PyDictIterValue_Type: PyTypeObject;
Expand Down
8 changes: 8 additions & 0 deletions pyo3-ffi/src/floatobject.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,16 +6,24 @@ use std::ffi::{c_double, c_int};
opaque_struct!(pub PyFloatObject);

extern_libpython! {
#[cfg(not(RustPython))]
#[cfg_attr(PyPy, link_name = "PyPyFloat_Type")]
pub static mut PyFloat_Type: PyTypeObject;

#[cfg(RustPython)]
pub fn PyFloat_Check(op: *mut PyObject) -> c_int;
#[cfg(RustPython)]
pub fn PyFloat_CheckExact(op: *mut PyObject) -> c_int;
}

#[inline]
#[cfg(not(RustPython))]
pub unsafe fn PyFloat_Check(op: *mut PyObject) -> c_int {
PyObject_TypeCheck(op, &raw mut PyFloat_Type)
}

#[inline]
#[cfg(not(RustPython))]
pub unsafe fn PyFloat_CheckExact(op: *mut PyObject) -> c_int {
Py_IS_TYPE(op, &raw mut PyFloat_Type)
}
Expand Down
6 changes: 4 additions & 2 deletions pyo3-ffi/src/genericaliasobject.rs
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
#[cfg(Py_3_9)]
use crate::object::{PyObject, PyTypeObject};
use crate::PyObject;
#[cfg(all(Py_3_9, not(RustPython)))]
use crate::PyTypeObject;

extern_libpython! {
#[cfg(Py_3_9)]
#[cfg_attr(PyPy, link_name = "PyPy_GenericAlias")]
pub fn Py_GenericAlias(origin: *mut PyObject, args: *mut PyObject) -> *mut PyObject;

#[cfg(Py_3_9)]
#[cfg(all(Py_3_9, not(RustPython)))]
pub static mut Py_GenericAliasType: PyTypeObject;
}
9 changes: 9 additions & 0 deletions pyo3-ffi/src/iterobject.rs
Original file line number Diff line number Diff line change
@@ -1,27 +1,36 @@
use crate::object::*;
use std::ffi::c_int;

#[cfg(not(RustPython))]
extern_libpython! {
pub static mut PySeqIter_Type: PyTypeObject;
pub static mut PyCallIter_Type: PyTypeObject;
}

#[inline]
#[cfg(not(RustPython))]
pub unsafe fn PySeqIter_Check(op: *mut PyObject) -> c_int {
Py_IS_TYPE(op, &raw mut PySeqIter_Type)
}

extern_libpython! {
#[cfg(RustPython)]
pub fn PySeqIter_Check(op: *mut PyObject) -> c_int;

#[cfg_attr(PyPy, link_name = "PyPySeqIter_New")]
pub fn PySeqIter_New(arg1: *mut PyObject) -> *mut PyObject;
}

#[inline]
#[cfg(not(RustPython))]
pub unsafe fn PyCallIter_Check(op: *mut PyObject) -> c_int {
Py_IS_TYPE(op, &raw mut PyCallIter_Type)
}

extern_libpython! {
#[cfg(RustPython)]
pub fn PyCallIter_Check(op: *mut PyObject) -> c_int;

#[cfg_attr(PyPy, link_name = "PyPyCallIter_New")]
pub fn PyCallIter_New(arg1: *mut PyObject, arg2: *mut PyObject) -> *mut PyObject;
}
4 changes: 4 additions & 0 deletions pyo3-ffi/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -429,6 +429,7 @@ pub mod compat;
mod impl_;

pub use self::abstract_::*;
#[cfg(not(RustPython))]
pub use self::bltinmodule::*;
pub use self::boolobject::*;
pub use self::bytearrayobject::*;
Expand All @@ -443,6 +444,7 @@ pub use self::context::*;
pub use self::datetime::*;
pub use self::descrobject::*;
pub use self::dictobject::*;
#[cfg(not(RustPython))]
pub use self::enumobject::*;
pub use self::fileobject::*;
pub use self::fileutils::*;
Expand Down Expand Up @@ -492,6 +494,7 @@ pub use self::weakrefobject::*;
mod abstract_;
// skipped asdl.h
// skipped ast.h
#[cfg(not(RustPython))]
mod bltinmodule;
mod boolobject;
mod bytearrayobject;
Expand All @@ -509,6 +512,7 @@ pub(crate) mod datetime;
mod descrobject;
mod dictobject;
// skipped dynamic_annotations.h
#[cfg(not(RustPython))]
mod enumobject;
// skipped errcode.h
// skipped exports.h
Expand Down
8 changes: 8 additions & 0 deletions pyo3-ffi/src/listobject.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,24 +2,32 @@ use crate::object::*;
use crate::pyport::Py_ssize_t;
use std::ffi::c_int;

#[cfg(not(RustPython))]
extern_libpython! {
#[cfg_attr(PyPy, link_name = "PyPyList_Type")]
pub static mut PyList_Type: PyTypeObject;
pub static mut PyListIter_Type: PyTypeObject;
pub static mut PyListRevIter_Type: PyTypeObject;
}

#[cfg(not(RustPython))]
#[inline]
pub unsafe fn PyList_Check(op: *mut PyObject) -> c_int {
PyType_FastSubclass(Py_TYPE(op), Py_TPFLAGS_LIST_SUBCLASS)
}

#[inline]
#[cfg(not(RustPython))]
pub unsafe fn PyList_CheckExact(op: *mut PyObject) -> c_int {
Py_IS_TYPE(op, &raw mut PyList_Type)
}

extern_libpython! {
#[cfg(RustPython)]
pub fn PyList_Check(op: *mut PyObject) -> c_int;
#[cfg(RustPython)]
pub fn PyList_CheckExact(op: *mut PyObject) -> c_int;

#[cfg_attr(PyPy, link_name = "PyPyList_New")]
pub fn PyList_New(size: Py_ssize_t) -> *mut PyObject;
#[cfg_attr(PyPy, link_name = "PyPyList_Size")]
Expand Down
Loading
Loading