Author: Armin Rigo <[email protected]>
Branch:
Changeset: r818:d0aeec56f5e1
Date: 2012-08-12 18:08 +0200
http://bitbucket.org/cffi/cffi/changeset/d0aeec56f5e1/
Log: More regularily in casts to floats.
diff --git a/c/_cffi_backend.c b/c/_cffi_backend.c
--- a/c/_cffi_backend.c
+++ b/c/_cffi_backend.c
@@ -2305,6 +2305,16 @@
}
value = (unsigned char)PyString_AS_STRING(io)[0];
}
+#if HAVE_WCHAR_H
+ else if (PyUnicode_Check(io)) {
+ wchar_t ordinal;
+ if (_my_PyUnicode_AsSingleWideChar(io, &ordinal) < 0) {
+ Py_DECREF(io);
+ goto cannot_cast;
+ }
+ value = (long)ordinal;
+ }
+#endif
else if ((ct->ct_flags & CT_IS_LONGDOUBLE) &&
CData_Check(io) &&
(((CDataObject *)io)->c_type->ct_flags & CT_IS_LONGDOUBLE)) {
diff --git a/c/test_c.py b/c/test_c.py
--- a/c/test_c.py
+++ b/c/test_c.py
@@ -82,6 +82,8 @@
assert int(cast(p, max + 1)) == min
py.test.raises(TypeError, cast, p, None)
assert long(cast(p, min - 1)) == max
+ assert int(cast(p, b'\x08')) == 8
+ assert int(cast(p, u'\x08')) == 8
for name in ['char', 'short', 'int', 'long', 'long long']:
p = new_primitive_type('unsigned ' + name)
size = sizeof(p)
@@ -91,6 +93,8 @@
assert int(cast(p, -1)) == max
assert int(cast(p, max + 1)) == 0
assert long(cast(p, -1)) == max
+ assert int(cast(p, b'\xFE')) == 254
+ assert int(cast(p, u'\xFE')) == 254
def test_no_float_on_int_types():
p = new_primitive_type('long')
@@ -122,7 +126,8 @@
assert cast(p, -1.1) != cast(p, -1.1)
assert repr(float(cast(p, -0.0))) == '-0.0'
- assert float(cast(p, '\x09')) == 9.0
+ assert float(cast(p, b'\x09')) == 9.0
+ assert float(cast(p, u'\x09')) == 9.0
assert float(cast(p, True)) == 1.0
py.test.raises(TypeError, cast, p, None)
_______________________________________________
pypy-commit mailing list
[email protected]
http://mail.python.org/mailman/listinfo/pypy-commit