Commit 99ff28d1 authored by Kevin Modzelewski's avatar Kevin Modzelewski

Passes with malloc checking turned on

parent 163f4574
...@@ -400,7 +400,7 @@ void BoxedClass::freeze() { ...@@ -400,7 +400,7 @@ void BoxedClass::freeze() {
std::vector<BoxedClass*> classes; std::vector<BoxedClass*> classes;
BoxedClass::BoxedClass(BoxedClass* base, int attrs_offset, int weaklist_offset, int instance_size, bool is_user_defined, BoxedClass::BoxedClass(BoxedClass* base, int attrs_offset, int weaklist_offset, int instance_size, bool is_user_defined,
const char* name, destructor dealloc, freefunc free) const char* name, destructor dealloc, freefunc free, bool is_gc)
: attrs(HiddenClass::makeSingleton()), : attrs(HiddenClass::makeSingleton()),
attrs_offset(attrs_offset), attrs_offset(attrs_offset),
is_constant(false), is_constant(false),
...@@ -421,7 +421,8 @@ BoxedClass::BoxedClass(BoxedClass* base, int attrs_offset, int weaklist_offset, ...@@ -421,7 +421,8 @@ BoxedClass::BoxedClass(BoxedClass* base, int attrs_offset, int weaklist_offset,
tp_flags |= Py_TPFLAGS_DEFAULT_CORE; tp_flags |= Py_TPFLAGS_DEFAULT_CORE;
tp_flags |= Py_TPFLAGS_CHECKTYPES; tp_flags |= Py_TPFLAGS_CHECKTYPES;
tp_flags |= Py_TPFLAGS_BASETYPE; tp_flags |= Py_TPFLAGS_BASETYPE;
tp_flags |= Py_TPFLAGS_HAVE_GC; if (is_gc)
tp_flags |= Py_TPFLAGS_HAVE_GC;
if (base && (base->tp_flags & Py_TPFLAGS_HAVE_NEWBUFFER)) if (base && (base->tp_flags & Py_TPFLAGS_HAVE_NEWBUFFER))
tp_flags |= Py_TPFLAGS_HAVE_NEWBUFFER; tp_flags |= Py_TPFLAGS_HAVE_NEWBUFFER;
...@@ -458,16 +459,20 @@ BoxedClass::BoxedClass(BoxedClass* base, int attrs_offset, int weaklist_offset, ...@@ -458,16 +459,20 @@ BoxedClass::BoxedClass(BoxedClass* base, int attrs_offset, int weaklist_offset,
assert(base && base->tp_dealloc); assert(base && base->tp_dealloc);
tp_dealloc = base->tp_dealloc; tp_dealloc = base->tp_dealloc;
} }
if (PyType_IS_GC(this))
assert(tp_free != PyObject_Del);
if (free) if (free)
tp_free = free; tp_free = free;
else { else if (base) {
assert(base && base->tp_free); // Copied from PyType_Ready
tp_free = base->tp_free; if (PyType_IS_GC(this) == PyType_IS_GC(base))
tp_free = base->tp_free;
else if (PyType_IS_GC(this) && base->tp_free == PyObject_Del)
this->tp_free = PyObject_GC_Del;
} }
if (PyType_IS_GC(this))
assert(tp_free != PyObject_Del);
assert(tp_dealloc); assert(tp_dealloc);
assert(tp_free); assert(tp_free);
...@@ -495,10 +500,10 @@ BoxedClass::BoxedClass(BoxedClass* base, int attrs_offset, int weaklist_offset, ...@@ -495,10 +500,10 @@ BoxedClass::BoxedClass(BoxedClass* base, int attrs_offset, int weaklist_offset,
BoxedClass* BoxedClass::create(BoxedClass* metaclass, BoxedClass* base, int attrs_offset, int weaklist_offset, BoxedClass* BoxedClass::create(BoxedClass* metaclass, BoxedClass* base, int attrs_offset, int weaklist_offset,
int instance_size, bool is_user_defined, const char* name, destructor dealloc, int instance_size, bool is_user_defined, const char* name, destructor dealloc,
freefunc free) { freefunc free, bool is_gc) {
assert(!is_user_defined); assert(!is_user_defined);
BoxedClass* made = new (metaclass, 0) BoxedClass* made = new (metaclass, 0)
BoxedClass(base, attrs_offset, weaklist_offset, instance_size, is_user_defined, name, dealloc, free); BoxedClass(base, attrs_offset, weaklist_offset, instance_size, is_user_defined, name, dealloc, free, is_gc);
// While it might be ok if these were set, it'd indicate a difference in // While it might be ok if these were set, it'd indicate a difference in
// expectations as to who was going to calculate them: // expectations as to who was going to calculate them:
......
...@@ -3448,8 +3448,7 @@ void setupRuntime() { ...@@ -3448,8 +3448,7 @@ void setupRuntime() {
type_cls = static_cast<BoxedClass*>(PyObject_MALLOC(sizeof(BoxedClass))); type_cls = static_cast<BoxedClass*>(PyObject_MALLOC(sizeof(BoxedClass)));
PyObject_INIT(object_cls, type_cls); PyObject_INIT(object_cls, type_cls);
PyObject_INIT(type_cls, type_cls); PyObject_INIT(type_cls, type_cls);
::new (object_cls) BoxedClass(NULL, 0, 0, sizeof(Box), false, "object", object_dealloc, PyObject_Del); ::new (object_cls) BoxedClass(NULL, 0, 0, sizeof(Box), false, "object", object_dealloc, PyObject_Del, /* is_gc */ false);
object_cls->tp_flags &= ~Py_TPFLAGS_HAVE_GC;
::new (type_cls) BoxedClass(object_cls, offsetof(BoxedClass, attrs), offsetof(BoxedClass, tp_weaklist), ::new (type_cls) BoxedClass(object_cls, offsetof(BoxedClass, attrs), offsetof(BoxedClass, tp_weaklist),
sizeof(BoxedHeapClass), false, "type", BoxedClass::dealloc, PyObject_GC_Del); sizeof(BoxedHeapClass), false, "type", BoxedClass::dealloc, PyObject_GC_Del);
...@@ -3467,18 +3466,18 @@ void setupRuntime() { ...@@ -3467,18 +3466,18 @@ void setupRuntime() {
object_cls->tp_new = object_new; object_cls->tp_new = object_new;
type_cls->tp_getattro = type_getattro; type_cls->tp_getattro = type_getattro;
none_cls = new (0) BoxedClass(object_cls, 0, 0, sizeof(Box), false, "NoneType", NULL, NULL); none_cls = new (0) BoxedClass(object_cls, 0, 0, sizeof(Box), false, "NoneType", NULL, NULL, /* is_gc */ false);
None = new (none_cls) Box(); None = new (none_cls) Box();
constants.push_back(None); constants.push_back(None);
assert(None->cls); assert(None->cls);
// You can't actually have an instance of basestring // You can't actually have an instance of basestring
basestring_cls = new (0) BoxedClass(object_cls, 0, 0, sizeof(Box), false, "basestring", NULL, NULL); basestring_cls = new (0) BoxedClass(object_cls, 0, 0, sizeof(Box), false, "basestring", NULL, NULL, false);
// We add 1 to the tp_basicsize of the BoxedString in order to hold the null byte at the end. // We add 1 to the tp_basicsize of the BoxedString in order to hold the null byte at the end.
// We use offsetof(BoxedString, s_data) as opposed to sizeof(BoxedString) so that we can // We use offsetof(BoxedString, s_data) as opposed to sizeof(BoxedString) so that we can
// use the extra padding bytes at the end of the BoxedString. // use the extra padding bytes at the end of the BoxedString.
str_cls = new (0) BoxedClass(basestring_cls, 0, 0, offsetof(BoxedString, s_data) + 1, false, "str", NULL, NULL); str_cls = new (0) BoxedClass(basestring_cls, 0, 0, offsetof(BoxedString, s_data) + 1, false, "str", NULL, NULL, false);
str_cls->tp_flags |= Py_TPFLAGS_STRING_SUBCLASS; str_cls->tp_flags |= Py_TPFLAGS_STRING_SUBCLASS;
str_cls->tp_itemsize = sizeof(char); str_cls->tp_itemsize = sizeof(char);
...@@ -3514,18 +3513,13 @@ void setupRuntime() { ...@@ -3514,18 +3513,13 @@ void setupRuntime() {
dict_cls->tp_flags |= Py_TPFLAGS_DICT_SUBCLASS; dict_cls->tp_flags |= Py_TPFLAGS_DICT_SUBCLASS;
file_cls = new (0) BoxedClass(object_cls, 0, offsetof(BoxedFile, weakreflist), file_cls = new (0) BoxedClass(object_cls, 0, offsetof(BoxedFile, weakreflist),
sizeof(BoxedFile), false, "file", file_dealloc, NULL); sizeof(BoxedFile), false, "file", file_dealloc, NULL);
int_cls = new (0) BoxedClass(object_cls, 0, 0, sizeof(BoxedInt), false, "int", NULL, NULL); int_cls = new (0) BoxedClass(object_cls, 0, 0, sizeof(BoxedInt), false, "int", NULL, NULL, false);
int_cls->tp_flags |= Py_TPFLAGS_INT_SUBCLASS; int_cls->tp_flags |= Py_TPFLAGS_INT_SUBCLASS;
int_cls->tp_flags &= ~Py_TPFLAGS_HAVE_GC; bool_cls = new (0) BoxedClass(int_cls, 0, 0, sizeof(BoxedBool), false, "bool", NULL, NULL, false);
bool_cls = new (0) BoxedClass(int_cls, 0, 0, sizeof(BoxedBool), false, "bool", NULL, NULL); complex_cls = new (0) BoxedClass(object_cls, 0, 0, sizeof(BoxedComplex), false, "complex", NULL, NULL, false);
bool_cls->tp_flags &= ~Py_TPFLAGS_HAVE_GC; long_cls = new (0) BoxedClass(object_cls, 0, 0, sizeof(BoxedLong), false, "long", NULL, NULL, false);
complex_cls = new (0) BoxedClass(object_cls, 0, 0, sizeof(BoxedComplex), false, "complex", NULL, NULL);
complex_cls->tp_flags &= ~Py_TPFLAGS_HAVE_GC;
long_cls = new (0) BoxedClass(object_cls, 0, 0, sizeof(BoxedLong), false, "long", NULL, NULL);
long_cls->tp_flags |= Py_TPFLAGS_LONG_SUBCLASS; long_cls->tp_flags |= Py_TPFLAGS_LONG_SUBCLASS;
long_cls->tp_flags &= ~Py_TPFLAGS_HAVE_GC; float_cls = new (0) BoxedClass(object_cls, 0, 0, sizeof(BoxedFloat), false, "float", NULL, NULL, false);
float_cls = new (0) BoxedClass(object_cls, 0, 0, sizeof(BoxedFloat), false, "float", NULL, NULL);
float_cls->tp_flags &= ~Py_TPFLAGS_HAVE_GC;
function_cls = new (0) function_cls = new (0)
BoxedClass(object_cls, offsetof(BoxedFunction, attrs), BoxedClass(object_cls, offsetof(BoxedFunction, attrs),
offsetof(BoxedFunction, weakreflist), sizeof(BoxedFunction), false, "function", functionDtor, NULL); offsetof(BoxedFunction, weakreflist), sizeof(BoxedFunction), false, "function", functionDtor, NULL);
......
...@@ -277,10 +277,10 @@ public: ...@@ -277,10 +277,10 @@ public:
// These should only be used for builtin types: // These should only be used for builtin types:
static BoxedClass* create(BoxedClass* metatype, BoxedClass* base, int attrs_offset, int weaklist_offset, static BoxedClass* create(BoxedClass* metatype, BoxedClass* base, int attrs_offset, int weaklist_offset,
int instance_size, bool is_user_defined, const char* name, destructor dealloc = NULL, int instance_size, bool is_user_defined, const char* name, destructor dealloc = NULL,
freefunc free = NULL); freefunc free = NULL, bool is_gc = true);
BoxedClass(BoxedClass* base, int attrs_offset, int weaklist_offset, int instance_size, BoxedClass(BoxedClass* base, int attrs_offset, int weaklist_offset, int instance_size,
bool is_user_defined, const char* name, destructor dealloc, freefunc free); bool is_user_defined, const char* name, destructor dealloc, freefunc free, bool is_gc = true);
DEFAULT_CLASS_VAR(type_cls, sizeof(SlotOffset)); DEFAULT_CLASS_VAR(type_cls, sizeof(SlotOffset));
......
...@@ -154,7 +154,7 @@ extern "C" void dumpEx(void* p, int levels) { ...@@ -154,7 +154,7 @@ extern "C" void dumpEx(void* p, int levels) {
printf("Guessing that it's a Python object\n"); printf("Guessing that it's a Python object\n");
Box* b = (Box*)p; Box* b = (Box*)p;
printf("Class: %s", getFullTypeName(b).c_str()); printf("Class: %s", b->cls->tp_name);
if (b->cls->cls != type_cls) { if (b->cls->cls != type_cls) {
printf(" (metaclass: %s)\n", getFullTypeName(b->cls).c_str()); printf(" (metaclass: %s)\n", getFullTypeName(b->cls).c_str());
} else { } else {
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment