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 ...@@ -632,10 +632,13 @@ static Box* typeCallInternal(BoxedFunctionBase* f, CallRewriteArgs* rewrite_args
} }
// For use on __init__ return values // For use on __init__ return values
static void assertInitNone(Box* obj) { static Box* assertInitNone(STOLEN(Box*) rtn, STOLEN(Box*) obj) {
if (obj != None) { AUTO_DECREF(rtn);
raiseExcHelper(TypeError, "__init__() should return None, not '%s'", getTypeName(obj)); 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) { static PyObject* cpythonTypeCall(BoxedClass* type, PyObject* args, PyObject* kwds) {
...@@ -1218,7 +1221,12 @@ static Box* typeCallInner(CallRewriteArgs* rewrite_args, ArgPassSpec argspec, Bo ...@@ -1218,7 +1221,12 @@ static Box* typeCallInner(CallRewriteArgs* rewrite_args, ArgPassSpec argspec, Bo
rewrite_args = NULL; rewrite_args = NULL;
} else { } else {
assert(S == CXX && "this need to be converted"); 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 { } else {
initrtn = runtimeCallInternal<S, NOT_REWRITABLE>(init_attr, NULL, argspec, made, arg2, arg3, args, 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 ...@@ -1240,7 +1248,8 @@ static Box* typeCallInner(CallRewriteArgs* rewrite_args, ArgPassSpec argspec, Bo
return NULL; return NULL;
} }
} else } 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 { } else {
// Otherwise, just call tp_init. This will work out well for extension classes, and no worse // 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?). // 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. # As the test filename says, init functions must return None.
# This file tests that; it also makes sure that it gets tested # This file tests that; it also makes sure that it gets tested
# when in a patchpoint. # when in a patchpoint.
...@@ -12,5 +10,8 @@ class C(object): ...@@ -12,5 +10,8 @@ class C(object):
# Call it in a loop to make sure that the constructor gets inlined: # Call it in a loop to make sure that the constructor gets inlined:
for i in xrange(1000): for i in xrange(1000):
try:
c = C(i) c = C(i)
print c.n 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