三、对象到底如何创建
来源:互联网 发布:80端口提供什么服务 编辑:程序博客网 时间:2024/06/07 22:33
http://blog.csdn.net/debugm/article/details/8241769
一、二 文中知道,无论PyObject还是PyXXXObject,都包含有那么几样东西。
具体举个例子来说,PyIntObject里面有三东西:
int ob_refcnt;//引用计数
struct _typeobject *ob_type; //一堆信息
long ob_ival; //值
只要把这三个要素构成了,不就生成一个基本的"int"了??是不是??
故在intobject.c中有如下代码出现。PyTypeObject就是_typeobject。
- PyTypeObject PyInt_Type = {
- PyVarObject_HEAD_INIT(&PyType_Type, 0)
- "int",
- sizeof(PyIntObject),
- 0,
- (destructor)int_dealloc, /* tp_dealloc */
- (printfunc)int_print, /* tp_print */
- 0, /* tp_getattr */
- 0, /* tp_setattr */
- (cmpfunc)int_compare, /* tp_compare */
- (reprfunc)int_to_decimal_string, /* tp_repr */
- &int_as_number, /* tp_as_number */
- 0, /* tp_as_sequence */
- 0, /* tp_as_mapping */
- (hashfunc)int_hash, /* tp_hash */
- 0, /* tp_call */
- (reprfunc)int_to_decimal_string, /* tp_str */
- PyObject_GenericGetAttr, /* tp_getattro */
- 0, /* tp_setattro */
- 0, /* tp_as_buffer */
- Py_TPFLAGS_DEFAULT | Py_TPFLAGS_CHECKTYPES |
- Py_TPFLAGS_BASETYPE | Py_TPFLAGS_INT_SUBCLASS, /* tp_flags */
- int_doc, /* tp_doc */
- 0, /* tp_traverse */
- 0, /* tp_clear */
- 0, /* tp_richcompare */
- 0, /* tp_weaklistoffset */
- 0, /* tp_iter */
- 0, /* tp_iternext */
- int_methods, /* tp_methods */
- 0, /* tp_members */
- int_getset, /* tp_getset */
- 0, /* tp_base */
- 0, /* tp_dict */
- 0, /* tp_descr_get */
- 0, /* tp_descr_set */
- 0, /* tp_dictoffset */
- 0, /* tp_init */
- 0, /* tp_alloc */
- int_new, /* tp_new */
- (freefunc)int_free, /* tp_free */
- };
总结:在XXXobject.c中,通过声明定义变量PyXXX_Type(PyTypeObject类型的)创建了一个XXX对象。
创建过程会调用一系列函数,具体过程是:tp_new(C++中的new),设置sizeof(PyIntObject),tp_init(视为类的构造函数)
参考:https://github.com/youngsterxyf/Translation/blob/master/Python-object-creation-sequence.rst- 三、对象到底如何创建
- 三、对象到底如何创建
- 到底创建了几个String对象?
- 到底创建了几个String对象
- 到底创建了几个String对象?(转载)
- 到底创建了几个String对象
- 到底创建了几个String对象?
- 到底创建了几个String对象
- String,到底创建了多少个对象?
- String,到底创建了多少个对象?
- String,到底创建了多少个对象?
- 到底创建了几个String对象?
- 到底创建了几个String对象?
- String,到底创建了多少个对象?
- 到底创建了几个String对象问题
- 到底创建了几个String对象?
- String,到底创建了多少个对象?
- String到底创建了多少个对象
- Qt QSortFilterProxyModel示例代码, 使用方法
- 移动支付成诈骗新宠 汇付宝提醒手机购物需谨慎
- 文档 用 微软雅黑
- 【xinfanqie】快速选择有线网络 提高网络速度
- zoj3329 One Person Game
- 三、对象到底如何创建
- Hadoop 新 MapReduce 框架 Yarn 详解
- 25个增强iOS应用程序性能的提示和技巧(初级篇)
- Android的monkey测试
- ARC属性的定义
- 更换svn账户
- SQL SERVER 函数组合实现oracle的LPAD函数功能
- HDU_2032 杨辉三角
- Linux uvc摄像头驱动初探