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

ac at codespeak.net ac at codespeak.net
Mon May 15 14:31:16 CEST 2006


Author: ac
Date: Mon May 15 14:31:16 2006
New Revision: 27234

Modified:
   pypy/dist/pypy/rpython/rctypes/rchar_p.py
   pypy/dist/pypy/rpython/rctypes/test/test_rchar_p.py
Log:
Fix NULL-ponter dereference.

Modified: pypy/dist/pypy/rpython/rctypes/rchar_p.py
==============================================================================
--- pypy/dist/pypy/rpython/rctypes/rchar_p.py	(original)
+++ pypy/dist/pypy/rpython/rctypes/rchar_p.py	Mon May 15 14:31:16 2006
@@ -115,6 +115,8 @@
     return lltype.direct_arrayitems(s.chars)
 
 def ll_charp2str(p):
+    if not p:
+        return lltype.nullptr(string_repr.lowleveltype.TO)
     length = ll_strlen(p)
     newstr = lltype.malloc(string_repr.lowleveltype.TO, length)
     for i in range(length):

Modified: pypy/dist/pypy/rpython/rctypes/test/test_rchar_p.py
==============================================================================
--- pypy/dist/pypy/rpython/rctypes/test/test_rchar_p.py	(original)
+++ pypy/dist/pypy/rpython/rctypes/test/test_rchar_p.py	Mon May 15 14:31:16 2006
@@ -112,6 +112,11 @@
             assert not c_char_p(None)
         interpret(func, [])
 
+    def test_null_ptr(self):
+        def func():
+            return pointer(c_char_p(None))[0] is None
+        assert interpret(func, [])
+        
     def test_convert_pointers(self):
         from pypy.rpython.rctypes.rchar_p import ll_strlen
         strlen = CFUNCTYPE(c_int, c_char_p)()   # not directly executable!
@@ -155,3 +160,10 @@
         fn = compile(func, [])
         res = fn()
         assert res == "hello"
+
+    def test_null_ptr(self):
+        def func():
+            return pointer(c_char_p(None))[0] is None
+        fn = compile(func, [])
+        assert fn()
+        



More information about the Pypy-commit mailing list