1. Yury Zaytsev
  2. pypy


Yury Zaytsev  committed 732ce43

CPython C-API compat: PyErr_BadArgument() is of type int and always returns zero

  • Participants
  • Parent commits 5558255
  • Branches default

Comments (0)

Files changed (2)

File pypy/module/cpyext/pyerrors.py

View file
  • Ignore whitespace
     exc_p[0] = make_ref(space, operr.w_type)
     val_p[0] = make_ref(space, operr.get_w_value(space))
-@cpython_api([], lltype.Void)
+@cpython_api([], rffi.INT_real, error=0)
 def PyErr_BadArgument(space):
     """This is a shorthand for PyErr_SetString(PyExc_TypeError, message), where
     message indicates that a built-in operation was invoked with an illegal
-    argument.  It is mostly for internal use."""
+    argument.  It is mostly for internal use. In CPython this function always
+    raises an exception and returns 0 in all cases, hence the (ab)use of the
+    error indicator."""
     raise OperationError(space.w_TypeError,
             space.wrap("bad argument type for built-in operation"))

File pypy/module/cpyext/test/test_pyerrors.py

View file
  • Ignore whitespace
     def test_BadArgument(self, space, api):
-        api.PyErr_BadArgument()
+        ret = api.PyErr_BadArgument()
         state = space.fromcache(State)
         assert space.eq_w(state.operror.w_type, space.w_TypeError)
+        assert ret == 0
     def test_Warning(self, space, api, capfd):