Author: Wim Lavrijsen <[email protected]>
Branch: reflex-support
Changeset: r45781:8e482e29abf4
Date: 2011-07-20 09:18 -0700
http://bitbucket.org/pypy/pypy/changeset/8e482e29abf4/
Log: new fragility tests for better error reporting
diff --git a/pypy/module/cppyy/converter.py b/pypy/module/cppyy/converter.py
--- a/pypy/module/cppyy/converter.py
+++ b/pypy/module/cppyy/converter.py
@@ -142,7 +142,7 @@
self.name = name
def convert_argument(self, space, w_obj, address):
- raise OperationError(space.w_TypeError,
+ raise OperationError(space.w_RuntimeError,
space.wrap('no converter available for type "%s"'
% self.name))
diff --git a/pypy/module/cppyy/executor.py b/pypy/module/cppyy/executor.py
--- a/pypy/module/cppyy/executor.py
+++ b/pypy/module/cppyy/executor.py
@@ -20,7 +20,9 @@
self.name = name
def execute(self, space, w_returntype, func, cppthis, num_args, args):
- raise NotImplementedError
+ rtype =
capi.charp2str_free(capi.c_method_result_type(func.cpptype.handle,
func.method_index))
+ raise OperationError(space.w_NotImplementedError,
+ space.wrap('return type not available or
supported ("%s")' % rtype))
def execute_libffi(self, space, w_returntype, libffifunc, argchain):
from pypy.module.cppyy.interp_cppyy import FastCallNotPossible
diff --git a/pypy/module/cppyy/interp_cppyy.py
b/pypy/module/cppyy/interp_cppyy.py
--- a/pypy/module/cppyy/interp_cppyy.py
+++ b/pypy/module/cppyy/interp_cppyy.py
@@ -7,7 +7,7 @@
from pypy.rpython.lltypesystem import rffi, lltype
-from pypy.rlib import libffi
+from pypy.rlib import libffi, rdynload
from pypy.rlib import jit, debug
from pypy.module.cppyy import converter, executor, helper
@@ -19,7 +19,10 @@
def load_lib(space, name):
# TODO: the following uses a hacked CDLL that won't work on Windows
+ try:
cdll = libffi.CDLL(name, 0x100 | 0x02)
+ except rdynload.DLOpenError, e:
+ raise OperationError(space.w_RuntimeError, space.wrap(str(e)))
return W_CPPLibrary(space, cdll)
load_lib.unwrap_spec = [ObjSpace, str]
@@ -215,8 +218,6 @@
newthis = capi.c_allocate(self.cpptype.handle)
assert lltype.typeOf(newthis) == rffi.VOIDP
try:
- # TODO: this does not work for CINT, as it calls a temp object
- # by value returning method, not placement on newthis ...
CPPMethod.call(self, newthis, None, args_w)
except Exception, e:
capi.c_deallocate(self.cpptype.handle, newthis)
diff --git a/pypy/module/cppyy/test/Makefile b/pypy/module/cppyy/test/Makefile
--- a/pypy/module/cppyy/test/Makefile
+++ b/pypy/module/cppyy/test/Makefile
@@ -1,4 +1,4 @@
-dicts = example01Dict.so datatypesDict.so advancedcppDict.so stltypesDict.so
operatorsDict.so
+dicts = example01Dict.so datatypesDict.so advancedcppDict.so stltypesDict.so
operatorsDict.so fragileDict.so
all : $(dicts)
ROOTSYS := ${ROOTSYS}
diff --git a/pypy/module/cppyy/test/fragile.cxx
b/pypy/module/cppyy/test/fragile.cxx
new file mode 100644
--- /dev/null
+++ b/pypy/module/cppyy/test/fragile.cxx
@@ -0,0 +1,1 @@
+#include "fragile.h"
diff --git a/pypy/module/cppyy/test/fragile.h b/pypy/module/cppyy/test/fragile.h
new file mode 100644
--- /dev/null
+++ b/pypy/module/cppyy/test/fragile.h
@@ -0,0 +1,16 @@
+namespace fragile {
+
+class no_such_class;
+
+class A {
+public:
+ virtual int check() { return (int)'A'; }
+};
+
+class B {
+public:
+ virtual int check() { return (int)'B'; }
+ no_such_class* gime_no_such() { return 0; }
+};
+
+} // namespace fragile
diff --git a/pypy/module/cppyy/test/fragile.xml
b/pypy/module/cppyy/test/fragile.xml
new file mode 100644
--- /dev/null
+++ b/pypy/module/cppyy/test/fragile.xml
@@ -0,0 +1,8 @@
+<lcgdict>
+
+ <namespace name="fragile" />
+
+ <class name="fragile::A" />
+ <class name="fragile::B" />
+
+</lcgdict>
diff --git a/pypy/module/cppyy/test/test_fragile.py
b/pypy/module/cppyy/test/test_fragile.py
new file mode 100644
--- /dev/null
+++ b/pypy/module/cppyy/test/test_fragile.py
@@ -0,0 +1,47 @@
+import py, os, sys
+from pypy.conftest import gettestobjspace
+
+
+currpath = py.path.local(__file__).dirpath()
+shared_lib = str(currpath.join("fragileDict.so"))
+
+space = gettestobjspace(usemodules=['cppyy'])
+
+def setup_module(mod):
+ if sys.platform == 'win32':
+ py.test.skip("win32 not supported so far")
+ err = os.system("cd '%s' && make fragileDict.so" % currpath)
+ if err:
+ raise OSError("'make' failed (see stderr)")
+
+class AppTestSTL:
+ def setup_class(cls):
+ cls.space = space
+ env = os.environ
+ cls.w_shared_lib = space.wrap(shared_lib)
+ cls.w_datatypes = cls.space.appexec([], """():
+ import cppyy
+ return cppyy.load_lib(%r)""" % (shared_lib, ))
+
+ def test01_load_failure(self):
+ """Test failure to load dictionary"""
+
+ import cppyy
+ raises(RuntimeError, cppyy.load_lib, "does_not_exist.so")
+
+ def test02_missing_classes(self):
+ """Test (non-)access to missing classes"""
+
+ import cppyy
+
+ raises(AttributeError, getattr, cppyy.gbl, "no_such_class")
+
+ assert cppyy.gbl.fragile == cppyy.gbl.fragile
+ fragile = cppyy.gbl.fragile
+
+ raises(AttributeError, getattr, fragile, "no_such_class")
+
+ assert fragile.B == fragile.B
+ assert fragile.B().check() == ord('B')
+
+ raises(NotImplementedError, fragile.B().gime_no_such)
diff --git a/pypy/module/cppyy/test/test_zjit.py
b/pypy/module/cppyy/test/test_zjit.py
--- a/pypy/module/cppyy/test/test_zjit.py
+++ b/pypy/module/cppyy/test/test_zjit.py
@@ -38,6 +38,8 @@
w_TypeError = FakeType("TypeError")
w_AttributeError = FakeType("AttributeError")
w_ReferenceError = FakeType("ReferenceError")
+ w_NotImplementedError = FakeType("NotImplementedError")
+ w_RuntimeError = FakeType("RuntimeError")
w_None = None
w_str = FakeType("str")
_______________________________________________
pypy-commit mailing list
[email protected]
http://mail.python.org/mailman/listinfo/pypy-commit