[pypy-svn] r79292 - pypy/branch/reflex-support/pypy/module/cppyy

wlav at codespeak.net wlav at codespeak.net
Sat Nov 20 03:25:46 CET 2010


Author: wlav
Date: Sat Nov 20 03:25:43 2010
New Revision: 79292

Modified:
   pypy/branch/reflex-support/pypy/module/cppyy/helper.py
Log:
fixes for rtyper: make sure iterator stop is non-neg

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	Sat Nov 20 03:25:43 2010
@@ -2,24 +2,25 @@
 
 def compound(name):
     name = "".join(rstring.split(name, "const")) # poor man's replace
-    if name[-1] == "]":                          # array type
+    if name.endswith("]"):                       # array type?
         return "[]"
     i = _find_qualifier_index(name)
     return "".join(name[i:].split(" "))
 
 def array_size(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])
+    if name.endswith("]"):                       # array type?
+        idx = name.rfind("[")
+        if 0 < idx:
+            end = len(name)-1                    # len rather than -1 for rpython
+            if 0 < end and (idx+1) < end:        # guarantee non-neg for rpython
+                return int(name[idx+1:end])
     return -1
 
 def _find_qualifier_index(name):
     i = len(name)
-    for i in range(len(name) - 1, -1, -1):
+    # search from the back; note len(name) > 0 (so rtyper can use uint)
+    for i in range(len(name) - 1, 0, -1):
         c = name[i]
         if c.isalnum() or c == ">" or c == "]":
             break
@@ -29,9 +30,8 @@
     assert name.find("const") == -1
     i = _find_qualifier_index(name)
     name = name[:i].strip(' ')
-    if name[-1] == "]":
-        for i in range(len(name) - 1, -1, -1):
-            c = name[i]
-            if c == "[":
-                return name[:i]
+    if name.endswith("]"):                       # array type?
+        idx = name.rfind("[")
+        if 0 < idx:
+            return name[:idx]
     return name



More information about the Pypy-commit mailing list