[pypy-svn] r74362 - in pypy/trunk/pypy/module/cpyext: . test
afa at codespeak.net
afa at codespeak.net
Tue May 4 19:23:53 CEST 2010
Author: afa
Date: Tue May 4 19:23:51 2010
New Revision: 74362
Modified:
pypy/trunk/pypy/module/cpyext/api.py
pypy/trunk/pypy/module/cpyext/pyerrors.py
pypy/trunk/pypy/module/cpyext/test/test_pyerrors.py
Log:
It's not so difficult to set errno from C code... unskip test
then fix PyErr_SetFromErrno which was completely broken.
Also add a few assertions (len(args) == len(argtypes)) in the generated wrappers
Modified: pypy/trunk/pypy/module/cpyext/api.py
==============================================================================
--- pypy/trunk/pypy/module/cpyext/api.py (original)
+++ pypy/trunk/pypy/module/cpyext/api.py Tue May 4 19:23:51 2010
@@ -178,6 +178,7 @@
from pypy.module.cpyext.pyobject import make_ref, from_ref
newargs = ()
to_decref = []
+ assert len(args) == len(api_function.argtypes)
for i, (ARG, is_wrapped) in types_names_enum_ui:
input_arg = args[i]
if is_PyObject(ARG) and not is_wrapped:
@@ -408,6 +409,7 @@
try:
if not we_are_translated() and DEBUG_WRAPPER:
print >>sys.stderr, callable,
+ assert len(args) == len(callable.api_func.argtypes)
for i, (typ, is_wrapped) in argtypes_enum_ui:
arg = args[i]
if typ is PyObject and is_wrapped:
@@ -817,6 +819,7 @@
def generic_cpy_call(space, func, *args):
boxed_args = ()
to_decref = []
+ assert len(args) == len(FT.ARGS)
for i, ARG in unrolling_arg_types:
arg = args[i]
if ARG is PyObject:
Modified: pypy/trunk/pypy/module/cpyext/pyerrors.py
==============================================================================
--- pypy/trunk/pypy/module/cpyext/pyerrors.py (original)
+++ pypy/trunk/pypy/module/cpyext/pyerrors.py Tue May 4 19:23:51 2010
@@ -1,13 +1,14 @@
import os
from pypy.rpython.lltypesystem import rffi, lltype
-from pypy.interpreter.error import OperationError
+from pypy.interpreter.error import OperationError, wrap_oserror
from pypy.module.cpyext.api import cpython_api, CANNOT_FAIL, CONST_STRING
from pypy.module.exceptions.interp_exceptions import W_RuntimeWarning
from pypy.module.cpyext.pyobject import (
PyObject, PyObjectP, make_ref, Py_DecRef, register_container)
from pypy.module.cpyext.state import State
from pypy.rlib.rposix import get_errno
+from pypy.rlib.rposix import get_errno
@cpython_api([PyObject, PyObject], lltype.Void)
def PyErr_SetObject(space, w_type, w_value):
@@ -77,6 +78,7 @@
state.set_exception(OperationError(w_type, w_value))
Py_DecRef(space, w_type)
Py_DecRef(space, w_value)
+ Py_DecRef(space, w_traceback)
@cpython_api([], lltype.Void)
def PyErr_BadArgument(space):
@@ -114,9 +116,7 @@
Return value: always NULL."""
# XXX Doesn't actually do anything with PyErr_CheckSignals.
errno = get_errno()
- errno_w = space.wrap(errno)
- message_w = space.wrap(os.strerror(errno))
- PyErr_SetObject(space, w_type, errno_w, message_w)
+ raise wrap_oserror(space, OSError(errno, "PyErr_SetFromErrno"))
@cpython_api([], rffi.INT_real, error=-1)
def PyErr_CheckSignals(space):
Modified: pypy/trunk/pypy/module/cpyext/test/test_pyerrors.py
==============================================================================
--- pypy/trunk/pypy/module/cpyext/test/test_pyerrors.py (original)
+++ pypy/trunk/pypy/module/cpyext/test/test_pyerrors.py Tue May 4 19:23:51 2010
@@ -77,11 +77,6 @@
AppTestCpythonExtensionBase.setup_class.im_func(cls)
space = cls.space
- def set_errno(num):
- ll2ctypes.TLS.errno = num
-
- cls.w_set_errno = space.wrap(interp2app(set_errno, unwrap_spec=[int]))
-
def test_occurred(self):
module = self.import_extension('foo', [
("check_error", "METH_NOARGS",
@@ -118,23 +113,21 @@
assert module.check_error()
def test_SetFromErrno(self):
- skip("The test does not set the errno in a way which "
- "untranslated pypy can actually notice")
-
- import errno
+ import errno, os
module = self.import_extension('foo', [
("set_from_errno", "METH_NOARGS",
'''
+ errno = EBADF;
PyErr_SetFromErrno(PyExc_OSError);
return NULL;
'''),
- ])
+ ],
+ prologue="#include <errno.h>")
try:
- self.set_errno(errno.EBADF)
module.set_from_errno()
except OSError, e:
assert e.errno == errno.EBADF
- assert e.message == os.strerror(errno.EBADF)
+ assert e.strerror == os.strerror(errno.EBADF)
More information about the Pypy-commit
mailing list