Commits

Armin Rigo committed 8f96dc6 Merge

hg merge default

Comments (0)

Files changed (2)

c/_cffi_backend.c

     else if (cd->c_type->ct_flags & CT_IS_ENUM)
         return convert_to_object(cd->c_data, cd->c_type);
     else
-        return cdata_repr(cd);
+        return Py_TYPE(cd)->tp_repr((PyObject *)cd);
 }
 
 #ifdef HAVE_WCHAR_H
 
  bad_number_of_arguments:
     {
-        PyObject *s = cdata_repr(cd);
-        PyErr_Format(PyExc_TypeError, errormsg,
-                     PyString_AsString(s), nargs_declared, nargs);
+        PyObject *s = Py_TYPE(cd)->tp_repr((PyObject *)cd);
+        if (s != NULL) {
+            PyErr_Format(PyExc_TypeError, errormsg,
+                         PyString_AS_STRING(s), nargs_declared, nargs);
+            Py_DECREF(s);
+        }
         goto error;
     }
 
     py.test.raises(TypeError, "p[0]")
 
 def test_default_str():
-    p = new_primitive_type("int")
-    x = cast(p, 42)
+    BInt = new_primitive_type("int")
+    x = cast(BInt, 42)
+    assert str(x) == repr(x)
+    BArray = new_array_type(new_pointer_type(BInt), 10)
+    x = newp(BArray, None)
     assert str(x) == repr(x)
 
 def test_cast_from_cdataint():
     assert f(-142) == -141
     assert repr(f).startswith(
         "<cdata 'int(*)(int)' calling <function cb at 0x")
+    e = py.test.raises(TypeError, f)
+    assert str(e.value) == "%r expects 1 arguments, got 0" % (f,)
 
 def test_callback_return_type():
     for rettype in ["signed char", "short", "int", "long", "long long",