Author: Wim Lavrijsen <[email protected]>
Branch: reflex-support
Changeset: r62673:f2c212b00402
Date: 2013-03-21 18:03 -0700
http://bitbucket.org/pypy/pypy/changeset/f2c212b00402/
Log: support for global templated functions
diff --git a/pypy/module/cppyy/interp_cppyy.py
b/pypy/module/cppyy/interp_cppyy.py
--- a/pypy/module/cppyy/interp_cppyy.py
+++ b/pypy/module/cppyy/interp_cppyy.py
@@ -373,7 +373,7 @@
return "CPPFunction: %s" % self.signature()
-class CPPTemplatedMember(object):
+class CPPTemplatedCall(object):
"""Method dispatcher that first needs to resolve the template instance.
Note that the derivation is from object: the CPPMethod is a data member."""
@@ -383,7 +383,10 @@
def __init__(self, space, templ_args, containing_scope, method_index,
arg_defs, args_required):
self.space = space
self.templ_args = templ_args
- self.method = CPPMethod(space, containing_scope, method_index,
arg_defs, args_required)
+ if capi.c_is_staticmethod(containing_scope, index):
+ self.method = CPPFunction(space, containing_scope, method_index,
arg_defs, args_require)
+ else:
+ self.method = CPPMethod(space, containing_scope, method_index,
arg_defs, args_required)
def call(self, cppthis, args_w):
assert lltype.typeOf(cppthis) == capi.C_OBJECT
@@ -402,7 +405,7 @@
return self.method.signature()
def __repr__(self):
- return "CPPTemplatedMember: %s" % self.signature()
+ return "CPPTemplatedCall: %s" % self.signature()
class CPPConstructor(CPPMethod):
@@ -825,13 +828,13 @@
cppfunction = CPPConstructor(self.space, self, index, arg_defs,
args_required)
if args_required == 0:
self.default_constructor = cppfunction
+ elif capi.c_method_is_template(self, index):
+ templ_args = capi.c_template_args(self, index)
+ cppfunction = CPPTemplatedCall(self.space, templ_args, self,
index, arg_defs, args_required)
elif capi.c_is_staticmethod(self, index):
cppfunction = CPPFunction(self.space, self, index, arg_defs,
args_required)
elif pyname == "__setitem__":
cppfunction = CPPSetItem(self.space, self, index, arg_defs,
args_required)
- elif capi.c_method_is_template(self, index):
- templ_args = capi.c_template_args(self, index)
- cppfunction = CPPTemplatedMember(self.space, templ_args, self,
index, arg_defs, args_required)
else:
cppfunction = CPPMethod(self.space, self, index, arg_defs,
args_required)
return cppfunction
diff --git a/pypy/module/cppyy/test/advancedcpp.h
b/pypy/module/cppyy/test/advancedcpp.h
--- a/pypy/module/cppyy/test/advancedcpp.h
+++ b/pypy/module/cppyy/test/advancedcpp.h
@@ -384,7 +384,7 @@
T my_templated_function(T t) { return t; }
template class my_templated_class<std::vector<float> >;
-template int my_templated_function<int>(int);
+template char my_templated_function<char>(char);
template double my_templated_function<double>(double);
class my_templated_method_class {
diff --git a/pypy/module/cppyy/test/test_advancedcpp.py
b/pypy/module/cppyy/test/test_advancedcpp.py
--- a/pypy/module/cppyy/test/test_advancedcpp.py
+++ b/pypy/module/cppyy/test/test_advancedcpp.py
@@ -567,3 +567,15 @@
assert m.get_size('double')() == m.get_double_size()
assert m.get_size('my_templated_method_class')() == m.get_self_size()
assert m.get_size('my_typedef_t')() == m.get_self_size()
+
+ def test17_template_global_functions(self):
+ """Test template global function lookup and calls"""
+
+ import cppyy
+
+ f = cppyy.gbl.my_templated_function
+
+ assert f('c') == 'c'
+ assert type(f('c')) == type('c')
+ assert f(3.) == 3.
+ assert type(f(4.)) == type(4.)
_______________________________________________
pypy-commit mailing list
[email protected]
http://mail.python.org/mailman/listinfo/pypy-commit