Author: Brian Kearns <[email protected]>
Branch:
Changeset: r61056:3bca589bc8bd
Date: 2013-02-10 20:44 -0500
http://bitbucket.org/pypy/pypy/changeset/3bca589bc8bd/
Log: test and fix lib_pypy.dbm handling of null characters (patch from
antocuni)
diff --git a/lib_pypy/dbm.py b/lib_pypy/dbm.py
--- a/lib_pypy/dbm.py
+++ b/lib_pypy/dbm.py
@@ -1,4 +1,4 @@
-from ctypes import Structure, c_char_p, c_int, c_void_p, CDLL
+from ctypes import Structure, c_char_p, c_int, c_void_p, CDLL, POINTER, c_char
import ctypes.util
import os, sys
@@ -11,7 +11,7 @@
class datum(Structure):
_fields_ = [
- ('dptr', c_char_p),
+ ('dptr', POINTER(c_char)),
('dsize', c_int),
]
diff --git a/pypy/module/test_lib_pypy/test_dbm_extra.py
b/pypy/module/test_lib_pypy/test_dbm_extra.py
--- a/pypy/module/test_lib_pypy/test_dbm_extra.py
+++ b/pypy/module/test_lib_pypy/test_dbm_extra.py
@@ -6,6 +6,10 @@
except ImportError, e:
py.test.skip(e)
+import sys
+if '__pypy__' not in sys.builtin_module_names:
+ skip("lib_pypy.dbm requires PyPy's ctypes")
+
def test_get():
path = str(udir.join('test_dbm_extra.test_get'))
d = dbm.open(path, 'c')
@@ -48,3 +52,12 @@
def test_extra():
py.test.raises(TypeError, dbm.datum, 123)
py.test.raises(TypeError, dbm.datum, False)
+
+def test_null():
+ db = dbm.open('test', 'c')
+ db['1'] = 'a\x00b'
+ db.close()
+
+ db = dbm.open('test', 'r')
+ assert db['1'] == 'a\x00b'
+ db.close()
_______________________________________________
pypy-commit mailing list
[email protected]
http://mail.python.org/mailman/listinfo/pypy-commit