Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 13 additions & 10 deletions 23 Objects/typeobject.c
Original file line number Diff line number Diff line change
Expand Up @@ -1116,7 +1116,7 @@ subtype_dealloc(PyObject *self)

/* Extract the type; we expect it to be a heap type */
type = Py_TYPE(self);
assert(type->tp_flags & Py_TPFLAGS_HEAPTYPE);
_PyObject_ASSERT((PyObject *)type, type->tp_flags & Py_TPFLAGS_HEAPTYPE);

/* Test whether the type has GC exactly once */

Expand Down Expand Up @@ -2208,17 +2208,19 @@ subtype_getweakref(PyObject *obj, void *context)
{
PyObject **weaklistptr;
PyObject *result;
PyTypeObject *type = Py_TYPE(obj);

if (Py_TYPE(obj)->tp_weaklistoffset == 0) {
if (type->tp_weaklistoffset == 0) {
PyErr_SetString(PyExc_AttributeError,
"This object has no __weakref__");
return NULL;
}
assert(Py_TYPE(obj)->tp_weaklistoffset > 0);
assert(Py_TYPE(obj)->tp_weaklistoffset + sizeof(PyObject *) <=
(size_t)(Py_TYPE(obj)->tp_basicsize));
weaklistptr = (PyObject **)
((char *)obj + Py_TYPE(obj)->tp_weaklistoffset);
_PyObject_ASSERT((PyObject *)type,
type->tp_weaklistoffset > 0);
_PyObject_ASSERT((PyObject *)type,
((type->tp_weaklistoffset + sizeof(PyObject *))
<= (size_t)(type->tp_basicsize)));
weaklistptr = (PyObject **)((char *)obj + type->tp_weaklistoffset);
if (*weaklistptr == NULL)
result = Py_None;
else
Expand Down Expand Up @@ -3279,7 +3281,7 @@ type_dealloc(PyTypeObject *type)
PyObject *tp, *val, *tb;

/* Assert this is a heap-allocated type object */
assert(type->tp_flags & Py_TPFLAGS_HEAPTYPE);
_PyObject_ASSERT((PyObject *)type, type->tp_flags & Py_TPFLAGS_HEAPTYPE);
_PyObject_GC_UNTRACK(type);
PyErr_Fetch(&tp, &val, &tb);
remove_all_subclasses(type, type->tp_bases);
Expand Down Expand Up @@ -3503,7 +3505,7 @@ type_clear(PyTypeObject *type)
PyDictKeysObject *cached_keys;
/* Because of type_is_gc(), the collector only calls this
for heaptypes. */
assert(type->tp_flags & Py_TPFLAGS_HEAPTYPE);
_PyObject_ASSERT((PyObject *)type, type->tp_flags & Py_TPFLAGS_HEAPTYPE);

/* We need to invalidate the method cache carefully before clearing
the dict, so that other objects caught in a reference cycle
Expand Down Expand Up @@ -5117,7 +5119,8 @@ PyType_Ready(PyTypeObject *type)
assert(_PyType_CheckConsistency(type));
return 0;
}
assert((type->tp_flags & Py_TPFLAGS_READYING) == 0);
_PyObject_ASSERT((PyObject *)type,
(type->tp_flags & Py_TPFLAGS_READYING) == 0);

type->tp_flags |= Py_TPFLAGS_READYING;

Expand Down
Morty Proxy This is a proxified and sanitized view of the page, visit original site.