Author: Wim Lavrijsen <[email protected]>
Branch: reflex-support
Changeset: r62414:21201b4d80e9
Date: 2013-03-18 16:20 -0700
http://bitbucket.org/pypy/pypy/changeset/21201b4d80e9/

Log:    o) don't use slice-indexing for STL maps, as it doesn't make any
        sense o) translate (type) str -> std::basic_string for template
        parameters o) propagate OperationError if coming from a non-
        overloaded function

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
@@ -467,9 +467,14 @@
             try:
                 return cppyyfunc.call(cppthis, args_w)
             except OperationError, e:
+                # special case if there's just one function, to prevent 
clogging the error message
+                if len(self.functions) == 1:
+                    raise
                 errmsg += '\n  '+cppyyfunc.signature()+' =>\n'
                 errmsg += '    '+e.errorstr(self.space)
             except Exception, e:
+                # can not special case this for non-overloaded functions as we 
anyway need an
+                # OperationError error down from here
                 errmsg += '\n  '+cppyyfunc.signature()+' =>\n'
                 errmsg += '    Exception: '+str(e)
 
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
@@ -35,7 +35,9 @@
         self._name = name
 
     def _arg_to_str(self, arg):
-        if type(arg) != str:
+        if arg == str:
+            arg = 'std::basic_string<char>'
+        elif type(arg) != str:
             arg = arg.__name__
         return arg
 
@@ -322,7 +324,8 @@
         pyclass.__iter__ = __iter__
 
     # combine __getitem__ and __len__ to make a pythonized __getitem__
-    if '__getitem__' in pyclass.__dict__ and '__len__' in pyclass.__dict__:
+    if not 'std::map' in pyclass.__name__ and\
+            '__getitem__' in pyclass.__dict__ and '__len__' in 
pyclass.__dict__:
         pyclass._getitem__unchecked = pyclass.__getitem__
         if '__setitem__' in pyclass.__dict__ and '__iadd__' in 
pyclass.__dict__:
             pyclass.__getitem__ = python_style_sliceable_getitem
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
@@ -45,8 +45,10 @@
 
     struct _CppyyMapInstances {
 
-        STLTYPE_INSTANTIATION2(map, int,         int, 1);
-        STLTYPE_INSTANTIATION2(map, std::string, int, 2);
+        STLTYPE_INSTANTIATION2(map, int,         int,           1);
+        STLTYPE_INSTANTIATION2(map, std::string, int,           2);
+        STLTYPE_INSTANTIATION2(map, std::string, unsigned int,  3);
+        STLTYPE_INSTANTIATION2(map, std::string, unsigned long, 4);
 
     };
 
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
@@ -342,7 +342,7 @@
         cls.w_N = cls.space.wrap(13)
         cls.w_test_dct  = cls.space.wrap(test_dct)
         cls.w_stlstring = cls.space.appexec([], """():
-            import cppyy, math
+            import cppyy, math, sys
             return cppyy.load_reflection_info(%r)""" % (test_dct, ))
 
     def test01_builtin_map_type(self):
@@ -383,8 +383,6 @@
         a = std.map(std.string, int)()
         for i in range(self.N):
             a[str(i)] = i
-            import pdb
-            pdb.set_trace()
             assert a[str(i)] == i
 
         assert len(a) == self.N
@@ -402,7 +400,7 @@
     def test04_unsignedvalue_typemap_types(self):
         """Test assignability of maps with unsigned value types"""
 
-        import cppyy, math
+        import cppyy, math, sys
         std = cppyy.gbl.std
 
         mui = std.map(str, 'unsigned int')()
@@ -418,8 +416,8 @@
         mul = std.map(str, 'unsigned long')()
         mul['two'] = 2
         assert mul['two'] == 2
-        mul['maxint'] = maxvalue + 3
-        assert mul['maxint'] == maxvalue + 3
+        mul['maxint'] = sys.maxint + 3
+        assert mul['maxint'] == sys.maxint + 3
 
         raises(ValueError, mul.__setitem__, 'minus two', -2)
 
_______________________________________________
pypy-commit mailing list
[email protected]
http://mail.python.org/mailman/listinfo/pypy-commit

Reply via email to