Skip to content

Commit 212bd24

Browse files
committed
Improve CallWrapper
1 parent 649d952 commit 212bd24

File tree

1 file changed

+38
-29
lines changed

1 file changed

+38
-29
lines changed

clingwrapper/src/clingwrapper.cxx

Lines changed: 38 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -879,37 +879,46 @@ void release_args(Parameter* args, size_t nargs) {
879879
// return (!is_direct && wrap->fFaceptr.fGeneric) || (is_direct && wrap->fFaceptr.fDirect);
880880
// }
881881

882-
static inline
883-
bool WrapperCall(Cppyy::TCppMethod_t method, size_t nargs, void* args_, void* self, void* result)
884-
{
885-
Parameter* args = (Parameter*)args_;
886-
bool is_direct = nargs & DIRECT_CALL;
887-
nargs = CALL_NARGS(nargs);
888-
889-
// if (!is_ready(wrap, is_direct))
890-
// return false; // happens with compilation error
891-
892-
if (Cpp::JitCall JC = Cpp::MakeFunctionCallable(method)) {
893-
bool runRelease = false;
894-
//const auto& fgen = /* is_direct ? faceptr.fDirect : */ faceptr;
895-
if (nargs <= SMALL_ARGS_N) {
896-
void* smallbuf[SMALL_ARGS_N];
897-
if (nargs) runRelease = copy_args(args, nargs, smallbuf);
898-
// CLING_CATCH_UNCAUGHT_
899-
JC.Invoke(result, {smallbuf, nargs}, self);
900-
// _CLING_CATCH_UNCAUGHT
901-
} else {
902-
std::vector<void*> buf(nargs);
903-
runRelease = copy_args(args, nargs, buf.data());
904-
// CLING_CATCH_UNCAUGHT_
905-
JC.Invoke(result, {buf.data(), nargs}, self);
906-
// _CLING_CATCH_UNCAUGHT
907-
}
908-
if (runRelease) release_args(args, nargs);
909-
return true;
910-
}
882+
static inline bool WrapperCall(Cppyy::TCppMethod_t method, size_t nargs,
883+
void* args_, void* self, void* result) {
884+
Parameter* args = (Parameter*)args_;
885+
bool is_direct = nargs & DIRECT_CALL;
886+
nargs = CALL_NARGS(nargs);
887+
888+
// if (!is_ready(wrap, is_direct))
889+
// return false; // happens with compilation error
890+
891+
Cpp::JitCall JC = Cpp::MakeFunctionCallable(method);
911892

893+
if (!JC)
912894
return false;
895+
896+
bool runRelease = false;
897+
// const auto& fgen = /* is_direct ? faceptr.fDirect : */ faceptr;
898+
899+
auto invokeHelper = [&](auto invoker) {
900+
if (nargs <= SMALL_ARGS_N) {
901+
void* smallbuf[SMALL_ARGS_N];
902+
if (nargs)
903+
runRelease = copy_args(args, nargs, smallbuf);
904+
// CLING_CATCH_UNCAUGHT_
905+
invoker(smallbuf, nargs);
906+
// _CLING_CATCH_UNCAUGHT
907+
} else {
908+
std::vector<void*> buf(nargs);
909+
runRelease = copy_args(args, nargs, buf.data());
910+
// CLING_CATCH_UNCAUGHT_
911+
invoker(buf.data(), nargs);
912+
// _CLING_CATCH_UNCAUGHT
913+
}
914+
};
915+
916+
invokeHelper(
917+
[&](void** buf, size_t count) { JC.Invoke(result, {buf, count}, self); });
918+
919+
if (runRelease)
920+
release_args(args, nargs);
921+
return true;
913922
}
914923

915924
template<typename T>

0 commit comments

Comments
 (0)