Skip to main content

pyo3_ffi/cpython/
longintrepr.rs

1use crate::{PyObject, Py_ssize_t};
2use core::ffi::{c_int, c_void};
3
4use crate::Py_uintptr_t;
5
6// skipped PyLong_BASE
7// skipped PyLong_MASK
8// skipped _PyLong_New
9// skipped _PyLong_Copy
10// skipped _PyLong_FromDigits
11// skipped _PyLong_SIGN_MASK
12// skipped _PyLong_NON_SIZE_BITS
13// skipped PyUnstable_Long_IsCompact
14// skipped PyUnstable_Long_CompactValue
15
16#[derive(Copy, Clone)]
17#[repr(C)]
18pub struct PyLongLayout {
19    pub bits_per_digit: u8,
20    pub digit_size: u8,
21    pub digits_order: i8,
22    pub digit_endianness: i8,
23}
24
25extern_libpython! {
26    pub fn PyLong_GetNativeLayout() -> *const PyLongLayout;
27}
28
29#[repr(C)]
30pub struct PyLongExport {
31    pub value: i64,
32    pub negative: u8,
33    pub ndigits: Py_ssize_t,
34    pub digits: *const c_void,
35    _reserved: Py_uintptr_t,
36}
37
38extern_libpython! {
39    pub fn PyLong_Export(obj: *mut PyObject, export_long: *mut PyLongExport) -> c_int;
40    pub fn PyLong_FreeExport(export_long: *mut PyLongExport);
41}
42
43opaque_struct!(pub PyLongWriter);
44
45extern_libpython! {
46    pub fn PyLongWriter_Create(
47        negative: c_int,
48        ndigits: Py_ssize_t,
49        digits: *mut *mut c_void,
50    ) -> *mut PyLongWriter;
51
52    pub fn PyLongWriter_Finish(writer: *mut PyLongWriter) -> *mut PyObject;
53
54    pub fn PyLongWriter_Discard(writer: *mut PyLongWriter);
55}
⚠️ Internal Docs ⚠️ Not Public API 👉 Official Docs Here