Author: Wim Lavrijsen <[email protected]>
Branch: reflex-support
Changeset: r45191:196862f0f5f7
Date: 2011-06-28 13:43 -0700
http://bitbucket.org/pypy/pypy/changeset/196862f0f5f7/
Log: new STL test and allow object to pass by reference
diff --git a/pypy/module/cppyy/converter.py b/pypy/module/cppyy/converter.py
--- a/pypy/module/cppyy/converter.py
+++ b/pypy/module/cppyy/converter.py
@@ -403,7 +403,7 @@
# 5) generalized cases (covers basically all user classes)
cpptype = interp_cppyy.type_byname(space, clean_name)
- if cpptype and compound == "*":
+ if cpptype and (compound == "*" or compound == "&"):
# type check for the benefit of the annotator
from pypy.module.cppyy.interp_cppyy import W_CPPType
cpptype = space.interp_w(W_CPPType, cpptype, can_be_None=False)
diff --git a/pypy/module/cppyy/test/stltypes.h
b/pypy/module/cppyy/test/stltypes.h
--- a/pypy/module/cppyy/test/stltypes.h
+++ b/pypy/module/cppyy/test/stltypes.h
@@ -8,4 +8,14 @@
template class __gnu_cxx::__normal_iterator<TTYPE*, std::STLTYPE< TTYPE > >;
\
template class __gnu_cxx::__normal_iterator<const TTYPE*, std::STLTYPE< TTYPE
> >;
+
+//- basic example class
+class just_a_class {
+public:
+ int m_i;
+};
+
+
+//- explicit instantiations of used types
STLTYPES_EXPLICIT_INSTANTIATION(vector, int)
+STLTYPES_EXPLICIT_INSTANTIATION(vector, just_a_class)
diff --git a/pypy/module/cppyy/test/stltypes.xml
b/pypy/module/cppyy/test/stltypes.xml
--- a/pypy/module/cppyy/test/stltypes.xml
+++ b/pypy/module/cppyy/test/stltypes.xml
@@ -7,4 +7,5 @@
<class pattern="std::_Vector_base<*>::_Vector_impl" />
<class pattern="std::allocator<*>" />
+ <class name="just_a_class" />
</lcgdict>
diff --git a/pypy/module/cppyy/test/test_stltypes.py
b/pypy/module/cppyy/test/test_stltypes.py
--- a/pypy/module/cppyy/test/test_stltypes.py
+++ b/pypy/module/cppyy/test/test_stltypes.py
@@ -24,7 +24,7 @@
import cppyy
return cppyy.load_lib(%r)""" % (shared_lib, ))
- def test1BuiltinTypeVectorType( self ):
+ def test01_builtin_type_vector_type(self):
"""Test access to an std::vector<int>"""
import cppyy
@@ -34,7 +34,7 @@
assert callable(cppyy.gbl.std.vector)
- tv1 = getattr(cppyy.gbl.std,'vector<int>')
+ tv1 = getattr(cppyy.gbl.std, 'vector<int>')
tv2 = cppyy.gbl.std.vector('int')
assert tv1 is tv2
@@ -62,3 +62,45 @@
assert v.size() == self.N
assert len(v) == self.N
v.destruct()
+
+ def test02_user_type_vector_type(self):
+ """Test access to an std::vector<just_a_class>"""
+
+ import cppyy
+
+ assert cppyy.gbl.std is cppyy.gbl.std
+ assert cppyy.gbl.std.vector is cppyy.gbl.std.vector
+
+ assert callable(cppyy.gbl.std.vector)
+
+ tv1 = getattr(cppyy.gbl.std, 'vector<just_a_class>')
+ tv2 = cppyy.gbl.std.vector('just_a_class')
+ tv3 = cppyy.gbl.std.vector(cppyy.gbl.just_a_class)
+
+ assert tv1 is tv2
+ assert tv2 is tv3
+
+ v = tv3()
+ assert hasattr(v, 'size' )
+ assert hasattr(v, 'push_back' )
+ assert hasattr(v, '__getitem__' )
+ assert hasattr(v, 'begin' )
+ assert hasattr(v, 'end' )
+
+ for i in range(self.N):
+ v.push_back(cppyy.gbl.just_a_class())
+ v[i].m_i = i
+ assert v[i].m_i == i
+
+ assert len(v) == self.N
+ v.destruct()
+
+ def test03_empty_vector_type(self):
+ """Test behavior of empty std::vector<int>"""
+
+ import cppyy
+
+ v = cppyy.gbl.std.vector(int)()
+ # for arg in v:
+ # pass
+ v.destruct()
_______________________________________________
pypy-commit mailing list
[email protected]
http://mail.python.org/mailman/listinfo/pypy-commit