[pypy-commit] pypy default: Don't raise uncaught RPython-level OSError
arigo
noreply at buildbot.pypy.org
Wed Nov 21 12:23:12 CET 2012
Author: Armin Rigo <arigo at tunes.org>
Branch:
Changeset: r59023:56918b5db6ac
Date: 2012-11-21 12:22 +0100
http://bitbucket.org/pypy/pypy/changeset/56918b5db6ac/
Log: Don't raise uncaught RPython-level OSError
diff --git a/pypy/module/_ffi/interp_funcptr.py b/pypy/module/_ffi/interp_funcptr.py
--- a/pypy/module/_ffi/interp_funcptr.py
+++ b/pypy/module/_ffi/interp_funcptr.py
@@ -9,11 +9,12 @@
#
from pypy.rlib import jit
from pypy.rlib import libffi
-from pypy.rlib.clibffi import get_libc_name, StackCheckError
+from pypy.rlib.clibffi import get_libc_name, StackCheckError, LibFFIError
from pypy.rlib.rdynload import DLOpenError
from pypy.rlib.rarithmetic import intmask, r_uint
from pypy.rlib.objectmodel import we_are_translated
from pypy.module._ffi.type_converter import FromAppLevelConverter, ToAppLevelConverter
+from pypy.module._rawffi.interp_rawffi import got_libffi_error
import os
if os.name == 'nt':
@@ -29,6 +30,8 @@
raise operationerrfmt(
space.w_AttributeError,
"No symbol %s found in library %s", name, CDLL.name)
+ except LibFFIError:
+ raise got_libffi_error(space)
return W_FuncPtr(func, argtypes_w, w_restype)
elif space.isinstance_w(w_name, space.w_int):
@@ -41,6 +44,9 @@
raise operationerrfmt(
space.w_AttributeError,
"No ordinal %d found in library %s", ordinal, CDLL.name)
+ except LibFFIError:
+ raise got_libffi_error(space)
+
return W_FuncPtr(func, argtypes_w, w_restype)
else:
raise OperationError(space.w_TypeError, space.wrap(
@@ -58,6 +64,8 @@
raise operationerrfmt(
space.w_AttributeError,
"No symbol %s found in library %s", name, CDLL.name)
+ except LibFFIError:
+ raise got_libffi_error(space)
return W_FuncPtr(func, argtypes_w, w_restype)
@@ -286,12 +294,11 @@
w_argtypes,
w_restype)
addr = rffi.cast(rffi.VOIDP, addr)
- func = libffi.Func(name, argtypes, restype, addr, flags)
try:
+ func = libffi.Func(name, argtypes, restype, addr, flags)
return W_FuncPtr(func, argtypes_w, w_restype)
- except OSError:
- raise OperationError(space.w_SystemError,
- space.wrap("internal error building the Func object"))
+ except LibFFIError:
+ raise got_libffi_error(space)
W_FuncPtr.typedef = TypeDef(
diff --git a/pypy/module/_rawffi/callback.py b/pypy/module/_rawffi/callback.py
--- a/pypy/module/_rawffi/callback.py
+++ b/pypy/module/_rawffi/callback.py
@@ -5,9 +5,9 @@
from pypy.module._rawffi.array import push_elem
from pypy.module._rawffi.structure import W_Structure
from pypy.module._rawffi.interp_rawffi import (W_DataInstance, letter2tp,
- unwrap_value, unpack_argshapes)
+ unwrap_value, unpack_argshapes, got_libffi_error)
from pypy.rlib.clibffi import USERDATA_P, CallbackFuncPtr, FUNCFLAG_CDECL
-from pypy.rlib.clibffi import ffi_type_void
+from pypy.rlib.clibffi import ffi_type_void, LibFFIError
from pypy.rlib import rweakref
from pypy.module._rawffi.tracker import tracker
from pypy.interpreter.error import OperationError
@@ -66,8 +66,11 @@
self.result = None
ffiresult = ffi_type_void
self.number = global_counter.add(self)
- self.ll_callback = CallbackFuncPtr(ffiargs, ffiresult,
- callback, self.number, flags)
+ try:
+ self.ll_callback = CallbackFuncPtr(ffiargs, ffiresult,
+ callback, self.number, flags)
+ except LibFFIError:
+ raise got_libffi_error(space)
self.ll_buffer = rffi.cast(rffi.VOIDP, self.ll_callback.ll_closure)
if tracker.DO_TRACING:
addr = rffi.cast(lltype.Signed, self.ll_callback.ll_closure)
diff --git a/pypy/module/_rawffi/interp_rawffi.py b/pypy/module/_rawffi/interp_rawffi.py
--- a/pypy/module/_rawffi/interp_rawffi.py
+++ b/pypy/module/_rawffi/interp_rawffi.py
@@ -133,6 +133,11 @@
return [unpack_simple_shape(space, w_arg)
for w_arg in space.unpackiterable(w_argtypes)]
+def got_libffi_error(space):
+ raise OperationError(space.w_SystemError,
+ space.wrap("not supported by libffi"))
+
+
class W_CDLL(Wrappable):
def __init__(self, space, name, cdll):
self.cdll = cdll
@@ -175,6 +180,8 @@
except KeyError:
raise operationerrfmt(space.w_AttributeError,
"No symbol %s found in library %s", name, self.name)
+ except LibFFIError:
+ raise got_libffi_error(space)
elif (_MS_WINDOWS and
space.is_true(space.isinstance(w_name, space.w_int))):
@@ -185,6 +192,8 @@
except KeyError:
raise operationerrfmt(space.w_AttributeError,
"No symbol %d found in library %s", ordinal, self.name)
+ except LibFFIError:
+ raise got_libffi_error(space)
else:
raise OperationError(space.w_TypeError, space.wrap(
"function name must be string or integer"))
@@ -448,8 +457,11 @@
resshape = unpack_resshape(space, w_res)
ffi_args = [shape.get_basic_ffi_type() for shape in argshapes]
ffi_res = resshape.get_basic_ffi_type()
- ptr = RawFuncPtr('???', ffi_args, ffi_res, rffi.cast(rffi.VOIDP, addr),
- flags)
+ try:
+ ptr = RawFuncPtr('???', ffi_args, ffi_res, rffi.cast(rffi.VOIDP, addr),
+ flags)
+ except LibFFIError:
+ raise got_libffi_error(space)
return space.wrap(W_FuncPtr(space, ptr, argshapes, resshape))
W_FuncPtr.typedef = TypeDef(
diff --git a/pypy/rlib/clibffi.py b/pypy/rlib/clibffi.py
--- a/pypy/rlib/clibffi.py
+++ b/pypy/rlib/clibffi.py
@@ -437,6 +437,9 @@
def __init__(self, message):
self.message = message
+class LibFFIError(Exception):
+ pass
+
CHUNK = 4096
CLOSURES = rffi.CArrayPtr(FFI_CLOSUREP.TO)
@@ -513,7 +516,7 @@
rffi.cast(rffi.UINT, argnum), restype,
self.ll_argtypes)
if not res == FFI_OK:
- raise OSError(-1, "Wrong typedef")
+ raise LibFFIError
def __del__(self):
if self.ll_cif:
@@ -543,7 +546,7 @@
ll_callback, rffi.cast(rffi.VOIDP,
self.ll_userdata))
if not res == FFI_OK:
- raise OSError(-1, "Unspecified error calling ffi_prep_closure")
+ raise LibFFIError
def __del__(self):
AbstractFuncPtr.__del__(self)
More information about the pypy-commit
mailing list