Author: Wim Lavrijsen <wlavrij...@lbl.gov> Branch: reflex-support Changeset: r62578:071dc7ce6101 Date: 2013-03-20 13:11 -0700 http://bitbucket.org/pypy/pypy/changeset/071dc7ce6101/
Log: o) finalize stl tests o) allow pointers to unknown classes to execute as void* diff --git a/pypy/module/cppyy/executor.py b/pypy/module/cppyy/executor.py --- a/pypy/module/cppyy/executor.py +++ b/pypy/module/cppyy/executor.py @@ -259,7 +259,7 @@ pass # 2) drop '&': by-ref is pretty much the same as by-value, python-wise - if compound and compound[len(compound)-1] == "&": + if compound and compound[len(compound)-1] == '&': # TODO: this does not actually work with Reflex (?) try: return _executors[clean_name](space, None) @@ -273,17 +273,18 @@ # type check for the benefit of the annotator from pypy.module.cppyy.interp_cppyy import W_CPPClass cppclass = space.interp_w(W_CPPClass, cppclass, can_be_None=False) - if compound == "": + if compound == '': return InstanceExecutor(space, cppclass) - elif compound == "*" or compound == "&": + elif compound == '*' or compound == '&': return InstancePtrExecutor(space, cppclass) - elif compound == "**" or compound == "*&": + elif compound == '**' or compound == '*&': return InstancePtrPtrExecutor(space, cppclass) elif capi.c_is_enum(clean_name): return _executors['unsigned int'](space, None) # 4) additional special cases - # ... none for now + if compound == '*': + return _executors['void*'](space, None) # allow at least passing of the pointer # currently used until proper lazy instantiation available in interp_cppyy return FunctionExecutor(space, None) diff --git a/pypy/module/cppyy/pythonify.py b/pypy/module/cppyy/pythonify.py --- a/pypy/module/cppyy/pythonify.py +++ b/pypy/module/cppyy/pythonify.py @@ -318,15 +318,17 @@ # global == and != for its iterators are reflected, which is a hassle ... if not 'vector' in pyclass.__name__[:11] and \ ('begin' in pyclass.__dict__ and 'end' in pyclass.__dict__): - # TODO: check return type of begin() and end() for existence - def __iter__(self): - iter = self.begin() - while iter != self.end(): - yield iter.__deref__() - iter.__preinc__() - iter.destruct() - raise StopIteration - pyclass.__iter__ = __iter__ + if cppyy._scope_byname(pyclass.__name__+'::iterator') or \ + cppyy._scope_byname(pyclass.__name__+'::const_iterator'): + def __iter__(self): + i = self.begin() + while i != self.end(): + yield i.__deref__() + i.__preinc__() + i.destruct() + raise StopIteration + pyclass.__iter__ = __iter__ + # else: rely on numbered iteration # combine __getitem__ and __len__ to make a pythonized __getitem__ if '__getitem__' in pyclass.__dict__ and '__len__' in pyclass.__dict__: diff --git a/pypy/module/cppyy/test/test_fragile.py b/pypy/module/cppyy/test/test_fragile.py --- a/pypy/module/cppyy/test/test_fragile.py +++ b/pypy/module/cppyy/test/test_fragile.py @@ -49,7 +49,7 @@ assert fragile.B == fragile.B assert fragile.B().check() == ord('B') - raises(TypeError, fragile.B().gime_no_such) + raises(AttributeError, getattr, fragile.B().gime_no_such(), "_cpp_proxy") assert fragile.C == fragile.C assert fragile.C().check() == ord('C') 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 @@ -431,8 +431,20 @@ assert a["some string" ] == 'string' assert a[3.1415] == 'double' + def test06_STL_like_class_iterators(self): + """Test the iterator protocol mapping for an STL like class""" -class AppTestSTLMAP: + import cppyy + stl_like_class = cppyy.gbl.stl_like_class + + a = stl_like_class(int)() + for i in a: + pass + + assert i == 3 + + +class AppTestSTLITERATOR: spaceconfig = dict(usemodules=['cppyy', 'itertools']) def setup_class(cls): _______________________________________________ pypy-commit mailing list pypy-commit@python.org http://mail.python.org/mailman/listinfo/pypy-commit