Commit 96bcd8cd authored by Kevin Modzelewski's avatar Kevin Modzelewski

Support CAPI exceptions through this function

Numpy was hitting this a lot

I love optimizing things we haven't approached before.  This small change
improved numpy.test() performance by 20%.
parent da8686b1
...@@ -546,7 +546,8 @@ public: ...@@ -546,7 +546,8 @@ public:
} }
std::tuple<FrameInfo*, ExcInfo, PythonStackExtractor> pause() { std::tuple<FrameInfo*, ExcInfo, PythonStackExtractor> pause() {
t.end(); static StatCounter stat("us_unwind_session");
stat.log(t.end());
return std::make_tuple(std::move(prev_frame_info), std::move(exc_info), std::move(pystack_extractor)); return std::make_tuple(std::move(prev_frame_info), std::move(exc_info), std::move(pystack_extractor));
} }
......
...@@ -1714,15 +1714,6 @@ template <ExceptionStyle S> ...@@ -1714,15 +1714,6 @@ template <ExceptionStyle S>
Box* BoxedCApiFunction::tppCall(Box* _self, CallRewriteArgs* rewrite_args, ArgPassSpec argspec, Box* arg1, Box* arg2, Box* BoxedCApiFunction::tppCall(Box* _self, CallRewriteArgs* rewrite_args, ArgPassSpec argspec, Box* arg1, Box* arg2,
Box* arg3, Box** args, Box* arg3, Box** args,
const std::vector<BoxedString*>* keyword_names) noexcept(S == CAPI) { const std::vector<BoxedString*>* keyword_names) noexcept(S == CAPI) {
if (S == CAPI) {
try {
return tppCall<CXX>(_self, NULL, argspec, arg1, arg2, arg3, args, keyword_names);
} catch (ExcInfo e) {
setCAPIException(e);
return NULL;
}
}
STAT_TIMER(t0, "us_timer_boxedcapifunction__call__", 10); STAT_TIMER(t0, "us_timer_boxedcapifunction__call__", 10);
BoxedCApiFunction* self = static_cast<BoxedCApiFunction*>(_self); BoxedCApiFunction* self = static_cast<BoxedCApiFunction*>(_self);
...@@ -1791,6 +1782,7 @@ Box* BoxedCApiFunction::tppCall(Box* _self, CallRewriteArgs* rewrite_args, ArgPa ...@@ -1791,6 +1782,7 @@ Box* BoxedCApiFunction::tppCall(Box* _self, CallRewriteArgs* rewrite_args, ArgPa
rewrite_args->out_rtn->setType(RefType::OWNED); rewrite_args->out_rtn->setType(RefType::OWNED);
rewrite_args->out_success = true; rewrite_args->out_success = true;
} }
assert(rtn); // This shouldn't throw, otherwise we would need to check the return value
return rtn; return rtn;
} }
// TODO rewrite these cases specially; tp_new_wrapper just slices the args array, // TODO rewrite these cases specially; tp_new_wrapper just slices the args array,
...@@ -1861,18 +1853,20 @@ Box* BoxedCApiFunction::tppCall(Box* _self, CallRewriteArgs* rewrite_args, ArgPa ...@@ -1861,18 +1853,20 @@ Box* BoxedCApiFunction::tppCall(Box* _self, CallRewriteArgs* rewrite_args, ArgPa
} }
if (rewrite_args) { if (rewrite_args) {
rewrite_args->rewriter->checkAndThrowCAPIException(rewrite_args->out_rtn); if (S == CXX)
rewrite_args->rewriter->checkAndThrowCAPIException(rewrite_args->out_rtn);
rewrite_args->out_success = true; rewrite_args->out_success = true;
} }
if (S == CXX && !rtn) if (S == CXX && !rtn)
throwCAPIException(); throwCAPIException();
assert(rtn && "should have set + thrown an exception!");
return rtn; return rtn;
}; };
return rearrangeArgumentsAndCall(paramspec, NULL, self->method_def->ml_name, defaults, rewrite_args, argspec, arg1, return callCXXFromStyle<S>([=]() {
arg2, arg3, args, keyword_names, continuation); return rearrangeArgumentsAndCall(paramspec, NULL, self->method_def->ml_name, defaults, rewrite_args, argspec,
arg1, arg2, arg3, args, keyword_names, continuation);
});
} }
/* extension modules might be compiled with GC support so these /* extension modules might be compiled with GC support so these
......
...@@ -1162,6 +1162,9 @@ static Box* typeCallInner(CallRewriteArgs* rewrite_args, ArgPassSpec argspec, Bo ...@@ -1162,6 +1162,9 @@ static Box* typeCallInner(CallRewriteArgs* rewrite_args, ArgPassSpec argspec, Bo
class InitHelper { class InitHelper {
public: public:
static Box* call(STOLEN(Box*) made, BoxedClass* cls, Box* args, Box* kwargs) noexcept(S == CAPI) { static Box* call(STOLEN(Box*) made, BoxedClass* cls, Box* args, Box* kwargs) noexcept(S == CAPI) {
if (S == CAPI && !made)
return NULL;
if (!isSubclass(made->cls, cls)) if (!isSubclass(made->cls, cls))
return made; return made;
......
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