[pypy-commit] pypy default: More precise test: can call c_bool(anything). Fix for the whole test.

arigo noreply at buildbot.pypy.org
Fri Jun 15 18:02:58 CEST 2012


Author: Armin Rigo <arigo at tunes.org>
Branch: 
Changeset: r55688:13efcfa19df4
Date: 2012-06-15 17:56 +0200
http://bitbucket.org/pypy/pypy/changeset/13efcfa19df4/

Log:	More precise test: can call c_bool(anything). Fix for the whole
	test.

diff --git a/lib_pypy/_ctypes/primitive.py b/lib_pypy/_ctypes/primitive.py
--- a/lib_pypy/_ctypes/primitive.py
+++ b/lib_pypy/_ctypes/primitive.py
@@ -249,6 +249,13 @@
                 self._buffer[0] = value
             result.value = property(_getvalue, _setvalue)
 
+        elif tp == '?':  # regular bool
+            def _getvalue(self):
+                return bool(self._buffer[0])
+            def _setvalue(self, value):
+                self._buffer[0] = bool(value)
+            result.value = property(_getvalue, _setvalue)
+
         elif tp == 'v': # VARIANT_BOOL type
             def _getvalue(self):
                 return bool(self._buffer[0])
diff --git a/pypy/module/test_lib_pypy/ctypes_tests/test_cast.py b/pypy/module/test_lib_pypy/ctypes_tests/test_cast.py
--- a/pypy/module/test_lib_pypy/ctypes_tests/test_cast.py
+++ b/pypy/module/test_lib_pypy/ctypes_tests/test_cast.py
@@ -100,3 +100,7 @@
         assert x.value is True
         x = c_bool(0.0)
         assert x.value is False
+        x = c_bool("")
+        assert x.value is False
+        x = c_bool(['yadda'])
+        assert x.value is True


More information about the pypy-commit mailing list