Skip to main content

pyforge_ffi/cpython/
listobject.rs

1use crate::object::*;
2use crate::pyport::Py_ssize_t;
3
4#[repr(C)]
5pub struct PyListObject {
6    pub ob_base: PyVarObject,
7    pub ob_item: *mut *mut PyObject,
8    pub allocated: Py_ssize_t,
9}
10
11// skipped _PyList_Extend
12// skipped _PyList_DebugMallocStats
13// skipped _PyList_CAST (used inline below)
14
15/// Macro, trading safety for speed
16#[inline]
17pub unsafe fn PyList_GET_ITEM(op: *mut PyObject, i: Py_ssize_t) -> *mut PyObject {
18    *(*(op as *mut PyListObject)).ob_item.offset(i)
19}
20
21/// Macro, *only* to be used to fill in brand new lists
22#[inline]
23pub unsafe fn PyList_SET_ITEM(op: *mut PyObject, i: Py_ssize_t, v: *mut PyObject) {
24    *(*(op as *mut PyListObject)).ob_item.offset(i) = v;
25}
26
27#[inline]
28pub unsafe fn PyList_GET_SIZE(op: *mut PyObject) -> Py_ssize_t {
29    Py_SIZE(op)
30}