Commit 9a717b07 authored by Kevin Modzelewski's avatar Kevin Modzelewski

Allow rewriting some cases even if they always throw

parent f46be79d
...@@ -1412,14 +1412,6 @@ Box* getattrInternalEx(Box* obj, BoxedString* attr, GetattrRewriteArgs* rewrite_ ...@@ -1412,14 +1412,6 @@ Box* getattrInternalEx(Box* obj, BoxedString* attr, GetattrRewriteArgs* rewrite_
Box* r = obj->cls->tp_getattro(obj, attr); Box* r = obj->cls->tp_getattro(obj, attr);
if (!r) {
if (S == CAPI) {
ensureCAPIExceptionSet();
return r;
} else
throwCAPIException();
}
// If attr is immortal, then we are free to write an embedded reference to it. // If attr is immortal, then we are free to write an embedded reference to it.
// Immortal are (unfortunately) common right now, so this is an easy way to get // Immortal are (unfortunately) common right now, so this is an easy way to get
// around the fact that we don't currently scan ICs for GC references, but eventually // around the fact that we don't currently scan ICs for GC references, but eventually
...@@ -1436,6 +1428,15 @@ Box* getattrInternalEx(Box* obj, BoxedString* attr, GetattrRewriteArgs* rewrite_ ...@@ -1436,6 +1428,15 @@ Box* getattrInternalEx(Box* obj, BoxedString* attr, GetattrRewriteArgs* rewrite_
rewrite_args->out_rtn = r_rtn; rewrite_args->out_rtn = r_rtn;
rewrite_args->out_success = true; rewrite_args->out_success = true;
} }
if (!r) {
if (S == CAPI) {
ensureCAPIExceptionSet();
return r;
} else
throwCAPIException();
}
return r; return r;
} }
...@@ -2832,11 +2833,12 @@ Box* _callattrEntry(Box* obj, BoxedString* attr, CallattrFlags flags, Box* arg1, ...@@ -2832,11 +2833,12 @@ Box* _callattrEntry(Box* obj, BoxedString* attr, CallattrFlags flags, Box* arg1,
rewrite_args.args = rewriter->getArg(6); rewrite_args.args = rewriter->getArg(6);
rtn = callattrInternal<S>(obj, attr, scope, &rewrite_args, argspec, arg1, arg2, arg3, args, keyword_names); rtn = callattrInternal<S>(obj, attr, scope, &rewrite_args, argspec, arg1, arg2, arg3, args, keyword_names);
assert(!(S == CAPI && flags.null_on_nonexistent));
if (!rewrite_args.out_success) { if (!rewrite_args.out_success) {
rewriter.reset(NULL); rewriter.reset(NULL);
} else if (rtn) { } else if (rtn) {
rewriter->commitReturning(rewrite_args.out_rtn); rewriter->commitReturning(rewrite_args.out_rtn);
} else if (flags.null_on_nonexistent) { } else if ((S == CAPI && !rtn) || flags.null_on_nonexistent) {
rewriter->commitReturning(rewriter->loadConst(0, rewriter->getReturnDestination())); rewriter->commitReturning(rewriter->loadConst(0, rewriter->getReturnDestination()));
} }
} else { } else {
...@@ -3755,26 +3757,20 @@ Box* runtimeCallInternal(Box* obj, CallRewriteArgs* rewrite_args, ArgPassSpec ar ...@@ -3755,26 +3757,20 @@ Box* runtimeCallInternal(Box* obj, CallRewriteArgs* rewrite_args, ArgPassSpec ar
assert((obj->cls->tp_call == NULL) == (typeLookup(obj->cls, call_str, NULL) == NULL)); assert((obj->cls->tp_call == NULL) == (typeLookup(obj->cls, call_str, NULL) == NULL));
} }
try { if (rewrite_args) {
if (rewrite_args) { rtn = callattrInternal<S>(obj, call_str, CLASS_ONLY, rewrite_args, argspec, arg1, arg2, arg3, args,
rtn = callattrInternal<S>(obj, call_str, CLASS_ONLY, rewrite_args, argspec, arg1, arg2, arg3, args, keyword_names);
keyword_names); } else {
} else { rtn = callattrInternal<S>(obj, call_str, CLASS_ONLY, NULL, argspec, arg1, arg2, arg3, args, keyword_names);
rtn = callattrInternal<S>(obj, call_str, CLASS_ONLY, NULL, argspec, arg1, arg2, arg3, args,
keyword_names);
}
} catch (ExcInfo e) {
if (S == CAPI) {
setCAPIException(e);
return NULL;
} else
throw e;
} }
if (!rtn) { if (!rtn) {
if (S == CAPI) { if (S == CAPI) {
if (!PyErr_Occurred()) if (!PyErr_Occurred()) {
if (rewrite_args)
rewrite_args->out_success = false;
PyErr_Format(TypeError, "'%s' object is not callable", getTypeName(obj)); PyErr_Format(TypeError, "'%s' object is not callable", getTypeName(obj));
}
return NULL; return NULL;
} else } else
raiseExcHelper(TypeError, "'%s' object is not callable", getTypeName(obj)); raiseExcHelper(TypeError, "'%s' object is not callable", getTypeName(obj));
......
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