From 5860dbc04106ab01e24307d2b91bf2577c1d7c5b Mon Sep 17 00:00:00 2001 From: Raphael Isemann Date: Wed, 26 Jul 2017 23:24:57 +0200 Subject: [PATCH] Fix calling variadic functions through TClingCallFunc. The casting of the function to improve lookup didn't took variadic functions into aspect, causing ABI issues when generating the code for calling this function. This correctly appends the annotation for a variadic function to the function type. This fixes the roottest-python-cling-cling test when compiling with icc. --- core/metacling/src/TClingCallFunc.cxx | 2 ++ core/metacling/test/TClingCallFuncTests.cxx | 22 +++++++++++++++++++++ 2 files changed, 24 insertions(+) diff --git a/core/metacling/src/TClingCallFunc.cxx b/core/metacling/src/TClingCallFunc.cxx index 4125d56c09510..6c944724fc86c 100644 --- a/core/metacling/src/TClingCallFunc.cxx +++ b/core/metacling/src/TClingCallFunc.cxx @@ -433,6 +433,8 @@ void TClingCallFunc::make_narg_call(const std::string &return_type, const unsign ROOT::TMetaUtils::GetNormalizedName(arg_type, QT, *fInterp, fNormCtxt); callbuf << arg_type; } + if (FD->isVariadic()) + callbuf << ", ..."; callbuf << ")"; } diff --git a/core/metacling/test/TClingCallFuncTests.cxx b/core/metacling/test/TClingCallFuncTests.cxx index 6acc33f551a40..5765bc34ed676 100644 --- a/core/metacling/test/TClingCallFuncTests.cxx +++ b/core/metacling/test/TClingCallFuncTests.cxx @@ -106,6 +106,28 @@ TEST(TClingCallFunc, FunctionWrapperVoid) gInterpreter->ClassInfo_Delete(GlobalNamespace); } +TEST(TClingCallFunc, FunctionWrapperVariadic) +{ + gInterpreter->Declare(R"cpp( + void FunctionWrapperFuncVariadic(int j, ...) {} + )cpp"); + + ClassInfo_t *GlobalNamespace = gInterpreter->ClassInfo_Factory(""); + CallFunc_t *mc = gInterpreter->CallFunc_Factory(); + long offset = 0; + + gInterpreter->CallFunc_SetFuncProto(mc, GlobalNamespace, "FunctionWrapperFuncVariadic", "int", &offset); + std::string wrapper = gInterpreter->CallFunc_GetWrapperCode(mc); + + ASSERT_TRUE(gInterpreter->Declare(wrapper.c_str())); + // Make sure we didn't forget the ... in the variadic function signature. + ASSERT_TRUE(wrapper.find("((void (&)(int, ...))FunctionWrapperFuncVariadic)") != wrapper.npos); + + // Cleanup + gInterpreter->CallFunc_Delete(mc); + gInterpreter->ClassInfo_Delete(GlobalNamespace); +} + TEST(TClingCallFunc, FunctionWrapperDefaultArg) { gInterpreter->Declare(R"cpp(