Skip to content

Commit 87e669a

Browse files
Remove static type references
1 parent c24a951 commit 87e669a

33 files changed

Lines changed: 133 additions & 24 deletions

pyo3-ffi/src/boolobject.rs

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,16 @@ use std::ffi::{c_int, c_long};
55

66
#[inline]
77
pub unsafe fn PyBool_Check(op: *mut PyObject) -> c_int {
8-
(Py_TYPE(op) == &raw mut PyBool_Type) as c_int
8+
#[cfg(not(RustPython))]
9+
{
10+
Py_IS_TYPE(op, &raw mut PyBool_Type)
11+
}
12+
13+
#[cfg(RustPython)]
14+
Py_IS_TYPE(
15+
op,
16+
crate::PyObject_GetAttrString(crate::PyEval_GetBuiltins(), c"bool".as_ptr()).cast(),
17+
)
918
}
1019

1120
extern_libpython! {

pyo3-ffi/src/bytearrayobject.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ use crate::object::*;
22
use crate::pyport::Py_ssize_t;
33
use std::ffi::{c_char, c_int};
44

5+
#[cfg(not(RustPython))]
56
extern_libpython! {
67
#[cfg_attr(PyPy, link_name = "PyPyByteArray_Type")]
78
pub static mut PyByteArray_Type: PyTypeObject;

pyo3-ffi/src/bytesobject.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ use crate::object::*;
22
use crate::pyport::Py_ssize_t;
33
use std::ffi::{c_char, c_int};
44

5+
#[cfg(not(RustPython))]
56
extern_libpython! {
67
#[cfg_attr(PyPy, link_name = "PyPyBytes_Type")]
78
pub static mut PyBytes_Type: PyTypeObject;

pyo3-ffi/src/complexobject.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
use crate::object::*;
22
use std::ffi::{c_double, c_int};
33

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

pyo3-ffi/src/context.rs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
1-
use crate::object::{PyObject, PyTypeObject, Py_TYPE};
1+
#[cfg(not(RustPython))]
2+
use crate::object::PyTypeObject;
3+
use crate::object::{PyObject, Py_TYPE};
24
use std::ffi::{c_char, c_int};
35

6+
#[cfg(not(RustPython))]
47
extern_libpython! {
58
pub static mut PyContext_Type: PyTypeObject;
69
// skipped non-limited opaque PyContext

pyo3-ffi/src/descrobject.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ impl Default for PyGetSetDef {
3535
}
3636
}
3737

38+
#[cfg(not(RustPython))]
3839
extern_libpython! {
3940
#[cfg_attr(PyPy, link_name = "PyPyClassMethodDescr_Type")]
4041
pub static mut PyClassMethodDescr_Type: PyTypeObject;

pyo3-ffi/src/dictobject.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ use crate::object::*;
22
use crate::pyport::Py_ssize_t;
33
use std::ffi::{c_char, c_int};
44

5+
#[cfg(not(RustPython))]
56
extern_libpython! {
67
#[cfg_attr(PyPy, link_name = "PyPyDict_Type")]
78
pub static mut PyDict_Type: PyTypeObject;
@@ -88,6 +89,7 @@ extern_libpython! {
8889
// skipped 3.10 / ex-non-limited PyObject_GenericGetDict
8990
}
9091

92+
#[cfg(not(RustPython))]
9193
extern_libpython! {
9294
pub static mut PyDictKeys_Type: PyTypeObject;
9395
pub static mut PyDictValues_Type: PyTypeObject;
@@ -114,6 +116,7 @@ pub unsafe fn PyDictViewSet_Check(op: *mut PyObject) -> c_int {
114116
(PyDictKeys_Check(op) != 0 || PyDictItems_Check(op) != 0) as c_int
115117
}
116118

119+
#[cfg(not(RustPython))]
117120
extern_libpython! {
118121
pub static mut PyDictIterKey_Type: PyTypeObject;
119122
pub static mut PyDictIterValue_Type: PyTypeObject;

pyo3-ffi/src/floatobject.rs

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,14 +5,24 @@ use std::ffi::{c_double, c_int};
55
// TODO: remove (see https://github.com/PyO3/pyo3/pull/1341#issuecomment-751515985)
66
opaque_struct!(pub PyFloatObject);
77

8+
#[cfg(not(RustPython))]
89
extern_libpython! {
910
#[cfg_attr(PyPy, link_name = "PyPyFloat_Type")]
1011
pub static mut PyFloat_Type: PyTypeObject;
1112
}
1213

1314
#[inline]
1415
pub unsafe fn PyFloat_Check(op: *mut PyObject) -> c_int {
15-
PyObject_TypeCheck(op, &raw mut PyFloat_Type)
16+
#[cfg(not(RustPython))]
17+
{
18+
PyObject_TypeCheck(op, &raw mut PyFloat_Type)
19+
}
20+
21+
#[cfg(RustPython)]
22+
PyObject_TypeCheck(
23+
op,
24+
crate::PyObject_GetAttrString(crate::PyEval_GetBuiltins(), c"float".as_ptr()).cast(),
25+
)
1626
}
1727

1828
#[inline]

pyo3-ffi/src/genericaliasobject.rs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,13 @@
11
#[cfg(Py_3_9)]
2-
use crate::object::{PyObject, PyTypeObject};
2+
use crate::PyObject;
3+
#[cfg(not(RustPython))]
4+
use crate::PyTypeObject;
35

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

9-
#[cfg(Py_3_9)]
11+
#[cfg(all(Py_3_9, not(RustPython)))]
1012
pub static mut Py_GenericAliasType: PyTypeObject;
1113
}

pyo3-ffi/src/iterobject.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
use crate::object::*;
22
use std::ffi::c_int;
33

4+
#[cfg(not(RustPython))]
45
extern_libpython! {
56
pub static mut PySeqIter_Type: PyTypeObject;
67
pub static mut PyCallIter_Type: PyTypeObject;

0 commit comments

Comments
 (0)