Commit d17f11a8 authored by Kevin Modzelewski's avatar Kevin Modzelewski

need to add deallocation to keep checking this

parent 71b2fa6b
......@@ -600,6 +600,8 @@ public:
};
static_assert(sizeof(HCAttrs) == sizeof(struct _hcattrs), "");
extern std::vector<BoxedClass*> classes;
class BoxedDict;
class BoxedString;
......@@ -640,6 +642,8 @@ public:
void setDict(BoxedDict* d);
// These functions won't consume any references.
// ie they will incref val
void setattr(BoxedString* attr, Box* val, SetattrRewriteArgs* rewrite_args);
void giveAttr(const char* attr, Box* val) { giveAttr(internStringMortal(attr), val); }
void giveAttr(BoxedString* attr, Box* val) {
......
......@@ -398,6 +398,7 @@ void BoxedClass::freeze() {
is_constant = true;
}
std::vector<BoxedClass*> classes;
BoxedClass::BoxedClass(BoxedClass* base, gcvisit_func gc_visit, int attrs_offset, int weaklist_offset,
int instance_size, bool is_user_defined, const char* name)
: attrs(HiddenClass::makeSingleton()),
......@@ -410,6 +411,8 @@ BoxedClass::BoxedClass(BoxedClass* base, gcvisit_func gc_visit, int attrs_offset
has_instancecheck(false),
tpp_call(NULL, NULL) {
classes.push_back(this);
// Zero out the CPython tp_* slots:
memset(&tp_name, 0, (char*)(&tp_version_tag + 1) - (char*)(&tp_name));
tp_basicsize = instance_size;
......
......@@ -3699,19 +3699,6 @@ void setupRuntime() {
none_cls->giveAttr("__base__", object_cls);
object_cls->giveAttr("__base__", None);
auto classes = {type_cls, object_cls, none_cls, str_cls, basestring_cls};
_Py_ReleaseInternedStrings();
for (auto b : classes)
b->clearAttrs();
for (auto b : {None})
Py_DECREF(b);
for (auto b : classes)
Py_DECREF(b);
// XXX
PRINT_TOTAL_REFS();
exit(0);
// Not sure why CPython defines sizeof(PyTupleObject) to include one element,
// but we copy that, which means we have to subtract that extra pointer to get the tp_basicsize:
tuple_cls = new (0)
......@@ -3747,6 +3734,22 @@ void setupRuntime() {
function_cls->tp_dealloc = builtin_function_or_method_cls->tp_dealloc = functionDtor;
function_cls->has_safe_tp_dealloc = builtin_function_or_method_cls->has_safe_tp_dealloc = true;
_Py_ReleaseInternedStrings();
for (auto b : classes)
b->clearAttrs();
for (auto b : { (Box*)None, (Box*)EmptyTuple })
Py_DECREF(b);
for (auto b : classes) {
if (b->tp_mro) {
Py_DECREF(b->tp_mro);
}
Py_DECREF(b);
}
// XXX
PRINT_TOTAL_REFS();
exit(0);
module_cls = new (0) BoxedClass(object_cls, &BoxedModule::gcHandler, offsetof(BoxedModule, attrs), 0,
sizeof(BoxedModule), false, "module");
......
......@@ -534,13 +534,16 @@ public:
return EmptyTuple;
}
BoxedTuple* rtn = new (nelts) BoxedTuple();
for (int i = 0; i < nelts; i++)
for (int i = 0; i < nelts; i++) {
assert(gc::isValidGCObject(elts[i]));
Py_INCREF(elts[i]);
}
memmove(&rtn->elts[0], elts, sizeof(Box*) * nelts);
return rtn;
}
static BoxedTuple* create1(Box* elt0) {
BoxedTuple* rtn = new (1) BoxedTuple();
Py_INCREF(elt0);
rtn->elts[0] = elt0;
for (int i = 0; i < rtn->size(); i++)
assert(gc::isValidGCObject(rtn->elts[i]));
......@@ -548,6 +551,8 @@ public:
}
static BoxedTuple* create2(Box* elt0, Box* elt1) {
BoxedTuple* rtn = new (2) BoxedTuple();
Py_INCREF(elt0);
Py_INCREF(elt1);
rtn->elts[0] = elt0;
rtn->elts[1] = elt1;
for (int i = 0; i < rtn->size(); i++)
......@@ -556,6 +561,9 @@ public:
}
static BoxedTuple* create3(Box* elt0, Box* elt1, Box* elt2) {
BoxedTuple* rtn = new (3) BoxedTuple();
Py_INCREF(elt0);
Py_INCREF(elt1);
Py_INCREF(elt2);
rtn->elts[0] = elt0;
rtn->elts[1] = elt1;
rtn->elts[2] = elt2;
......@@ -565,6 +573,10 @@ public:
}
static BoxedTuple* create4(Box* elt0, Box* elt1, Box* elt2, Box* elt3) {
BoxedTuple* rtn = new (4) BoxedTuple();
Py_INCREF(elt0);
Py_INCREF(elt1);
Py_INCREF(elt2);
Py_INCREF(elt3);
rtn->elts[0] = elt0;
rtn->elts[1] = elt1;
rtn->elts[2] = elt2;
......@@ -575,6 +587,11 @@ public:
}
static BoxedTuple* create5(Box* elt0, Box* elt1, Box* elt2, Box* elt3, Box* elt4) {
BoxedTuple* rtn = new (5) BoxedTuple();
Py_INCREF(elt0);
Py_INCREF(elt1);
Py_INCREF(elt2);
Py_INCREF(elt3);
Py_INCREF(elt4);
rtn->elts[0] = elt0;
rtn->elts[1] = elt1;
rtn->elts[2] = elt2;
......@@ -586,6 +603,12 @@ public:
}
static BoxedTuple* create6(Box* elt0, Box* elt1, Box* elt2, Box* elt3, Box* elt4, Box* elt5) {
BoxedTuple* rtn = new (6) BoxedTuple();
Py_INCREF(elt0);
Py_INCREF(elt1);
Py_INCREF(elt2);
Py_INCREF(elt3);
Py_INCREF(elt4);
Py_INCREF(elt5);
rtn->elts[0] = elt0;
rtn->elts[1] = elt1;
rtn->elts[2] = elt2;
......@@ -619,6 +642,9 @@ public:
rtn = new (nelts) BoxedTuple();
else
rtn = new (cls, nelts) BoxedTuple();
for (int i = 0; i < nelts; i++) {
Py_INCREF(elts[i]);
}
memmove(&rtn->elts[0], elts, sizeof(Box*) * nelts);
return rtn;
}
......@@ -673,6 +699,7 @@ private:
// by the time we make it here elts[] is big enough to contain members
Box** p = &elts[0];
for (auto b : members) {
Py_INCREF(b);
*p++ = b;
assert(gc::isValidGCObject(b));
}
......
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