int
PyType_Ready(PyTypeObject *type)
{
PyObject *dict, *bases;
PyTypeObject *base;
Py_ssize_t i, n; if (type->tp_flags & Py_TPFLAGS_READY) {
assert(type->tp_dict != NULL);
return ;
}
assert((type->tp_flags & Py_TPFLAGS_READYING) == ); type->tp_flags |= Py_TPFLAGS_READYING; #ifdef Py_TRACE_REFS
/* PyType_Ready is the closest thing we have to a choke point
* for type objects, so is the best place I can think of to try
* to get type objects into the doubly-linked list of all objects.
* Still, not all type objects go thru PyType_Ready.
*/
_Py_AddToAllObjects((PyObject *)type, );
#endif /* Initialize tp_base (defaults to BaseObject unless that's us) */
base = type->tp_base;
if (base == NULL && type != &PyBaseObject_Type) {
base = type->tp_base = &PyBaseObject_Type;
Py_INCREF(base);
} /* Now the only way base can still be NULL is if type is
* &PyBaseObject_Type.
*/ /* Initialize the base class */
if (base && base->tp_dict == NULL) {
if (PyType_Ready(base) < )
goto error;
} /* Initialize ob_type if NULL. This means extensions that want to be
compilable separately on Windows can call PyType_Ready() instead of
initializing the ob_type field of their type objects. */
/* The test for base != NULL is really unnecessary, since base is only
NULL when type is &PyBaseObject_Type, and we know its ob_type is
not NULL (it's initialized to &PyType_Type). But coverity doesn't
know that. */
if (Py_TYPE(type) == NULL && base != NULL)
Py_TYPE(type) = Py_TYPE(base); /* Initialize tp_bases */
bases = type->tp_bases;
if (bases == NULL) {
if (base == NULL)
bases = PyTuple_New();
else
bases = PyTuple_Pack(, base);
if (bases == NULL)
goto error;
type->tp_bases = bases;
} /* Initialize tp_dict */
dict = type->tp_dict;
if (dict == NULL) {
dict = PyDict_New();
if (dict == NULL)
goto error;
type->tp_dict = dict;
} /* Add type-specific descriptors to tp_dict */
if (add_operators(type) < )
goto error;
if (type->tp_methods != NULL) {
if (add_methods(type, type->tp_methods) < )
goto error;
}
if (type->tp_members != NULL) {
if (add_members(type, type->tp_members) < )
goto error;
}
if (type->tp_getset != NULL) {
if (add_getset(type, type->tp_getset) < )
goto error;
} /* Calculate method resolution order */
if (mro_internal(type) < ) {
goto error;
} /* Inherit special flags from dominant base */
if (type->tp_base != NULL)
inherit_special(type, type->tp_base); /* Initialize tp_dict properly */
bases = type->tp_mro;
assert(bases != NULL);
assert(PyTuple_Check(bases));
n = PyTuple_GET_SIZE(bases);
for (i = ; i < n; i++) {
PyObject *b = PyTuple_GET_ITEM(bases, i);
if (PyType_Check(b))
inherit_slots(type, (PyTypeObject *)b);
} /* Sanity check for tp_free. */
if (PyType_IS_GC(type) && (type->tp_flags & Py_TPFLAGS_BASETYPE) &&
(type->tp_free == NULL || type->tp_free == PyObject_Del)) {
/* This base class needs to call tp_free, but doesn't have
* one, or its tp_free is for non-gc'ed objects.
*/
PyErr_Format(PyExc_TypeError, "type '%.100s' participates in "
"gc and is a base type but has inappropriate "
"tp_free slot",
type->tp_name);
goto error;
} /* if the type dictionary doesn't contain a __doc__, set it from
the tp_doc slot.
*/
if (PyDict_GetItemString(type->tp_dict, "__doc__") == NULL) {
if (type->tp_doc != NULL) {
PyObject *doc = PyString_FromString(type->tp_doc);
if (doc == NULL)
goto error;
PyDict_SetItemString(type->tp_dict, "__doc__", doc);
Py_DECREF(doc);
} else {
PyDict_SetItemString(type->tp_dict,
"__doc__", Py_None);
}
} /* Some more special stuff */
base = type->tp_base;
if (base != NULL) {
if (type->tp_as_number == NULL)
type->tp_as_number = base->tp_as_number;
if (type->tp_as_sequence == NULL)
type->tp_as_sequence = base->tp_as_sequence;
if (type->tp_as_mapping == NULL)
type->tp_as_mapping = base->tp_as_mapping;
if (type->tp_as_buffer == NULL)
type->tp_as_buffer = base->tp_as_buffer;
} /* Link into each base class's list of subclasses */
bases = type->tp_bases;
n = PyTuple_GET_SIZE(bases);
for (i = ; i < n; i++) {
PyObject *b = PyTuple_GET_ITEM(bases, i);
if (PyType_Check(b) &&
add_subclass((PyTypeObject *)b, type) < )
goto error;
} /* All done -- set the ready flag */
assert(type->tp_dict != NULL);
type->tp_flags =
(type->tp_flags & ~Py_TPFLAGS_READYING) | Py_TPFLAGS_READY;
return ; error:
type->tp_flags &= ~Py_TPFLAGS_READYING;
return -;
}

python tp_ready函数分析的更多相关文章

  1. Python回调函数用法实例详解

    本文实例讲述了Python回调函数用法.分享给大家供大家参考.具体分析如下: 一.百度百科上对回调函数的解释: 回调函数就是一个通过函数指针调用的函数.如果你把函数的指针(地址)作为参数传递给另一个函 ...

  2. Python之函数与变量

    本节内容 函数介绍及其作用 函数的定义与调用 函数的参数说明 全局变量与局部变量 值传递和引用传递 一.函数的介绍及其作用 编程语言中的函数与数学中的函数是有区别的:数学中的函数有参数(输入),就会有 ...

  3. 【C++实现python字符串函数库】一:分割函数:split、rsplit

    [C++实现python字符串函数库]split()与rsplit()方法 前言 本系列文章将介绍python提供的字符串函数,并尝试使用C++来实现这些函数.这些C++函数在这里做单独的分析,最后我 ...

  4. 第三章:Python基础の函数和文件操作实战

    本課主題 Set 集合和操作实战 函数介紹和操作实战 参数的深入介绍和操作实战 format 函数操作实战 lambda 表达式介绍 文件操作函数介紹和操作实战 本周作业 Set 集合和操作实战 Se ...

  5. Python文章相关性分析---金庸武侠小说分析

    百度到<金庸小说全集 14部>全(TXT)作者:金庸 下载下来,然后读取内容with open('names.txt') as f: data = [line.strip() for li ...

  6. Python 3 函数自由变量的大坑

    Python中函数是一个对象, 和整数,字符串等对象有很多相似之处,例如可以作为其他函数的参数或返回对象, Python中的函数还可以携带自由变量, 两者无疑极大增进了Python的表达力. 但是Py ...

  7. 学以致用三十二-----python中函数的括号使用

    一直以来对python中函数括号的使用,有点分不清楚,到底什么时候用括号,什么时候不用括号,造成了很大看困惑. 今天来总结下. class aaa(): y = 'you' def __init__( ...

  8. 用python探索和分析网络数据

    Edited by Markdown Refered from: John Ladd, Jessica Otis, Christopher N. Warren, and Scott Weingart, ...

  9. python第六天 函数 python标准库实例大全

    今天学习第一模块的最后一课课程--函数: python的第一个函数: 1 def func1(): 2 print('第一个函数') 3 return 0 4 func1() 1 同时返回多种类型时, ...

随机推荐

  1. javascript 跨域请求详细分析(终极跨域解决办法)

    自从我接触前端以来,接手的项目里面很大部分都是前后端分离的,后端只提供接口,前端根据后端接口渲染出实际页面.个人觉得这是一个挺好的模式,前后端各自负责各自的模块,分工明确,而且也给前端更大的发挥空间. ...

  2. JS类小功能

    工作中,总是要处理一些前端的小功能.都是网上搜的JS脚本 <script> //防止页面后退 history.pushState(null, null, document.URL); wi ...

  3. TensorFlow 神经网络相关函数

    TensorFlow 激活函数 激活操作提供用于神经网络的不同类型的非线性.这些包括平滑的非线性(sigmoid,tanh,elu,softplus,和softsign),连续的,但不是到处可微函数( ...

  4. Fiddler中session请求/响应类型与图标含义

    近期在看fiddler抓包工具,发现前面都会有小图标显示,不同的图标代表了不同的含义,通过查询,整理如下:  请求发送到服务器  从服务器下载响应结果  请求在断点处被暂停  响应在断点处被暂停  请 ...

  5. 1159 Palindrome

    Palindrome Time Limit: 3000MS   Memory Limit: 65536K Total Submissions: 68562   Accepted: 23869 Desc ...

  6. testDecoration

    def count(): fs = [] for i in range(1,4): def f(): n=i*i return n fs.append(f) return fs c1,c2,c3 = ...

  7. 535种使用JavaScript重新加载页面的方法

    除了location = location之外还有534中方法重新加载页面 location = location location = location.href location = window ...

  8. oracle-组件vault

    ===================== lsnrctl stopshutdown immediate;emctl stop dbconsolecd $ORACLE_HOME/rdbms/libma ...

  9. Python小练习(二)

    按照下面的要求实现对列表的操作:       1)产生一个列表,其中有40个元素,每个元素是0到100的一个随机整数       2)如果这个列表中的数据代表着某个班级40人的分数,请计算成绩低于平均 ...

  10. mysql查询中AND与OR注意事项

    在查询的where条件中,and要优于or 如果要改变优先级, 需要在最小逻辑判断的条件外加括号(),例如: select * from `table_name` where (`type` = 1 ...