/* PyObject_HEAD defines the initial segment of every PyObject. */ #define PyObject_HEAD \ _PyObject_HEAD_EXTRA \ Py_ssize_t ob_refcnt; \ struct _typeobject *ob_type;
typedef struct _object {
PyObject_HEAD
} PyObject;
typedef struct {
PyObject_VAR_HEAD
} PyVarObject;
#define PyObject_VAR_HEAD \
PyObject_HEAD \
Py_ssize_t ob_size; /* Number of items in variable part */
>>> a = 1 >>> a 1 >>> type(a) <type 'int'> #等价的两个 >>> type(type(a)) <type 'type'> >>> type(int) <type 'type'> #还是等价的两个 >>> type(type(type(a))) <type 'type'> >>> type(type(int)) <type 'type'>
typedef struct _typeobject {
/* MARK: base, 注意, 是个变长对象*/
PyObject_VAR_HEAD
const char *tp_name; /* For printing, in format "<module>.<name>" */ //类型名
Py_ssize_t tp_basicsize, tp_itemsize; /* For allocation */ // 创建该类型对象时分配的内存空间大小
// 一堆方法定义, 函数和指针
/* Methods to implement standard operations */
printfunc tp_print;
hashfunc tp_hash;
/* Method suites for standard classes */
PyNumberMethods *tp_as_number; // 数值对象操作
PySequenceMethods *tp_as_sequence; // 序列对象操作
PyMappingMethods *tp_as_mapping; // 字典对象操作
// 一堆属性定义
....
} PyTypeObject;
PyTypeObject PyType_Type = {
PyVarObject_HEAD_INIT(&PyType_Type, 0)
"type", /* tp_name */
sizeof(PyHeapTypeObject), /* tp_basicsize */
sizeof(PyMemberDef), /* tp_itemsize */
(destructor)type_dealloc, /* tp_dealloc */
// type对象的方法和属性初始化值
.....
};
# 1. int 的 类型 是`type` >>> type(int) <type 'type'> # 2. type 的类型 还是`type`, 对应上面说明第二点 >>> type(type(int)) <type 'type'>
PyTypeObject PyInt_Type = {
PyVarObject_HEAD_INIT(&PyType_Type, 0)
"int",
sizeof(PyIntObject),
0,
// int类型的相关方法和属性值
....
(hashfunc)int_hash, /* tp_hash */
};
*ob_type = &PyType_Type
>>> type(1) <type 'int'> >>> type(type(1)) <type 'type'>
typedef struct {
PyObject_HEAD
long ob_ival;
} PyIntObject;
机械节能产品生产企业官网模板...
大气智能家居家具装修装饰类企业通用网站模板...
礼品公司网站模板
宽屏简约大气婚纱摄影影楼模板...
蓝白WAP手机综合医院类整站源码(独立后台)...苏ICP备2024110244号-2 苏公网安备32050702011978号 增值电信业务经营许可证编号:苏B2-20251499 | Copyright 2018 - 2025 源码网商城 (www.ymwmall.com) 版权所有