Commit 448680a3 authored by Kevin Modzelewski's avatar Kevin Modzelewski

Free instance attributes

parent cf3ae02d
......@@ -634,7 +634,7 @@ private:
BoxedDict** getDictPtr();
// Appends a new value to the hcattrs array.
void appendNewHCAttr(Box* val, SetattrRewriteArgs* rewrite_args);
void appendNewHCAttr(BORROWED(Box*) val, SetattrRewriteArgs* rewrite_args);
public:
// Add a no-op constructor to make sure that we don't zero-initialize cls
......@@ -660,7 +660,7 @@ public:
// Note, setattr does *not* steal a reference, but it probably should
void setattr(BoxedString* attr, Box* val, SetattrRewriteArgs* rewrite_args);
void setattr(BoxedString* attr, BORROWED(Box*) val, SetattrRewriteArgs* rewrite_args);
// giveAttr consumes a reference to val and attr
void giveAttr(const char* attr, Box* val) { giveAttr(internStringMortal(attr), val); }
// giveAttrBorrowed consumes a reference only to attr (but it only has the const char* variant
......
......@@ -480,6 +480,11 @@ static void subtype_dealloc(Box* self) noexcept {
}
}
// Pyston addition: same for hcattrs
if (type->attrs_offset && !base->attrs_offset) {
self->getHCAttrsPtr()->clear();
}
/* Extract the type again; tp_del may have changed it */
type = Py_TYPE(self);
......@@ -1110,7 +1115,7 @@ template <Rewritable rewritable> BORROWED(Box*) Box::getattr(BoxedString* attr,
template Box* Box::getattr<REWRITABLE>(BoxedString*, GetattrRewriteArgs*);
template Box* Box::getattr<NOT_REWRITABLE>(BoxedString*, GetattrRewriteArgs*);
void Box::appendNewHCAttr(Box* new_attr, SetattrRewriteArgs* rewrite_args) {
void Box::appendNewHCAttr(BORROWED(Box*) new_attr, SetattrRewriteArgs* rewrite_args) {
Py_INCREF(new_attr);
assert(cls->instancesHaveHCAttrs());
......@@ -1161,7 +1166,7 @@ void Box::giveAttr(BoxedString* attr, Box* val) {
Py_DECREF(attr);
}
void Box::setattr(BoxedString* attr, Box* val, SetattrRewriteArgs* rewrite_args) {
void Box::setattr(BoxedString* attr, BORROWED(Box*) val, SetattrRewriteArgs* rewrite_args) {
assert(attr->interned_state != SSTATE_NOT_INTERNED);
// Have to guard on the memory layout of this object.
......
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