[pypy-svn] r15436 - in pypy/dist/pypy/rpython: . test

cfbolz at codespeak.net cfbolz at codespeak.net
Sat Jul 30 21:20:10 CEST 2005


Author: cfbolz
Date: Sat Jul 30 21:20:07 2005
New Revision: 15436

Modified:
   pypy/dist/pypy/rpython/rlist.py
   pypy/dist/pypy/rpython/rstr.py
   pypy/dist/pypy/rpython/test/test_rlist.py
   pypy/dist/pypy/rpython/test/test_rstr.py
Log:
(pedronis, cfbolz):
fixed string and list comparisons to make it not segfault if one of the
compared elements is None (a Null pointer).


Modified: pypy/dist/pypy/rpython/rlist.py
==============================================================================
--- pypy/dist/pypy/rpython/rlist.py	(original)
+++ pypy/dist/pypy/rpython/rlist.py	Sat Jul 30 21:20:07 2005
@@ -579,6 +579,10 @@
 #  Comparison.
 
 def ll_listeq(l1, l2, eqfn):
+    if not l1 and not l2:
+        return True
+    if not l1 or not l2:
+        return False
     len1 = len(l1.items)
     len2 = len(l2.items)
     if len1 != len2:

Modified: pypy/dist/pypy/rpython/rstr.py
==============================================================================
--- pypy/dist/pypy/rpython/rstr.py	(original)
+++ pypy/dist/pypy/rpython/rstr.py	Sat Jul 30 21:20:07 2005
@@ -568,6 +568,10 @@
     return newstr
 
 def ll_strcmp(s1, s2):
+    if not s1 and not s2:
+        return True
+    if not s1 or not s2:
+        return False
     chars1 = s1.chars
     chars2 = s2.chars
     len1 = len(chars1)
@@ -586,6 +590,10 @@
     return len1 - len2
 
 def ll_streq(s1, s2):
+    if not s1 and not s2:
+        return True
+    if not s1 or not s2:
+        return False
     len1 = len(s1.chars)
     len2 = len(s2.chars)
     if len1 != len2:

Modified: pypy/dist/pypy/rpython/test/test_rlist.py
==============================================================================
--- pypy/dist/pypy/rpython/test/test_rlist.py	(original)
+++ pypy/dist/pypy/rpython/test/test_rlist.py	Sat Jul 30 21:20:07 2005
@@ -253,12 +253,13 @@
 
 def test_list_compare():
     def fn(i, j, neg=False):
-        s1 = [[1, 2, 3], [4, 5, 1]]
-        s2 = [[1, 2, 3], [4, 5, 1], [1], [1, 2], [4, 5, 1, 6], [7, 1, 1, 8, 9, 10]]
+        s1 = [[1, 2, 3], [4, 5, 1], None]
+        s2 = [[1, 2, 3], [4, 5, 1], [1], [1, 2], [4, 5, 1, 6],
+              [7, 1, 1, 8, 9, 10], None]
         if neg: return s1[i] != s2[i]
         return s1[i] == s2[j]
-    for i in range(2):
-        for j in range(6):
+    for i in range(3):
+        for j in range(7):
             for case in False, True:
                 res = interpret(fn, [i,j,case])
                 assert res is fn(i, j, case)

Modified: pypy/dist/pypy/rpython/test/test_rstr.py
==============================================================================
--- pypy/dist/pypy/rpython/test/test_rstr.py	(original)
+++ pypy/dist/pypy/rpython/test/test_rstr.py	Sat Jul 30 21:20:07 2005
@@ -124,11 +124,11 @@
 
 def test_str_compare():
     def fn(i, j):
-        s1 = ['one', 'two']
-        s2 = ['one', 'two', 'o', 'on', 'twos', 'foobar']
+        s1 = ['one', 'two', None]
+        s2 = ['one', 'two', 'o', 'on', 'twos', 'foobar', None]
         return s1[i] == s2[j]
-    for i in range(2):
-        for j in range(6):
+    for i in range(3):
+        for j in range(7):
             res = interpret(fn, [i,j])
             assert res is fn(i, j)
 



More information about the Pypy-commit mailing list