Commits

Armin Rigo committed d0aeec5

More regularily in casts to floats.

  • Participants
  • Parent commits 75c275f

Comments (0)

Files changed (2)

File c/_cffi_backend.c

             }
             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)) {
         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)
         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')
 
         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)