Commit ec8adc6f authored by Kevin Modzelewski's avatar Kevin Modzelewski

More ref fixes

parent abaede1e
...@@ -3372,6 +3372,7 @@ static Box* tppProxyToTpCall(Box* self, CallRewriteArgs* rewrite_args, ArgPassSp ...@@ -3372,6 +3372,7 @@ static Box* tppProxyToTpCall(Box* self, CallRewriteArgs* rewrite_args, ArgPassSp
rewrite_args->out_rtn = rewrite_args->rewriter->call(true, (void*)self->cls->tp_call, rewrite_args->obj, rewrite_args->out_rtn = rewrite_args->rewriter->call(true, (void*)self->cls->tp_call, rewrite_args->obj,
rewrite_args->arg1, rewrite_args->arg2); rewrite_args->arg1, rewrite_args->arg2);
rewrite_args->out_rtn->setType(RefType::OWNED);
if (S == CXX) if (S == CXX)
rewrite_args->rewriter->checkAndThrowCAPIException(rewrite_args->out_rtn); rewrite_args->rewriter->checkAndThrowCAPIException(rewrite_args->out_rtn);
rewrite_args->out_success = true; rewrite_args->out_success = true;
......
...@@ -236,7 +236,6 @@ void ASTInterpreter::setFrameInfo(const FrameInfo* frame_info) { ...@@ -236,7 +236,6 @@ void ASTInterpreter::setFrameInfo(const FrameInfo* frame_info) {
} }
void ASTInterpreter::setGlobals(Box* globals) { void ASTInterpreter::setGlobals(Box* globals) {
assert(0 && "Check refcounting (of callers)");
assert(!this->frame_info.globals); assert(!this->frame_info.globals);
this->frame_info.globals = incref(globals); this->frame_info.globals = incref(globals);
} }
...@@ -892,6 +891,7 @@ Value ASTInterpreter::visit_langPrimitive(AST_LangPrimitive* node) { ...@@ -892,6 +891,7 @@ Value ASTInterpreter::visit_langPrimitive(AST_LangPrimitive* node) {
int level = static_cast<AST_Num*>(node->args[0])->n_int; int level = static_cast<AST_Num*>(node->args[0])->n_int;
Value froms = visit_expr(node->args[1]); Value froms = visit_expr(node->args[1]);
AUTO_DECREF(froms.o);
auto ast_str = ast_cast<AST_Str>(node->args[2]); auto ast_str = ast_cast<AST_Str>(node->args[2]);
assert(ast_str->str_type == AST_Str::STR); assert(ast_str->str_type == AST_Str::STR);
const std::string& module_name = ast_str->str_data; const std::string& module_name = ast_str->str_data;
......
...@@ -493,7 +493,7 @@ Box* delattrFunc(Box* obj, Box* _str) { ...@@ -493,7 +493,7 @@ Box* delattrFunc(Box* obj, Box* _str) {
return None; return None;
} }
static Box* getattrFuncHelper(Box* return_val, Box* obj, BoxedString* str, Box* default_val) noexcept { static Box* getattrFuncHelper(STOLEN(Box*) return_val, Box* obj, BoxedString* str, Box* default_val) noexcept {
assert(PyString_Check(str)); assert(PyString_Check(str));
if (return_val) if (return_val)
...@@ -506,7 +506,7 @@ static Box* getattrFuncHelper(Box* return_val, Box* obj, BoxedString* str, Box* ...@@ -506,7 +506,7 @@ static Box* getattrFuncHelper(Box* return_val, Box* obj, BoxedString* str, Box*
if (default_val) { if (default_val) {
if (exc) if (exc)
PyErr_Clear(); PyErr_Clear();
return default_val; return incref(default_val);
} }
if (!exc) if (!exc)
raiseAttributeErrorCapi(obj, str->s()); raiseAttributeErrorCapi(obj, str->s());
...@@ -527,6 +527,10 @@ Box* getattrFuncInternal(BoxedFunctionBase* func, CallRewriteArgs* rewrite_args, ...@@ -527,6 +527,10 @@ Box* getattrFuncInternal(BoxedFunctionBase* func, CallRewriteArgs* rewrite_args,
Box* _str = arg2; Box* _str = arg2;
Box* default_value = arg3; Box* default_value = arg3;
AUTO_DECREF(obj);
AUTO_DECREF(_str);
AUTO_XDECREF(default_value);
if (rewrite_args) { if (rewrite_args) {
// We need to make sure that the attribute string will be the same. // We need to make sure that the attribute string will be the same.
// Even though the passed string might not be the exact attribute name // Even though the passed string might not be the exact attribute name
...@@ -549,6 +553,7 @@ Box* getattrFuncInternal(BoxedFunctionBase* func, CallRewriteArgs* rewrite_args, ...@@ -549,6 +553,7 @@ Box* getattrFuncInternal(BoxedFunctionBase* func, CallRewriteArgs* rewrite_args,
_str = coerceUnicodeToStr<S>(_str); _str = coerceUnicodeToStr<S>(_str);
if (S == CAPI && !_str) if (S == CAPI && !_str)
return NULL; return NULL;
AUTO_DECREF(_str);
if (!PyString_Check(_str)) { if (!PyString_Check(_str)) {
if (S == CAPI) { if (S == CAPI) {
...@@ -594,8 +599,10 @@ Box* getattrFuncInternal(BoxedFunctionBase* func, CallRewriteArgs* rewrite_args, ...@@ -594,8 +599,10 @@ Box* getattrFuncInternal(BoxedFunctionBase* func, CallRewriteArgs* rewrite_args,
if (rewrite_args) { if (rewrite_args) {
assert(PyString_CHECK_INTERNED(str) == SSTATE_INTERNED_IMMORTAL); assert(PyString_CHECK_INTERNED(str) == SSTATE_INTERNED_IMMORTAL);
RewriterVar* r_str = rewrite_args->rewriter->loadConst((intptr_t)str, Location::forArg(2)); RewriterVar* r_str = rewrite_args->rewriter->loadConst((intptr_t)str, Location::forArg(2));
RewriterVar* final_rtn = rewrite_args->rewriter->call(false, (void*)getattrFuncHelper, r_rtn, RewriterVar* final_rtn
rewrite_args->arg1, r_str, rewrite_args->arg3); = rewrite_args->rewriter->call(false, (void*)getattrFuncHelper, r_rtn, rewrite_args->arg1, r_str,
rewrite_args->arg3)->setType(RefType::OWNED);
r_rtn->refConsumed();
if (S == CXX) if (S == CXX)
rewrite_args->rewriter->checkAndThrowCAPIException(final_rtn); rewrite_args->rewriter->checkAndThrowCAPIException(final_rtn);
......
...@@ -82,7 +82,10 @@ Box* dictCopy(BoxedDict* self) { ...@@ -82,7 +82,10 @@ Box* dictCopy(BoxedDict* self) {
raiseExcHelper(TypeError, "descriptor 'copy' requires a 'dict' object but received a '%s'", getTypeName(self)); raiseExcHelper(TypeError, "descriptor 'copy' requires a 'dict' object but received a '%s'", getTypeName(self));
BoxedDict* r = new BoxedDict(); BoxedDict* r = new BoxedDict();
assert(0 && "check refcounting"); for (auto&& p : self->d) {
Py_INCREF(p.first.value);
Py_INCREF(p.second);
}
r->d = self->d; r->d = self->d;
return r; return r;
} }
......
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