[pypy-svn] r73201 - in pypy/branch/cpython-extension/pypy/module/cpyext: . test
trundle at codespeak.net
trundle at codespeak.net
Wed Mar 31 04:01:44 CEST 2010
Author: trundle
Date: Wed Mar 31 04:01:43 2010
New Revision: 73201
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_SetObject.
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:01:43 2010
@@ -4,11 +4,17 @@
register_container, CANNOT_FAIL
from pypy.module.cpyext.state import State
+ at cpython_api([PyObject, PyObject], lltype.Void)
+def PyErr_SetObject(space, w_type, w_value):
+ """This function is similar to PyErr_SetString() but lets you specify an
+ arbitrary Python object for the "value" of the exception."""
+ state = space.fromcache(State)
+ state.set_exception(w_type, w_value)
+
@cpython_api([PyObject, rffi.CCHARP], lltype.Void)
def PyErr_SetString(space, w_type, message_ptr):
message = rffi.charp2str(message_ptr)
- state = space.fromcache(State)
- state.set_exception(w_type, space.wrap(message))
+ PyErr_SetObject(space, w_type, space.wrap(message))
@cpython_api([], PyObject, borrowed=True)
def PyErr_Occurred(space):
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:01:43 2010
@@ -1560,12 +1560,6 @@
exception state."""
raise NotImplementedError
- at cpython_api([PyObject, PyObject], lltype.Void)
-def PyErr_SetObject(space, type, value):
- """This function is similar to PyErr_SetString() but lets you specify an
- arbitrary Python object for the "value" of the exception."""
- raise NotImplementedError
-
@cpython_api([PyObject, rffi.CCHARP, ...], PyObject)
def PyErr_Format(space, exception, format, ):
"""This function sets the error indicator and returns NULL. exception should be
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:01:43 2010
@@ -1,3 +1,4 @@
+from pypy.module.cpyext.state import State
from pypy.module.cpyext.test.test_api import BaseApiTest
from pypy.module.cpyext.test.test_cpyext import AppTestCpythonExtensionBase
from pypy.rpython.lltypesystem import rffi
@@ -35,6 +36,14 @@
api.PyErr_Clear()
+ def test_SetObject(self, space, api):
+ api.PyErr_SetObject(space.w_ValueError, space.wrap("a value"))
+ assert api.PyErr_Occurred() is space.w_ValueError
+ state = space.fromcache(State)
+ assert space.eq_w(state.exc_value, space.wrap("a value"))
+
+ api.PyErr_Clear()
+
class AppTestFetch(AppTestCpythonExtensionBase):
def test_occurred(self):
module = self.import_extension('foo', [
More information about the Pypy-commit
mailing list