From 0b9c11dd042d85d6e4a5ac5fb8f458d4819b932a Mon Sep 17 00:00:00 2001 From: Aaron Jomy Date: Mon, 3 Aug 2026 17:59:30 +0200 Subject: [PATCH] [sync] Take the three final fork commits ahead of archival --- src/CPyCppyy/src/CPyCppyyModule.cxx | 2 +- src/backend/clingwrapper.cxx | 5 ++++- test/test_templates.py | 15 +++++++++++++++ 3 files changed, 20 insertions(+), 2 deletions(-) diff --git a/src/CPyCppyy/src/CPyCppyyModule.cxx b/src/CPyCppyy/src/CPyCppyyModule.cxx index a6b4441..21b0232 100644 --- a/src/CPyCppyy/src/CPyCppyyModule.cxx +++ b/src/CPyCppyy/src/CPyCppyyModule.cxx @@ -385,7 +385,7 @@ static PyObject* MakeCppTemplateClass(PyObject* /* self */, PyObject* args) if (!scope) { PyErr_Format(PyExc_TypeError, "Template instantiation failed: '%s' with args: '%s\n'", - Cppyy::GetScopedFinalName(cppscope).c_str(), + Cppyy::GetScopedFinalName(tmpl).c_str(), CPyCppyy_PyText_AsString(PyObject_Repr(args))); return nullptr; } diff --git a/src/backend/clingwrapper.cxx b/src/backend/clingwrapper.cxx index ee2644e..4b89dab 100644 --- a/src/backend/clingwrapper.cxx +++ b/src/backend/clingwrapper.cxx @@ -541,7 +541,10 @@ bool Cppyy::AppendTypesSlow(const std::string& name, for (const std::string& candidate : candidates) { std::string var = "__Cppyy_s" + std::to_string(struct_count++); - if (!Cpp::Declare(("__Cppyy_AppendTypesSlow<" + candidate + "> " + var + ";\n").c_str(), /*silent=*/true)) { + // nodebug: with -g the variable's debug info would carry the full DIE + // tree of every template argument (all member declarations included) -- + // a large, uncacheable per-lookup cost on heavyweight types. + if (!Cpp::Declare(("__Cppyy_AppendTypesSlow<" + candidate + "> __attribute__((nodebug)) " + var + ";\n").c_str(), /*silent=*/true)) { TCppType_t varN = Cpp::GetVariableType(Cpp::GetNamed(var.c_str(), /*parent=*/nullptr)); TCppScope_t instance_class = Cpp::GetScopeFromType(varN); diff --git a/test/test_templates.py b/test/test_templates.py index 56d3782..fb88608 100644 --- a/test/test_templates.py +++ b/test/test_templates.py @@ -1334,6 +1334,21 @@ def test39_monkey_patching_template_proxy(self): assert a.m([1, 2, 3]) assert not a.m(42) + def test40_instantiation_failure_error_message(self): + """Rejected instantiation names the template, not garbage""" + + import cppyy + + cppyy.cppdef("namespace errpath { template struct Buf { int tag; }; }") + + # Check that the failed instantiation error message contains the + # correct template name. + with raises(TypeError) as exc: + cppyy.gbl.errpath.Buf["int"] + msg = str(exc.value) + assert "errpath::Buf" in msg + assert "" not in msg + @mark.skipif((IS_MAC and IS_CLING), reason="setup class fails with OS X cling") class TestTEMPLATED_TYPEDEFS: