Author: Philip Jenvey <[email protected]>
Branch:
Changeset: r65674:29a9e38aedb6
Date: 2013-07-25 16:26 -0700
http://bitbucket.org/pypy/pypy/changeset/29a9e38aedb6/
Log: add a wrap_dlopenerror for consistency's sake
diff --git a/pypy/module/_cffi_backend/libraryobj.py
b/pypy/module/_cffi_backend/libraryobj.py
--- a/pypy/module/_cffi_backend/libraryobj.py
+++ b/pypy/module/_cffi_backend/libraryobj.py
@@ -4,6 +4,7 @@
from pypy.interpreter.error import operationerrfmt
from pypy.interpreter.gateway import interp2app, unwrap_spec
from pypy.interpreter.typedef import TypeDef
+from pypy.module._rawffi.interp_rawffi import wrap_dlopenerror
from rpython.rtyper.lltypesystem import rffi
from rpython.rlib.rdynload import DLLHANDLE, dlopen, dlsym, dlclose,
DLOpenError
@@ -24,9 +25,7 @@
try:
self.handle = dlopen(ll_libname, flags)
except DLOpenError, e:
- raise operationerrfmt(space.w_OSError,
- "cannot load library %s: %s",
- filename, e.msg)
+ raise wrap_dlopenerror(space, e, filename)
self.name = filename
def __del__(self):
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
@@ -14,7 +14,7 @@
from rpython.rlib.rarithmetic import r_uint
from rpython.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
+from pypy.module._rawffi.interp_rawffi import got_libffi_error,
wrap_dlopenerror
import os
if os.name == 'nt':
@@ -324,8 +324,7 @@
try:
self.cdll = libffi.CDLL(name, mode)
except DLOpenError, e:
- raise operationerrfmt(space.w_OSError, '%s: %s', self.name,
- e.msg or 'unspecified error')
+ raise wrap_dlopenerror(space, e, self.name)
def getfunc(self, space, w_name, w_argtypes, w_restype):
return _getfunc(space, self, w_name, w_argtypes, w_restype)
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
@@ -140,6 +140,11 @@
raise OperationError(space.w_SystemError,
space.wrap("not supported by libffi"))
+def wrap_dlopenerror(space, e, filename):
+ msg = e.msg if e.msg else 'unspecified error'
+ return operationerrfmt(space.w_OSError, 'Cannot load library %s: %s',
+ filename, msg)
+
class W_CDLL(W_Root):
def __init__(self, space, name, cdll):
@@ -219,8 +224,7 @@
try:
cdll = CDLL(name)
except DLOpenError, e:
- raise operationerrfmt(space.w_OSError, '%s: %s', name,
- e.msg or 'unspecified error')
+ raise wrap_dlopenerror(space, e, name)
except OSError, e:
raise wrap_oserror(space, e)
return space.wrap(W_CDLL(space, name, cdll))
diff --git a/pypy/module/_rawffi/test/test__rawffi.py
b/pypy/module/_rawffi/test/test__rawffi.py
--- a/pypy/module/_rawffi/test/test__rawffi.py
+++ b/pypy/module/_rawffi/test/test__rawffi.py
@@ -223,7 +223,8 @@
_rawffi.CDLL("xxxxx_this_name_does_not_exist_xxxxx")
except OSError, e:
print e
- assert str(e).startswith("xxxxx_this_name_does_not_exist_xxxxx: ")
+ assert str(e).startswith(
+ "Cannot load library xxxxx_this_name_does_not_exist_xxxxx: ")
else:
raise AssertionError("did not fail??")
_______________________________________________
pypy-commit mailing list
[email protected]
http://mail.python.org/mailman/listinfo/pypy-commit