Skip to content

Commit a77621a

Browse files
committed
Use InvokeConstructor in CallWrapper, adapt to changes in JitCall
1 parent b5e398d commit a77621a

File tree

1 file changed

+45
-29
lines changed

1 file changed

+45
-29
lines changed

clingwrapper/src/clingwrapper.cxx

Lines changed: 45 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -879,37 +879,53 @@ 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+
if (JC.getKind() == Cpp::JitCall::kGenericCall) {
917+
invokeHelper([&](void** buf, size_t count) {
918+
JC.Invoke(result, {buf, count}, self);
919+
});
920+
} else if (JC.getKind() == Cpp::JitCall::kConstructorCall) {
921+
invokeHelper([&](void** buf, size_t count) {
922+
JC.InvokeConstructor(result, 1UL, {buf, count}, self);
923+
});
924+
}
925+
926+
if (runRelease)
927+
release_args(args, nargs);
928+
return true;
913929
}
914930

915931
template<typename T>

0 commit comments

Comments
 (0)