make PyDictObject, PyFloatObject opaque under limited API

This commit is contained in:
Nicholas Sim 2020-12-28 18:13:33 +08:00
parent 643d0af3bf
commit 72ce3081e6
3 changed files with 21 additions and 16 deletions

View file

@ -3,6 +3,19 @@ use crate::ffi::object::*;
use crate::ffi::pyport::Py_ssize_t; use crate::ffi::pyport::Py_ssize_t;
use std::os::raw::c_int; use std::os::raw::c_int;
opaque_struct!(PyDictKeysObject);
#[repr(C)]
#[derive(Debug)]
// Not moved because dict.rs uses PyDictObject extensively.
pub struct PyDictObject {
pub ob_base: PyObject,
pub ma_used: Py_ssize_t,
pub ma_version_tag: u64,
pub ma_keys: *mut PyDictKeysObject,
pub ma_values: *mut *mut PyObject,
}
extern "C" { extern "C" {
// skipped _PyDict_GetItem_KnownHash // skipped _PyDict_GetItem_KnownHash
// skipped _PyDict_GetItemIdWithError // skipped _PyDict_GetItemIdWithError

View file

@ -107,17 +107,6 @@ extern "C" {
pub static mut PyDictRevIterItem_Type: PyTypeObject; pub static mut PyDictRevIterItem_Type: PyTypeObject;
} }
#[repr(C)] #[cfg(Py_LIMITED_API)]
#[derive(Debug)] // TODO: remove (see https://github.com/PyO3/pyo3/pull/1341#issuecomment-751515985)
// TODO: move to cpython/dictobject.rs opaque_struct!(PyDictObject);
// Not moved because dict.rs uses PyDictObject extensively.
pub struct PyDictObject {
pub ob_base: PyObject,
pub ma_used: Py_ssize_t,
pub ma_version_tag: u64,
pub ma_keys: *mut PyDictKeysObject,
pub ma_values: *mut *mut PyObject,
}
// TODO: move to cpython/dictobject.rs
opaque_struct!(PyDictKeysObject);

View file

@ -1,8 +1,11 @@
use crate::ffi::object::*; use crate::ffi::object::*;
use std::os::raw::{c_double, c_int}; use std::os::raw::{c_double, c_int};
// TODO: mark non-limited #[cfg(Py_LIMITED_API)]
// currently used by types/floatob.rs // TODO: remove (see https://github.com/PyO3/pyo3/pull/1341#issuecomment-751515985)
opaque_struct!(PyFloatObject);
#[cfg(not(Py_LIMITED_API))]
#[repr(C)] #[repr(C)]
pub struct PyFloatObject { pub struct PyFloatObject {
pub ob_base: PyObject, pub ob_base: PyObject,