Commit 70c8dd5c authored by Kevin Modzelewski's avatar Kevin Modzelewski

Add refcounting to Box::setattr

parent 56a0d0bd
...@@ -1012,8 +1012,6 @@ void Box::setattr(BoxedString* attr, Box* val, SetattrRewriteArgs* rewrite_args) ...@@ -1012,8 +1012,6 @@ void Box::setattr(BoxedString* attr, Box* val, SetattrRewriteArgs* rewrite_args)
Py_DECREF(prev); Py_DECREF(prev);
if (rewrite_args) { if (rewrite_args) {
assert(0 && "check refcounting");
if (cls->attrs_offset < 0) { if (cls->attrs_offset < 0) {
REWRITE_ABORTED(""); REWRITE_ABORTED("");
rewrite_args = NULL; rewrite_args = NULL;
...@@ -1021,6 +1019,8 @@ void Box::setattr(BoxedString* attr, Box* val, SetattrRewriteArgs* rewrite_args) ...@@ -1021,6 +1019,8 @@ void Box::setattr(BoxedString* attr, Box* val, SetattrRewriteArgs* rewrite_args)
RewriterVar* r_hattrs RewriterVar* r_hattrs
= rewrite_args->obj->getAttr(cls->attrs_offset + offsetof(HCAttrs, attr_list), Location::any()); = rewrite_args->obj->getAttr(cls->attrs_offset + offsetof(HCAttrs, attr_list), Location::any());
r_hattrs->getAttr(offset * sizeof(Box*) + offsetof(HCAttrs::AttrList, attrs))->decref();
rewrite_args->attrval->incref();
r_hattrs->setAttr(offset * sizeof(Box*) + offsetof(HCAttrs::AttrList, attrs), r_hattrs->setAttr(offset * sizeof(Box*) + offsetof(HCAttrs::AttrList, attrs),
rewrite_args->attrval); rewrite_args->attrval);
...@@ -6391,6 +6391,7 @@ extern "C" Box* getGlobal(Box* globals, BoxedString* name) { ...@@ -6391,6 +6391,7 @@ extern "C" Box* getGlobal(Box* globals, BoxedString* name) {
rewriter->commitReturning(r_rtn); rewriter->commitReturning(r_rtn);
} }
assert(r->ob_refcnt > 0);
Py_INCREF(r); Py_INCREF(r);
return r; return r;
} }
...@@ -6398,6 +6399,8 @@ extern "C" Box* getGlobal(Box* globals, BoxedString* name) { ...@@ -6398,6 +6399,8 @@ extern "C" Box* getGlobal(Box* globals, BoxedString* name) {
r = m->getattr(name); r = m->getattr(name);
nopatch_getglobal.log(); nopatch_getglobal.log();
if (r) { if (r) {
assert(r->ob_refcnt > 0);
Py_INCREF(r); Py_INCREF(r);
return r; return r;
} }
...@@ -6411,6 +6414,7 @@ extern "C" Box* getGlobal(Box* globals, BoxedString* name) { ...@@ -6411,6 +6414,7 @@ extern "C" Box* getGlobal(Box* globals, BoxedString* name) {
auto it = d->d.find(name); auto it = d->d.find(name);
if (it != d->d.end()) { if (it != d->d.end()) {
assert(it->second->ob_refcnt > 0);
Py_INCREF(it->second); Py_INCREF(it->second);
return it->second; return it->second;
} }
...@@ -6440,6 +6444,7 @@ extern "C" Box* getGlobal(Box* globals, BoxedString* name) { ...@@ -6440,6 +6444,7 @@ extern "C" Box* getGlobal(Box* globals, BoxedString* name) {
rtn = builtins_module->getattr(name); rtn = builtins_module->getattr(name);
} }
assert(rtn->ob_refcnt > 0);
if (rtn) { if (rtn) {
Py_INCREF(rtn); Py_INCREF(rtn);
return rtn; return rtn;
...@@ -6476,6 +6481,8 @@ extern "C" void setGlobal(Box* globals, BoxedString* name, Box* value) { ...@@ -6476,6 +6481,8 @@ extern "C" void setGlobal(Box* globals, BoxedString* name, Box* value) {
} }
if (globals->cls == module_cls) { if (globals->cls == module_cls) {
// Note: in optimized builds, this will be a tail call, which will
// preserve the return address, letting the setattr() call rewrite itself.
setattr(static_cast<BoxedModule*>(globals), name, value); setattr(static_cast<BoxedModule*>(globals), name, value);
} else { } else {
RELEASE_ASSERT(globals->cls == dict_cls, "%s", globals->cls->tp_name); RELEASE_ASSERT(globals->cls == dict_cls, "%s", globals->cls->tp_name);
......
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