[pypy-commit] pypy nupypy-axis-arg-check: merge default into branch
mattip
noreply at buildbot.pypy.org
Sat Jun 16 22:08:52 CEST 2012
Author: mattip <matti.picus at gmail.com>
Branch: nupypy-axis-arg-check
Changeset: r55698:0eecdf337603
Date: 2012-06-16 20:54 +0300
http://bitbucket.org/pypy/pypy/changeset/0eecdf337603/
Log: merge default into branch
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
@@ -94,4 +94,13 @@
def test_cast_argumenterror(self):
param = c_uint(42)
py.test.raises(ArgumentError, "cast(param, c_void_p)")
-
+
+ def test_c_bool(self):
+ x = c_bool(42)
+ 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
diff --git a/pypy/rpython/lltypesystem/ll2ctypes.py b/pypy/rpython/lltypesystem/ll2ctypes.py
--- a/pypy/rpython/lltypesystem/ll2ctypes.py
+++ b/pypy/rpython/lltypesystem/ll2ctypes.py
@@ -1234,6 +1234,8 @@
# upgrade to a more recent ctypes (e.g. 1.0.2) if you get
# an OverflowError on the following line.
cvalue = ctypes.cast(ctypes.c_void_p(cvalue), cresulttype)
+ elif RESTYPE == lltype.Bool:
+ cvalue = bool(cvalue)
else:
try:
cvalue = cresulttype(cvalue).value # mask high bits off if needed
diff --git a/pypy/translator/c/funcgen.py b/pypy/translator/c/funcgen.py
--- a/pypy/translator/c/funcgen.py
+++ b/pypy/translator/c/funcgen.py
@@ -716,12 +716,14 @@
def OP_CAST_PRIMITIVE(self, op):
TYPE = self.lltypemap(op.result)
val = self.expr(op.args[0])
+ result = self.expr(op.result)
+ if TYPE == Bool:
+ return "%(result)s = !!%(val)s;" % locals()
ORIG = self.lltypemap(op.args[0])
if ORIG is Char:
val = "(unsigned char)%s" % val
elif ORIG is UniChar:
val = "(unsigned long)%s" % val
- result = self.expr(op.result)
typename = cdecl(self.db.gettype(TYPE), '')
return "%(result)s = (%(typename)s)(%(val)s);" % locals()
diff --git a/pypy/translator/c/test/test_typed.py b/pypy/translator/c/test/test_typed.py
--- a/pypy/translator/c/test/test_typed.py
+++ b/pypy/translator/c/test/test_typed.py
@@ -895,3 +895,12 @@
f = self.getcompiled(func, [int])
res = f(-2000000000)
assert res == -200000000000000
+
+ def test_bool_2(self):
+ from pypy.rpython.lltypesystem import lltype, rffi
+ def func(n):
+ x = rffi.cast(lltype.Bool, n)
+ return int(x)
+ f = self.getcompiled(func, [int])
+ res = f(2)
+ assert res == 1 # and not 2
More information about the pypy-commit
mailing list