[pypy-commit] cffi default: Simplify this error message

arigo noreply at buildbot.pypy.org
Thu Jul 26 13:00:41 CEST 2012


Author: Armin Rigo <arigo at tunes.org>
Branch: 
Changeset: r682:36da3efc1834
Date: 2012-07-26 12:59 +0200
http://bitbucket.org/cffi/cffi/changeset/36da3efc1834/

Log:	Simplify this error message

diff --git a/c/_cffi_backend.c b/c/_cffi_backend.c
--- a/c/_cffi_backend.c
+++ b/c/_cffi_backend.c
@@ -1648,7 +1648,7 @@
     if (cif_descr != NULL) {
         /* regular case: this function does not take '...' arguments */
         if (nargs != nargs_declared) {
-            errormsg = "%s expects %zd arguments, got %zd";
+            errormsg = "'%s' expects %zd arguments, got %zd";
             goto bad_number_of_arguments;
         }
     }
@@ -1656,7 +1656,7 @@
         /* call of a variadic function */
         ffi_abi fabi;
         if (nargs < nargs_declared) {
-            errormsg = "%s expects at least %zd arguments, got %zd";
+            errormsg = "'%s' expects at least %zd arguments, got %zd";
             goto bad_number_of_arguments;
         }
         fvarargs = PyTuple_New(nargs);
@@ -1784,16 +1784,8 @@
     return res;
 
  bad_number_of_arguments:
-    {
-        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;
-    }
-
+    PyErr_Format(PyExc_TypeError, errormsg,
+                 cd->c_type->ct_name, nargs_declared, nargs);
  error:
     if (buffer)
         PyObject_Free(buffer);
diff --git a/c/test_c.py b/c/test_c.py
--- a/c/test_c.py
+++ b/c/test_c.py
@@ -862,7 +862,7 @@
     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,)
+    assert str(e.value) == "'int(*)(int)' expects 1 arguments, got 0"
 
 def test_callback_return_type():
     for rettype in ["signed char", "short", "int", "long", "long long",


More information about the pypy-commit mailing list