Commit bd1e4b54 authored by Kevin Modzelewski's avatar Kevin Modzelewski

Add some function keep-alives

I think this is more than is necessary but it's so hard to reason about that.
parent 3ee01f02
...@@ -100,6 +100,7 @@ void generatorEntry(BoxedGenerator* g) { ...@@ -100,6 +100,7 @@ void generatorEntry(BoxedGenerator* g) {
// call body of the generator // call body of the generator
BoxedFunctionBase* func = g->function; BoxedFunctionBase* func = g->function;
KEEP_ALIVE(func);
Box** args = g->args ? &g->args->elts[0] : nullptr; Box** args = g->args ? &g->args->elts[0] : nullptr;
auto r = callCLFunc<ExceptionStyle::CXX, NOT_REWRITABLE>(func->md, nullptr, func->md->numReceivedArgs(), auto r = callCLFunc<ExceptionStyle::CXX, NOT_REWRITABLE>(func->md, nullptr, func->md->numReceivedArgs(),
......
...@@ -4490,8 +4490,6 @@ Box* callCLFunc(FunctionMetadata* md, CallRewriteArgs* rewrite_args, int num_out ...@@ -4490,8 +4490,6 @@ Box* callCLFunc(FunctionMetadata* md, CallRewriteArgs* rewrite_args, int num_out
rewrite_args = NULL; rewrite_args = NULL;
} }
assert(0 && "I think this is where the KEEP_ALIVE should go. should also keep the rewritten version alive.");
CompiledFunction* chosen_cf = pickVersion(md, S, num_output_args, oarg1, oarg2, oarg3, oargs); CompiledFunction* chosen_cf = pickVersion(md, S, num_output_args, oarg1, oarg2, oarg3, oargs);
if (!chosen_cf) { if (!chosen_cf) {
...@@ -4664,8 +4662,10 @@ Box* runtimeCallInternal(Box* obj, CallRewriteArgs* rewrite_args, ArgPassSpec ar ...@@ -4664,8 +4662,10 @@ Box* runtimeCallInternal(Box* obj, CallRewriteArgs* rewrite_args, ArgPassSpec ar
if (obj->cls != function_cls && obj->cls != builtin_function_or_method_cls && obj->cls != instancemethod_cls) { if (obj->cls != function_cls && obj->cls != builtin_function_or_method_cls && obj->cls != instancemethod_cls) {
// TODO: maybe eventually runtimeCallInternal should just be the default tpp_call? // TODO: maybe eventually runtimeCallInternal should just be the default tpp_call?
if (obj->cls->tpp_call.get(S)) { if (obj->cls->tpp_call.get(S)) {
KEEP_ALIVE(obj); // CPython doesn't have this, but I think they should
return obj->cls->tpp_call.call<S>(obj, rewrite_args, argspec, arg1, arg2, arg3, args, keyword_names); return obj->cls->tpp_call.call<S>(obj, rewrite_args, argspec, arg1, arg2, arg3, args, keyword_names);
} else if (S == CAPI && obj->cls->tpp_call.get<CXX>()) { } else if (S == CAPI && obj->cls->tpp_call.get<CXX>()) {
KEEP_ALIVE(obj);
try { try {
return obj->cls->tpp_call.call<CXX>(obj, NULL, argspec, arg1, arg2, arg3, args, keyword_names); return obj->cls->tpp_call.call<CXX>(obj, NULL, argspec, arg1, arg2, arg3, args, keyword_names);
} catch (ExcInfo e) { } catch (ExcInfo e) {
...@@ -4673,6 +4673,7 @@ Box* runtimeCallInternal(Box* obj, CallRewriteArgs* rewrite_args, ArgPassSpec ar ...@@ -4673,6 +4673,7 @@ Box* runtimeCallInternal(Box* obj, CallRewriteArgs* rewrite_args, ArgPassSpec ar
return NULL; return NULL;
} }
} else if (S == CXX && obj->cls->tpp_call.get<CAPI>()) { } else if (S == CXX && obj->cls->tpp_call.get<CAPI>()) {
KEEP_ALIVE(obj);
Box* r = obj->cls->tpp_call.call<CAPI>(obj, NULL, argspec, arg1, arg2, arg3, args, keyword_names); Box* r = obj->cls->tpp_call.call<CAPI>(obj, NULL, argspec, arg1, arg2, arg3, args, keyword_names);
if (!r) if (!r)
throwCAPIException(); throwCAPIException();
...@@ -4784,6 +4785,7 @@ Box* runtimeCallInternal(Box* obj, CallRewriteArgs* rewrite_args, ArgPassSpec ar ...@@ -4784,6 +4785,7 @@ Box* runtimeCallInternal(Box* obj, CallRewriteArgs* rewrite_args, ArgPassSpec ar
callable = callFunc<S>; callable = callFunc<S>;
} }
KEEP_ALIVE(f);
Box* res = callable(f, rewrite_args, argspec, arg1, arg2, arg3, args, keyword_names); Box* res = callable(f, rewrite_args, argspec, arg1, arg2, arg3, args, keyword_names);
return res; return res;
} else if (obj->cls == instancemethod_cls) { } else if (obj->cls == instancemethod_cls) {
......
...@@ -626,6 +626,7 @@ static Box* typeCallInternal(BoxedFunctionBase* f, CallRewriteArgs* rewrite_args ...@@ -626,6 +626,7 @@ static Box* typeCallInternal(BoxedFunctionBase* f, CallRewriteArgs* rewrite_args
if (argspec.has_starargs || argspec.num_args == 0) { if (argspec.has_starargs || argspec.num_args == 0) {
// Get callFunc to expand the arguments. // Get callFunc to expand the arguments.
// TODO: update this to use rearrangeArguments instead. // TODO: update this to use rearrangeArguments instead.
KEEP_ALIVE(f);
return callFunc<CXX>(f, rewrite_args, argspec, arg1, arg2, arg3, args, keyword_names); return callFunc<CXX>(f, rewrite_args, argspec, arg1, arg2, arg3, args, keyword_names);
} }
......
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