This commit is contained in:
2026-06-16 16:09:42 +08:00
commit bffb0cb6b7
644 changed files with 86620 additions and 0 deletions

View File

@@ -0,0 +1,178 @@
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;

View File

@@ -0,0 +1,37 @@
import Object
import t, c
class PyBytesObject:
ob_base: Object.PyVarObject
ob_shash: Object.Py_hash_t
ob_sval: list[t.CChar, 1]
def _PyBytes_Resize(arg0: Object.PyObjectPtr[t.CPtr], arg1: Object.Py_ssize_t) -> int | t.State: pass
def _PyBytes_FormatEx(format: t.CConst | str, format_len: Object.Py_ssize_t, args: Object.PyObjectPtr, use_bytearray: int) -> Object.PyObjectPtr | t.State: pass
def _PyBytes_FromHex(string: Object.PyObjectPtr, use_bytearray: int) -> Object.PyObjectPtr | t.State: pass
def _PyBytes_DecodeEscape(arg0: t.CConst | str, arg1: Object.Py_ssize_t, arg2: t.CConst | str, arg3: t.CConst | str | t.CPtr) -> Object.PyObjectPtr | t.State: pass
def _PyBytes_CAST(op) -> t.CDefine | PyBytesObject: (PyBytesObject | t.CPtr)(op)
def PyBytes_AS_STRING(op: Object.PyObjectPtr) -> t.CStatic | t.CInline | bytes:
return _PyBytes_CAST(op).ob_sval
def _PyBytes_Join(sep: Object.PyObjectPtr, x: Object.PyObjectPtr) -> Object.PyObjectPtr | t.State: pass
class _PyBytesWriter:
buffer: Object.PyObjectPtr
allocated: Object.Py_ssize_t
min_size: Object.Py_ssize_t
use_bytearray: int
overallocate: int
use_small_buffer: int
small_buffer: list[t.CChar, 512]
def _PyBytesWriter_Init(writer: _PyBytesWriter | t.CPtr) -> t.State: pass
def _PyBytesWriter_Finish(writer: _PyBytesWriter | t.CPtr, str: str) -> Object.PyObjectPtr | t.State: pass
def _PyBytesWriter_Dealloc(writer: _PyBytesWriter | t.CPtr) -> t.State: pass
def _PyBytesWriter_Alloc(writer: _PyBytesWriter | t.CPtr, size: Object.Py_ssize_t) -> bytes | t.State: pass
def _PyBytesWriter_Prepare(writer: _PyBytesWriter | t.CPtr, str: str, size: Object.Py_ssize_t) -> bytes | t.State: pass
def _PyBytesWriter_Resize(writer: _PyBytesWriter | t.CPtr, str: str, size: Object.Py_ssize_t) -> bytes | t.State: pass
def _PyBytesWriter_WriteBytes(writer: _PyBytesWriter | t.CPtr, str: str, bytes: t.CConst | bytes, size: Object.Py_ssize_t) -> bytes | t.State: pass

View File

@@ -0,0 +1,19 @@
import Object
import t, c
class PyFloatObject:
ob_base: Object.PyObject
ob_fval: t.CDouble
def PyFloat_AS_DOUBLE(op: Object.PyObjectPtr) -> t.CStatic | t.CInline | t.CDouble:
return (PyFloatObject | t.CPtr)(op).ob_fval
def PyFloat_Pack2(x: t.CDouble, p: str, le: int) -> int | t.State: pass
def PyFloat_Pack4(x: t.CDouble, p: str, le: int) -> int | t.State: pass
def PyFloat_Pack8(x: t.CDouble, p: str, le: int) -> int | t.State: pass
def PyFloat_Unpack2(p: t.CConst | str, le: int) -> t.CDouble | t.State: pass
def PyFloat_Unpack4(p: t.CConst | str, le: int) -> t.CDouble | t.State: pass
def PyFloat_Unpack8(p: t.CConst | str, le: int) -> t.CDouble | t.State: pass

View File

@@ -0,0 +1,11 @@
import Object
import t, c
class PyListObject:
ob_base: Object.PyVarObject
ob_item: Object.PyObjectPtr[t.CPtr]
allocated: Object.Py_ssize_t
def _PyList_Extend(arg0: PyListObject | t.CPtr, arg1: PyListObject | t.CPtr) -> PyListObject | t.CPtr | t.State: pass
def _PyList_DebugMallocStats(out: FILE | t.CPtr) -> t.State: pass

View File

@@ -0,0 +1,16 @@
import Object
import t, c
digit: t.CTypedef = t.CUInt32T
sdigit: t.CTypedef = t.CInt32T # signed variant of digit
twodigits: t.CTypedef = t.CUInt64T
stwodigits: t.CTypedef = t.CInt64T # signed variant of twodigits
class _PyLongValue:
lv_tag: t.CUIntPtrT # Number of digits, sign and flags
ob_digit: list[digit, 1]
class PyLongObject:
ob_base: Object.PyObject
long_value: _PyLongValue

View File

@@ -0,0 +1,38 @@
import Object
import t, c
# --- Unicode Type -------------------------------------------------------
# ASCII-only strings created through PyUnicode_New use the PyASCIIObject
# structure. state.ascii and state.compact are set, and the data
# immediately follow the structure. utf8_length can be found
# in the length field; the utf8 pointer is equal to the data pointer. */
class PyASCIIObject:
ob_base: Object.PyObject
length: Object.Py_ssize_t # Number of code points in the string
hash: Object.Py_hash_t # Hash value; -1 if not set
class state:
interned: t.CUnsignedInt | t.Bit[2]
kind: t.CUnsignedInt | t.Bit[3]
compact: t.CUnsignedInt | t.Bit[1]
ascii: t.CUnsignedInt | t.Bit[1]
_: t.CUnsignedInt | t.Bit[25]
class PyCompactUnicodeObject:
_base: PyASCIIObject
utf8_length: Object.Py_ssize_t # Number of bytes in utf8, excluding the * terminating \0.
utf8: str # UTF-8 representation (null-terminated)
Py_UCS4: t.CTypedef = t.CUInt32T
Py_UCS2: t.CTypedef = t.CUInt16T
Py_UCS1: t.CTypedef = t.CUInt8T
# Object format for Unicode subclasses.
class PyUnicodeObject:
_base: PyCompactUnicodeObject
class data(t.CUnion):
any: t.CVoid | t.CPtr
latin1: Py_UCS1 | t.CPtr
ucs2: Py_UCS2 | t.CPtr
ucs4: Py_UCS4 | t.CPtr
# Canonical, smallest-form Unicode buffer