From 5b8dcd1021e571e7948925f2dde6fafa3c57feeb Mon Sep 17 00:00:00 2001 From: Jonas Rembser Date: Thu, 27 Nov 2025 13:06:14 +0100 Subject: [PATCH 1/2] [TPython] Avoid using `std::make_any` in documentation and tests The `std::make_any` helper has a different signature on MSVC, so to be truly platform independent we should not use it. We can use `std::any` directly, at the cost of one extra copy. --- bindings/tpython/src/TPython.cxx | 8 ++++---- bindings/tpython/test/testTPython.cxx | 2 +- bindings/tpython/test/test_tpython.py | 2 +- 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/bindings/tpython/src/TPython.cxx b/bindings/tpython/src/TPython.cxx index 05c55dca5b41c..adb8bb6017de0 100644 --- a/bindings/tpython/src/TPython.cxx +++ b/bindings/tpython/src/TPython.cxx @@ -48,15 +48,15 @@ /// /// // Create a TNamed on the python side, and transfer it back and forth. /// root [1] std::any res1; -/// root [2] TPython::Exec("_anyresult = ROOT.std.make_any['TNamed']('hello', '')", &res1); +/// root [2] TPython::Exec("_anyresult = ROOT.std.any(ROOT.TNamed('hello', ''))", &res1); /// root [3] TPython::Bind(&std::any_cast(res1), "n"); /// root [4] std::any res2; -/// root [5] TPython::Exec("_anyresult = ROOT.std.make_any['TNamed*', 'TNamed*'](n)", &res2); -/// root [6] (&std::any_cast(res1) == std::any_cast(res2)) +/// root [5] TPython::Exec("_anyresult = ROOT.std.any(n)", &res2); +/// root [6] strcmp(std::any_cast(res1).GetName(), std::any_cast(res2).GetName()) == 0 /// (bool) true /// /// // Variables can cross-over by using an `std::any` with a specific name. -/// root [6] TPython::Exec("_anyresult = ROOT.std.make_any['Int_t'](1 + 1)", &res1); +/// root [6] TPython::Exec("_anyresult = ROOT.std.any(1 + 1)", &res1); /// root [7] std::any_cast(res1) /// (int) 2 /// ~~~ diff --git a/bindings/tpython/test/testTPython.cxx b/bindings/tpython/test/testTPython.cxx index 4c0af642471b1..f5e0a43e482a5 100644 --- a/bindings/tpython/test/testTPython.cxx +++ b/bindings/tpython/test/testTPython.cxx @@ -37,6 +37,6 @@ TEST(TPython, ExecMultithreading) // In the end, let's check if the size is correct. std::any len; - TPython::Exec("_anyresult = ROOT.std.make_any['int'](len(arr))", &len); + TPython::Exec("_anyresult = ROOT.std.any(len(arr))", &len); EXPECT_EQ(std::any_cast(len), nThreads); } diff --git a/bindings/tpython/test/test_tpython.py b/bindings/tpython/test/test_tpython.py index 203bf0f375549..62bf58643bf15 100644 --- a/bindings/tpython/test/test_tpython.py +++ b/bindings/tpython/test/test_tpython.py @@ -21,7 +21,7 @@ def test_exec(self): { std::any out; std::stringstream cmd; - cmd << "_anyresult = ROOT.std.make_any['int'](" << nIn << ")"; + cmd << "_anyresult = ROOT.std.any(" << nIn << ")"; TPython::Exec(cmd.str().c_str(), &out); return std::any_cast(out); } From a2f9d67dfcffd061fd0b4710d5095a21c465fbea Mon Sep 17 00:00:00 2001 From: Jonas Rembser Date: Thu, 13 Nov 2025 00:36:21 +0100 Subject: [PATCH 2/2] [CMake] Run TPython C++ test also on Windows --- bindings/tpython/test/CMakeLists.txt | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/bindings/tpython/test/CMakeLists.txt b/bindings/tpython/test/CMakeLists.txt index f56b36306cfa5..7135221f4ff58 100644 --- a/bindings/tpython/test/CMakeLists.txt +++ b/bindings/tpython/test/CMakeLists.txt @@ -17,10 +17,11 @@ else() PYTHONPATH=${ROOTSYS}/lib:$ENV{PYTHONPATH}) endif() +ROOT_ADD_GTEST(testTPython testTPython.cxx LIBRARIES ROOTTPython ENVIRONMENT ${tpython_gtest_env}) + if(NOT MSVC) - # These tests fail on Windows because of a problem with std::any - # input_line_33:7:52: error: address of overloaded function 'make_any' does not match required type 'std::any (int &&)' - # new (ret) (std::any) (((std::any (&)(int &&))std::make_any)((int&&)*(int*)args[0])); - ROOT_ADD_GTEST(testTPython testTPython.cxx LIBRARIES ROOTTPython ENVIRONMENT ${tpython_gtest_env}) + # This test fails on Windows because MSVC’s standard library does not export + # the symbols needed for cling to JIT-compile code involving std::any, + # causing symbol resolution to fail. ROOT_ADD_PYUNITTEST(test_tpython test_tpython.py) endif()