[pypy-svn] r79137 - in pypy/branch/reflex-support/pypy/module/cppyy: . test

wlav at codespeak.net wlav at codespeak.net
Tue Nov 16 00:48:09 CET 2010


Author: wlav
Date: Tue Nov 16 00:48:06 2010
New Revision: 79137

Modified:
   pypy/branch/reflex-support/pypy/module/cppyy/converter.py
   pypy/branch/reflex-support/pypy/module/cppyy/executor.py
   pypy/branch/reflex-support/pypy/module/cppyy/helper.py
   pypy/branch/reflex-support/pypy/module/cppyy/test/test_helper.py
Log:
mods to be rpython compliant

Modified: pypy/branch/reflex-support/pypy/module/cppyy/converter.py
==============================================================================
--- pypy/branch/reflex-support/pypy/module/cppyy/converter.py	(original)
+++ pypy/branch/reflex-support/pypy/module/cppyy/converter.py	Tue Nov 16 00:48:06 2010
@@ -10,13 +10,16 @@
 _converters = {}
 
 class TypeConverter(object):
+    def __init__(self, space, extra=None):
+        pass
+
     def _get_fieldptr(self, space, w_obj, offset):
         obj = space.interpclass_w(space.findattr(w_obj, space.wrap("_cppinstance")))
         return lltype.direct_ptradd(obj.rawobject, offset)
 
     def _is_abstract(self):
         raise NotImplementedError(
-            "abstract base class (actual: %s)" % type(self).__name__)
+            "abstract base class" ) # more detailed part is not rpython: (actual: %s)" % type(self).__name__)
 
     def convert_argument(self, space, w_obj):
         self._is_abstract()
@@ -170,7 +173,7 @@
 
 class ShortPtrConverter(TypeConverter):
     _immutable_ = True
-    def __init__(self, detail=None):
+    def __init__(self, space, detail=None):
         if detail is None:
             import sys
             detail = sys.maxint
@@ -203,7 +206,7 @@
 
 class LongPtrConverter(TypeConverter):
     _immutable_ = True
-    def __init__(self, detail=None):
+    def __init__(self, space, detail=None):
         if detail is None:
             import sys
             detail = sys.maxint
@@ -270,18 +273,19 @@
 
     #   1) full, exact match
     try:
-        return _converters[name]()
-    except KeyError:
+        return _converters[name](space)
+    except KeyError, k:
         pass
 
     #   2) match of decorated, unqualified type
-    compound, detail = helper.compound(name)
+    compound = helper.compound(name)
     clean_name = helper.clean_type(name)
     try:
-        if detail:
-            return _converters[clean_name+compound](detail)
-        return _converters[clean_name+compound]()
-    except KeyError:
+        array_index = helper.array_index(name)
+        if array_index:
+            return _converters[clean_name+compound](space, array_index)
+        return _converters[clean_name+compound](space)
+    except KeyError, k:
         pass
         
     cpptype = interp_cppyy.type_byname(space, clean_name)

Modified: pypy/branch/reflex-support/pypy/module/cppyy/executor.py
==============================================================================
--- pypy/branch/reflex-support/pypy/module/cppyy/executor.py	(original)
+++ pypy/branch/reflex-support/pypy/module/cppyy/executor.py	Tue Nov 16 00:48:06 2010
@@ -75,7 +75,7 @@
     except KeyError:
         pass
 
-    compound, detail = helper.compound(name)
+    compound = helper.compound(name)
     cpptype = interp_cppyy.type_byname(space, helper.clean_type(name))
     if compound == "*":           
         return InstancePtrExecutor(space, cpptype)

Modified: pypy/branch/reflex-support/pypy/module/cppyy/helper.py
==============================================================================
--- pypy/branch/reflex-support/pypy/module/cppyy/helper.py	(original)
+++ pypy/branch/reflex-support/pypy/module/cppyy/helper.py	Tue Nov 16 00:48:06 2010
@@ -2,13 +2,20 @@
 
 def compound(name):
     name = "".join(rstring.split(name, "const")) # poor man's replace
+    if name[-1] == "]":                          # array type
+        return "[]"
     i = _find_qualifier_index(name)
+    return "".join(name[i:].split(" "))
+
+def array_index(name):
+    name = "".join(rstring.split(name, "const")) # poor man's replace
     if name[-1] == "]":                          # array type
+        i = _find_qualifier_index(name)
         for i in range(len(name) - 1, -1, -1):
             c = name[i]
             if c == "[":
-                return "[]", int(name[i+1:-1])
-    return "".join(name[i:].split(" ")), None
+                return int(name[i+1:-1])
+    return 0
 
 def _find_qualifier_index(name):
     i = len(name)

Modified: pypy/branch/reflex-support/pypy/module/cppyy/test/test_helper.py
==============================================================================
--- pypy/branch/reflex-support/pypy/module/cppyy/test/test_helper.py	(original)
+++ pypy/branch/reflex-support/pypy/module/cppyy/test/test_helper.py	Tue Nov 16 00:48:06 2010
@@ -1,10 +1,11 @@
 from pypy.module.cppyy import helper
 
 def test_compound():
-    assert helper.compound("int*") == ("*", None)
-    assert helper.compound("int* const *&") == ("**&", None)
-    assert helper.compound("std::vector<int>*") == ("*", None)
-    assert helper.compound("unsigned long int[5]") == ("[]", 5)
+    assert helper.compound("int*") == "*"
+    assert helper.compound("int* const *&") == "**&"
+    assert helper.compound("std::vector<int>*") == "*"
+    assert helper.compound("unsigned long int[5]") == "[]"
+    assert helper.array_index("unsigned long int[5]") == 5
 
 
 def test_clean_type():



More information about the Pypy-commit mailing list