Author: Yury V. Zaytsev <[email protected]>
Branch:
Changeset: r67195:732ce43952a5
Date: 2013-10-08 10:12 +0200
http://bitbucket.org/pypy/pypy/changeset/732ce43952a5/
Log: CPython C-API compat: PyErr_BadArgument() is of type int and always
returns zero
diff --git a/pypy/module/cpyext/pyerrors.py b/pypy/module/cpyext/pyerrors.py
--- a/pypy/module/cpyext/pyerrors.py
+++ b/pypy/module/cpyext/pyerrors.py
@@ -103,11 +103,13 @@
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"))
diff --git a/pypy/module/cpyext/test/test_pyerrors.py
b/pypy/module/cpyext/test/test_pyerrors.py
--- a/pypy/module/cpyext/test/test_pyerrors.py
+++ b/pypy/module/cpyext/test/test_pyerrors.py
@@ -70,9 +70,10 @@
api.PyErr_Clear()
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
api.PyErr_Clear()
def test_Warning(self, space, api, capfd):
_______________________________________________
pypy-commit mailing list
[email protected]
https://mail.python.org/mailman/listinfo/pypy-commit