[pypy-svn] r73203 - in pypy/branch/cpython-extension/pypy/module/cpyext: . test
trundle at codespeak.net
trundle at codespeak.net
Wed Mar 31 04:15:10 CEST 2010
Author: trundle
Date: Wed Mar 31 04:15:08 2010
New Revision: 73203
Modified:
pypy/branch/cpython-extension/pypy/module/cpyext/pyerrors.py
pypy/branch/cpython-extension/pypy/module/cpyext/stubs.py
pypy/branch/cpython-extension/pypy/module/cpyext/test/test_pyerrors.py
Log:
Implement PyErr_ExceptionMatches.
Modified: pypy/branch/cpython-extension/pypy/module/cpyext/pyerrors.py
==============================================================================
--- pypy/branch/cpython-extension/pypy/module/cpyext/pyerrors.py (original)
+++ pypy/branch/cpython-extension/pypy/module/cpyext/pyerrors.py Wed Mar 31 04:15:08 2010
@@ -43,3 +43,11 @@
else:
w_given_type = w_given
return space.exception_match(w_given_type, w_exc)
+
+ at cpython_api([PyObject], rffi.INT_real, error=CANNOT_FAIL)
+def PyErr_ExceptionMatches(space, w_exc):
+ """Equivalent to PyErr_GivenExceptionMatches(PyErr_Occurred(), exc). This
+ should only be called when an exception is actually set; a memory access
+ violation will occur if no exception has been raised."""
+ w_type = PyErr_Occurred(space)
+ return PyErr_GivenExceptionMatches(space, w_type, w_exc)
Modified: pypy/branch/cpython-extension/pypy/module/cpyext/stubs.py
==============================================================================
--- pypy/branch/cpython-extension/pypy/module/cpyext/stubs.py (original)
+++ pypy/branch/cpython-extension/pypy/module/cpyext/stubs.py Wed Mar 31 04:15:08 2010
@@ -1516,13 +1516,6 @@
"""Alias for PyErr_PrintEx(1)."""
raise NotImplementedError
- at cpython_api([PyObject], rffi.INT_real)
-def PyErr_ExceptionMatches(space, exc):
- """Equivalent to PyErr_GivenExceptionMatches(PyErr_Occurred(), exc). This
- should only be called when an exception is actually set; a memory access
- violation will occur if no exception has been raised."""
- raise NotImplementedError
-
@cpython_api([{PyObject**exc}, {PyObject**val}, {PyObject**tb}], lltype.Void)
def PyErr_NormalizeException(space, , , ):
"""Under certain circumstances, the values returned by PyErr_Fetch() below
Modified: pypy/branch/cpython-extension/pypy/module/cpyext/test/test_pyerrors.py
==============================================================================
--- pypy/branch/cpython-extension/pypy/module/cpyext/test/test_pyerrors.py (original)
+++ pypy/branch/cpython-extension/pypy/module/cpyext/test/test_pyerrors.py Wed Mar 31 04:15:08 2010
@@ -27,6 +27,14 @@
exceptions = space.newtuple([space.w_LookupError, space.w_ValueError])
assert exc_matches(space.w_ValueError, exceptions)
+ def test_ExceptionMatches(self, space, api):
+ api.PyErr_SetObject(space.w_ValueError, space.wrap("message"))
+ assert api.PyErr_ExceptionMatches(space.w_Exception)
+ assert api.PyErr_ExceptionMatches(space.w_ValueError)
+ assert not api.PyErr_ExceptionMatches(space.w_TypeError)
+
+ api.PyErr_Clear()
+
def test_Occurred(self, space, api):
assert not api.PyErr_Occurred()
string = rffi.str2charp("spam and eggs")
More information about the Pypy-commit
mailing list