Commit 6d12a868 authored by Kevin Modzelewski's avatar Kevin Modzelewski

More refcounting fixes

Need to make setattr() stealing
parent 714969bc
......@@ -532,8 +532,10 @@ void JitFragmentWriter::emitReturn(RewriterVar* v) {
v->decvref();
}
void JitFragmentWriter::emitSetAttr(AST_expr* node, RewriterVar* obj, BoxedString* s, RewriterVar* attr) {
emitPPCall((void*)setattr, { obj, imm(s), attr }, 2, 512, node)->setType(RefType::OWNED);
void JitFragmentWriter::emitSetAttr(AST_expr* node, RewriterVar* obj, BoxedString* s, STOLEN(RewriterVar*) attr) {
attr->stealRef();
emitPPCall((void*)setattr, { obj, imm(s), attr }, 2, 512, node);
attr->decvref();
}
void JitFragmentWriter::emitSetBlockLocal(InternedString s, STOLEN(RewriterVar*) v) {
......@@ -555,8 +557,10 @@ void JitFragmentWriter::emitSetExcInfo(RewriterVar* type, RewriterVar* value, Re
call(false, (void*)ASTInterpreterJitInterface::setExcInfoHelper, getInterp(), type, value, traceback);
}
void JitFragmentWriter::emitSetGlobal(Box* global, BoxedString* s, RewriterVar* v) {
void JitFragmentWriter::emitSetGlobal(Box* global, BoxedString* s, STOLEN(RewriterVar*) v) {
v->stealRef();
emitPPCall((void*)setGlobal, { imm(global), imm(s), v }, 2, 512);
v->decvref();
}
void JitFragmentWriter::emitSetItem(RewriterVar* target, RewriterVar* slice, RewriterVar* value) {
......
......@@ -257,11 +257,11 @@ public:
void emitRaise0();
void emitRaise3(RewriterVar* arg0, RewriterVar* arg1, RewriterVar* arg2);
void emitReturn(RewriterVar* v);
void emitSetAttr(AST_expr* node, RewriterVar* obj, BoxedString* s, RewriterVar* attr);
void emitSetAttr(AST_expr* node, RewriterVar* obj, BoxedString* s, STOLEN(RewriterVar*) attr);
void emitSetBlockLocal(InternedString s, STOLEN(RewriterVar*) v);
void emitSetCurrentInst(AST_stmt* node);
void emitSetExcInfo(RewriterVar* type, RewriterVar* value, RewriterVar* traceback);
void emitSetGlobal(Box* global, BoxedString* s, RewriterVar* v);
void emitSetGlobal(Box* global, BoxedString* s, STOLEN(RewriterVar*) v);
void emitSetItemName(BoxedString* s, RewriterVar* v);
void emitSetItem(RewriterVar* target, RewriterVar* slice, RewriterVar* value);
void emitSetLocal(InternedString s, int vreg, bool set_closure, STOLEN(RewriterVar*) v);
......
......@@ -659,6 +659,7 @@ public:
void setDict(BoxedDict* d);
// Note, setattr does *not* steal a reference, but it probably should
void setattr(BoxedString* attr, Box* val, SetattrRewriteArgs* rewrite_args);
// giveAttr consumes a reference to val and attr
void giveAttr(const char* attr, Box* val) { giveAttr(internStringMortal(attr), val); }
......
......@@ -1026,6 +1026,8 @@ void Box::setattr(BoxedString* attr, Box* val, SetattrRewriteArgs* rewrite_args)
r_hattrs->getAttr(offset * sizeof(Box*) + offsetof(HCAttrs::AttrList, attrs))
->setType(RefType::OWNED)
->decvref();
// TODO make this stealing
rewrite_args->attrval->incvref();
rewrite_args->attrval->stealRef();
r_hattrs->setAttr(offset * sizeof(Box*) + offsetof(HCAttrs::AttrList, attrs),
rewrite_args->attrval);
......@@ -2544,9 +2546,13 @@ void setattrGeneric(Box* obj, BoxedString* attr, STOLEN(Box*) val, SetattrRewrit
raiseAttributeError(obj, attr->s());
}
if (rewrite_args)
rewrite_args->attrval->stealRef();
obj->setattr(attr, val, rewrite_args);
// TODO: make setattr() stealing
Py_DECREF(val);
if (rewrite_args)
rewrite_args->attrval->decvref();
}
// TODO this should be in type_setattro
......@@ -2573,7 +2579,7 @@ void setattrGeneric(Box* obj, BoxedString* attr, STOLEN(Box*) val, SetattrRewrit
template void setattrGeneric<NOT_REWRITABLE>(Box* obj, BoxedString* attr, Box* val, SetattrRewriteArgs* rewrite_args);
template void setattrGeneric<REWRITABLE>(Box* obj, BoxedString* attr, Box* val, SetattrRewriteArgs* rewrite_args);
extern "C" void setattr(Box* obj, BoxedString* attr, Box* attr_val) {
extern "C" void setattr(Box* obj, BoxedString* attr, STOLEN(Box*) attr_val) {
STAT_TIMER(t0, "us_timer_slowpath_setattr", 10);
static StatCounter slowpath_setattr("slowpath_setattr");
......@@ -4806,6 +4812,7 @@ Box* binopInternal(Box* lhs, Box* rhs, int op_type, bool inplace, BinopRewriteAr
}
return lrtn;
}
Py_DECREF(lrtn);
}
// TODO patch these cases
......@@ -6536,6 +6543,7 @@ Box* getFromGlobals(Box* globals, BoxedString* name) {
extern "C" void setGlobal(Box* globals, BoxedString* name, STOLEN(Box*) value) {
if (globals->cls == attrwrapper_cls) {
assert(0 && "check refcounting");
globals = unwrapAttrWrapper(globals);
RELEASE_ASSERT(globals->cls == module_cls, "%s", globals->cls->tp_name);
}
......
......@@ -55,7 +55,7 @@ extern "C" Box* getattr(Box* obj, BoxedString* attr);
extern "C" Box* getattr_capi(Box* obj, BoxedString* attr) noexcept;
extern "C" Box* getattrMaybeNonstring(Box* obj, Box* attr);
// XXX: testing. this tail-calls in optimized builds so force it to inline for unoptimized as well to get the same behavior.
extern "C" void setattr(Box* obj, BoxedString* attr, Box* attr_val) __attribute__((always_inline));
extern "C" void setattr(Box* obj, BoxedString* attr, STOLEN(Box*) attr_val) __attribute__((always_inline));
extern "C" void setattrMaybeNonstring(Box* obj, Box* attr, Box* attr_val);
extern "C" void delattr(Box* obj, BoxedString* attr);
extern "C" void delattrMaybeNonstring(Box* obj, Box* attr);
......
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