Files
TransPyC/CPython/Python/P312/Object.py
2026-06-16 16:09:42 +08:00

178 lines
5.2 KiB
Python

import t, c
Py_uintptr_t: t.CTypedef = t.CUIntPtrT
Py_intptr_t: t.CTypedef = t.CIntPtrT
PY_UINT32_T: t.CTypedef = t.CUInt32T
PY_UINT64_T: t.CTypedef = t.CUInt64T
# Signed variants of the above
PY_INT32_T: t.CTypedef = t.CInt32T
PY_INT64_T: t.CTypedef = t.CInt64T
# * Py_ssize_t is a signed integral type such that sizeof(Py_ssize_t) ==
# * sizeof(size_t). C99 doesn't define such a thing directly (size_t is an
# * unsigned integral type). See PEP 353 for details.
# * PY_SSIZE_T_MAX is the largest positive value of type Py_ssize_t.
Py_ssize_t: t.CTypedef = Py_intptr_t
Py_hash_t: t.CTypedef = Py_ssize_t
SIZEOF_VOID_P: t.CDefine = 8
# If this structure is modified, Doc/includes/typestruct.h should be updated
# as well.
class PyTypeObject:
ob_base: PyVarObject
tp_name: t.CConst | str # For printing, in format "<module>.<name>"
tp_basicsize: Py_ssize_t
tp_itemsize: Py_ssize_t # For allocation
# Methods to implement standard operations
tp_dealloc: destructor
tp_vectorcall_offset: Py_ssize_t
tp_getattr: getattrfunc
tp_setattr: setattrfunc
tp_as_async: PyAsyncMethods | t.CPtr # formerly known as tp_compare (Python 2) or tp_reserved (Python 3)
tp_repr: reprfunc
# Method suites for standard classes
tp_as_number: PyNumberMethods | t.CPtr
tp_as_sequence: PySequenceMethods | t.CPtr
tp_as_mapping: PyMappingMethods | t.CPtr
# More standard operations (here for binary compatibility)
tp_hash: hashfunc
tp_call: ternaryfunc
tp_str: reprfunc
tp_getattro: getattrofunc
tp_setattro: setattrofunc
# Functions to access object as input/output buffer
tp_as_buffer: PyBufferProcs | t.CPtr
# Flags to define presence of optional/expanded features
tp_flags: t.CUnsignedLong
tp_doc: t.CConst | str # Documentation string
# Assigned meaning in release 2.0
# call function for all accessible objects
tp_traverse: traverseproc
# delete references to contained objects */
tp_clear: inquiry
# Assigned meaning in release 2.1
# rich comparisons
tp_richcompare: richcmpfunc
# weak reference enabler
tp_weaklistoffset: Py_ssize_t
# Iterators
tp_iter: getiterfunc
tp_iternext: iternextfunc
# Attribute descriptor and subclassing stuff
tp_methods: PyMethodDef | t.CPtr
tp_members: PyMemberDef | t.CPtr
tp_getset: PyGetSetDef | t.CPtr
# Strong reference on a heap type, borrowed reference on a static type
tp_base: PyTypeObject | t.CPtr
tp_dict: PyObject | t.CPtr
tp_descr_get: descrgetfunc
tp_descr_set: descrgetfunc
tp_dictoffset: Py_ssize_t
tp_init: initproc
tp_alloc: allocfunc
tp_new: newfunc
tp_free: freefunc # Low-level free-memory routine
tp_is_gc: inquiry # For PyObject_IS_GC
tp_bases: PyObjectPtr
tp_mro: PyObjectPtr # method resolution order
tp_cache: PyObjectPtr # no longer used
tp_subclasses: t.CVoid | t.CPtr # for static builtin types this is an index
tp_weaklist: PyObjectPtr # not used for static builtin types
tp_del: destructor
# Type attribute cache version tag. Added in version 2.6
tp_version_tag: t.CUnsignedInt
tp_finalize: destructor
tp_vectorcall: vectorcallfunc
# bitset of which type-watchers care about this type
tp_watched: t.CUnsignedChar
class PyMethodDef:
ml_name: t.CConst | str # The name of the built-in function/method */
ml_meth: PyCFunction # The C function that implements it */
ml_flags: int # Combination of METH_xxx flags, which mostly describe the args expected by the C func
ml_doc: t.CConst | str # The __doc__ attribute, or NULL
class PyModuleDef:
m_base: PyModuleDef_Base
m_name: t.CConst | str
m_doc: t.CConst | str
m_size: Py_ssize_t
m_methods: PyMethodDef | t.CPtr
m_slots: PyModuleDef_Slot | t.CPtr
m_traverse: traverseproc
m_clear: inquiry
m_free: freefunc
class PyMemberDef:
name: t.CConst | str
type: int
offset: Py_ssize_t
flags: int
doc: t.CConst | str
class PyGetSetDef:
name: t.CConst | str
get: getter
set: setter
doc: t.CConst | str
closure: t.CVoid | t.CPtr
class PyVarObject:
ob_base: PyObject
ob_size: Py_ssize_t # Number of items in variable part
class PyObject:
# _PyObject_HEAD_EXTRA
class ob(t.CUnion):
ob_refcnt: Py_ssize_t
if c.CIf(SIZEOF_VOID_P > 4):
ob_refcnt_split: list[PY_UINT32_T, 2]
ob_type: PyTypeObject | t.CPtr
PyObjectPtr: t.CTypedef = PyObject | t.CPtr
#typedef struct PyModuleDef PyModuleDef;
#typedef struct PyModuleDef_Slot PyModuleDef_Slot;
#typedef struct PyMethodDef PyMethodDef;
#typedef struct PyGetSetDef PyGetSetDef;
#typedef struct PyMemberDef PyMemberDef;
#typedef struct _object PyObject;
#typedef struct _longobject PyLongObject;
#typedef struct _typeobject PyTypeObject;
#typedef struct PyCodeObject PyCodeObject;
#typedef struct _frame PyFrameObject;
#typedef struct _ts PyThreadState;
#typedef struct _is PyInterpreterState;