[pypy-commit] cffi python3-port: hg merge default

arigo noreply at buildbot.pypy.org
Sun Aug 12 18:50:54 CEST 2012


Author: Armin Rigo <arigo at tunes.org>
Branch: python3-port
Changeset: r820:f84ab980729c
Date: 2012-08-12 18:09 +0200
http://bitbucket.org/cffi/cffi/changeset/f84ab980729c/

Log:	hg merge default

diff --git a/c/_cffi_backend.c b/c/_cffi_backend.c
--- a/c/_cffi_backend.c
+++ b/c/_cffi_backend.c
@@ -2398,6 +2398,16 @@
             }
             value = (unsigned char)PyBytes_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
@@ -88,6 +88,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)
@@ -97,6 +99,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')
@@ -128,7 +132,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)
 


More information about the pypy-commit mailing list