Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions bindings/pyroot/cppyy/CPyCppyy/src/TemplateProxy.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,12 @@ PyObject* TemplateProxy::Instantiate(const std::string& fname,
} else
PyErr_Clear();

if (!bArgSet && (Py_TYPE(itemi) == &TemplateProxy_Type)) {
TemplateProxy *tp = (TemplateProxy*)itemi;
PyObject *tmpl_name = CPyCppyy_PyText_FromFormat("decltype(%s%s)", tp->fTI->fCppName.c_str(), tp->fTemplateArgs ? CPyCppyy_PyText_AsString(tp->fTemplateArgs) : "");
Comment thread
Vipul-Cariappa marked this conversation as resolved.
PyTuple_SET_ITEM(tpArgs, i, tmpl_name);
bArgSet = true;
}
if (!bArgSet) {
// normal case (may well fail)
PyErr_Clear();
Expand Down
36 changes: 36 additions & 0 deletions bindings/pyroot/cppyy/cppyy/test/test_templates.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import py, pytest, os

Check failure on line 1 in bindings/pyroot/cppyy/cppyy/test/test_templates.py

View workflow job for this annotation

GitHub Actions / ruff

Ruff (F401)

bindings/pyroot/cppyy/cppyy/test/test_templates.py:1:8: F401 `py` imported but unused

Check failure on line 1 in bindings/pyroot/cppyy/cppyy/test/test_templates.py

View workflow job for this annotation

GitHub Actions / ruff

Ruff (E401)

bindings/pyroot/cppyy/cppyy/test/test_templates.py:1:1: E401 Multiple imports on one line
from pytest import mark, raises
from support import setup_make, pylong

Check failure on line 3 in bindings/pyroot/cppyy/cppyy/test/test_templates.py

View workflow job for this annotation

GitHub Actions / ruff

Ruff (F401)

bindings/pyroot/cppyy/cppyy/test/test_templates.py:3:21: F401 `support.setup_make` imported but unused

Check failure on line 3 in bindings/pyroot/cppyy/cppyy/test/test_templates.py

View workflow job for this annotation

GitHub Actions / ruff

Ruff (I001)

bindings/pyroot/cppyy/cppyy/test/test_templates.py:1:1: I001 Import block is un-sorted or un-formatted

Expand Down Expand Up @@ -29,8 +29,8 @@
def test01_template_member_functions(self):
"""Template member functions lookup and calls"""

import cppyy
import sys

Check failure on line 33 in bindings/pyroot/cppyy/cppyy/test/test_templates.py

View workflow job for this annotation

GitHub Actions / ruff

Ruff (I001)

bindings/pyroot/cppyy/cppyy/test/test_templates.py:32:9: I001 Import block is un-sorted or un-formatted

m = cppyy.gbl.MyTemplatedMethodClass()

Expand All @@ -46,7 +46,7 @@
if sys.hexversion >= 0x3000000:
targ = 'long'
else:
targ = long

Check failure on line 49 in bindings/pyroot/cppyy/cppyy/test/test_templates.py

View workflow job for this annotation

GitHub Actions / ruff

Ruff (F821)

bindings/pyroot/cppyy/cppyy/test/test_templates.py:49:20: F821 Undefined name `long`
assert m.get_size[targ]() == m.get_long_size()

import ctypes
Expand Down Expand Up @@ -110,19 +110,19 @@
from cppyy.gbl.std import vector
# float in, float out
ggsr = cppyy.gbl.global_get_some_result['std::vector<float>']
assert type(ggsr(vector['float']([0.5])).m_retval) == float

Check failure on line 113 in bindings/pyroot/cppyy/cppyy/test/test_templates.py

View workflow job for this annotation

GitHub Actions / ruff

Ruff (E721)

bindings/pyroot/cppyy/cppyy/test/test_templates.py:113:16: E721 Use `is` and `is not` for type comparisons, or `isinstance()` for isinstance checks
assert ggsr(vector['float']([0.5])).m_retval == 0.5
# int in, float out
ggsr = cppyy.gbl.global_get_some_result['std::vector<int>']
assert type(ggsr(vector['int']([5])).m_retval) == float

Check failure on line 117 in bindings/pyroot/cppyy/cppyy/test/test_templates.py

View workflow job for this annotation

GitHub Actions / ruff

Ruff (E721)

bindings/pyroot/cppyy/cppyy/test/test_templates.py:117:16: E721 Use `is` and `is not` for type comparisons, or `isinstance()` for isinstance checks
assert ggsr(vector['int']([5])).m_retval == 5.
# float in, int out
ggsr = cppyy.gbl.global_get_some_result['std::vector<float>, int']
assert type(ggsr(vector['float']([0.3])).m_retval) == int

Check failure on line 121 in bindings/pyroot/cppyy/cppyy/test/test_templates.py

View workflow job for this annotation

GitHub Actions / ruff

Ruff (E721)

bindings/pyroot/cppyy/cppyy/test/test_templates.py:121:16: E721 Use `is` and `is not` for type comparisons, or `isinstance()` for isinstance checks
assert ggsr(vector['float']([0.3])).m_retval == 0
# int in, int out
ggsr = cppyy.gbl.global_get_some_result['std::vector<int>, int']
assert type(ggsr(vector['int']([5])).m_retval) == int

Check failure on line 125 in bindings/pyroot/cppyy/cppyy/test/test_templates.py

View workflow job for this annotation

GitHub Actions / ruff

Ruff (E721)

bindings/pyroot/cppyy/cppyy/test/test_templates.py:125:16: E721 Use `is` and `is not` for type comparisons, or `isinstance()` for isinstance checks
assert ggsr(vector['int']([5])).m_retval == 5

def test04_variadic_function(self):
Expand Down Expand Up @@ -1341,5 +1341,41 @@
assert type(e1+e2) == cppyy.gbl.TypeReduction.Expr[int]


class TestTEMPLATED_CALLBACK:
def setup_class(cls):
cls.test_dct = test_dct
import cppyy
cls.templates = cppyy.load_reflection_info(cls.test_dct)

def test01_templated_callbacks(self):
import cppyy
from cppyy.gbl import std

cppyy.cppdef(r"""
bool foo() { return true; }

int bar(int a, int b) { return a + b; }

template <typename T, typename U>
T baz(T a, U b, std::string c) {
return (T)(a + b) + std::stoi(c);
}

template <typename F, typename R, typename... Args>
R returned_callback(F callable, R r, Args... args) {
return callable(r, std::forward<Args>(args)...);
}

template <typename F, typename... Args>
bool callback(F callable, Args&&... args) {
return callable(std::forward<Args>(args)...);
}
""")

assert cppyy.gbl.callback(cppyy.gbl.foo)
assert cppyy.gbl.returned_callback(cppyy.gbl.bar, 1, 1) == 2
assert cppyy.gbl.returned_callback(cppyy.gbl.baz[int, int], 1, 1, std.string("1")) == 3


if __name__ == "__main__":
exit(pytest.main(args=['-sv', '-ra', __file__]))
4 changes: 3 additions & 1 deletion interpreter/cling/lib/Interpreter/LookupHelper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1691,7 +1691,9 @@ namespace cling {
clang::QualType QT = clang::Sema::GetTypeFromParser(Res.get(), &TSI);
QT = QT.getCanonicalType();
{
ExprValueKind VK = VK_PRValue;
// XValue is an object that can be "moved" whereas PRValue is temporary value
// This enables overloads that require the object to be moved
ExprValueKind VK = VK_XValue;
Comment thread
vgvassilev marked this conversation as resolved.
if (QT->getAs<LValueReferenceType>()) {
VK = VK_LValue;
}
Expand Down
Loading