Commit c79cce9f authored by Kevin Modzelewski's avatar Kevin Modzelewski

Get assertInitNone working

parent d30d7780
......@@ -632,10 +632,13 @@ static Box* typeCallInternal(BoxedFunctionBase* f, CallRewriteArgs* rewrite_args
}
// For use on __init__ return values
static void assertInitNone(Box* obj) {
if (obj != None) {
raiseExcHelper(TypeError, "__init__() should return None, not '%s'", getTypeName(obj));
static Box* assertInitNone(STOLEN(Box*) rtn, STOLEN(Box*) obj) {
AUTO_DECREF(rtn);
if (rtn != None) {
Py_DECREF(obj);
raiseExcHelper(TypeError, "__init__() should return None, not '%s'", getTypeName(rtn));
}
return obj;
}
static PyObject* cpythonTypeCall(BoxedClass* type, PyObject* args, PyObject* kwds) {
......@@ -1218,7 +1221,12 @@ static Box* typeCallInner(CallRewriteArgs* rewrite_args, ArgPassSpec argspec, Bo
rewrite_args = NULL;
} else {
assert(S == CXX && "this need to be converted");
rewrite_args->rewriter->call(true, (void*)assertInitNone, srewrite_args.out_rtn);
auto new_r_made
= rewrite_args->rewriter->call(true, (void*)assertInitNone, srewrite_args.out_rtn, r_made);
r_made->refConsumed();
new_r_made->setType(RefType::OWNED);
r_made = new_r_made;
srewrite_args.out_rtn->refConsumed();
}
} else {
initrtn = runtimeCallInternal<S, NOT_REWRITABLE>(init_attr, NULL, argspec, made, arg2, arg3, args,
......@@ -1240,7 +1248,8 @@ static Box* typeCallInner(CallRewriteArgs* rewrite_args, ArgPassSpec argspec, Bo
return NULL;
}
} else
assertInitNone(autoDecref(initrtn));
made = assertInitNone(initrtn, made); // assertInitNone is optimized for the rewriter case; this call
// here could be improved if it is an issue.
} else {
// Otherwise, just call tp_init. This will work out well for extension classes, and no worse
// than failing the rewrite for Python non-extension non-functions (when does that happen?).
......
# expected: reffail
# should_error
# As the test filename says, init functions must return None.
# This file tests that; it also makes sure that it gets tested
# when in a patchpoint.
......@@ -12,5 +10,8 @@ class C(object):
# Call it in a loop to make sure that the constructor gets inlined:
for i in xrange(1000):
c = C(i)
print c.n
try:
c = C(i)
print c.n
except Exception as e:
print e
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