示例#1
0
文件: gcmodule.c 项目: d11/rts
/* Return true if object has a finalization method. */
static int
has_finalizer(PyObject *op)
{
    /* first, dynamic decision per object */
    traverseproc traverse;
    int collectable;
    traverse = Py_TYPE(op)->tp_traverse;
    collectable = -1;
    (void) traverse(op,
                    (visitproc)visit_has_finalizer,
                    (void *)&collectable);
    if (collectable >= 0)
        return collectable == 0;

    if ( PyType_Check(op)) {
        assert(delstr != NULL);
        return _PyType_Lookup(Py_TYPE(op), delstr) != NULL;
    }
    else if (PyType_HasFeature(op->ob_type, Py_TPFLAGS_HEAPTYPE))
        return op->ob_type->tp_del != NULL;
    else if (PyGen_CheckExact(op))
        return PyGen_NeedsFinalizing((PyGenObject *)op);
    else
        return op->ob_type->tp_del != NULL;
}
示例#2
0
/* Return true if object has a finalization method. */
static int
has_finalizer(PyObject *op)
{
    if (PyGen_CheckExact(op))
        return PyGen_NeedsFinalizing((PyGenObject *)op);
    else
        return op->ob_type->tp_del != NULL;
}
示例#3
0
/* Return true if object has a finalization method.
 * CAUTION:  An instance of an old-style class has to be checked for a
 *__del__ method, and earlier versions of this used to call PyObject_HasAttr,
 * which in turn could call the class's __getattr__ hook (if any).  That
 * could invoke arbitrary Python code, mutating the object graph in arbitrary
 * ways, and that was the source of some excruciatingly subtle bugs.
 */
static int
has_finalizer(PyObject *op)
{
	if (PyInstance_Check(op)) {
		assert(delstr != NULL);
		return _PyInstance_Lookup(op, delstr) != NULL;
	}
	else if (PyType_HasFeature(op->ob_type, Py_TPFLAGS_HEAPTYPE))
		return op->ob_type->tp_del != NULL;
	else if (PyGen_CheckExact(op))
		return PyGen_NeedsFinalizing((PyGenObject *)op);
	else
		return 0;
}