Author: Armin Rigo <ar...@tunes.org> Branch: ffi-backend Changeset: r55961:993108db35b8 Date: 2012-07-07 13:00 +0200 http://bitbucket.org/pypy/pypy/changeset/993108db35b8/
Log: Test and fix. diff --git a/pypy/module/_cffi_backend/ctypeobj.py b/pypy/module/_cffi_backend/ctypeobj.py --- a/pypy/module/_cffi_backend/ctypeobj.py +++ b/pypy/module/_cffi_backend/ctypeobj.py @@ -51,10 +51,14 @@ "float() not supported on cdata '%s'", self.name) def convert_to_object(self, cdata): - raise NotImplementedError + space = self.space + raise operationerrfmt(space.w_TypeError, + "cannot return a cdata '%s'", self.name) def convert_from_object(self, cdata, w_ob): - raise NotImplementedError + space = self.space + raise operationerrfmt(space.w_TypeError, + "cannot initialize cdata '%s'", self.name) def _convert_error(self, expected, w_got): space = self.space diff --git a/pypy/module/_cffi_backend/test/_backend_test_c.py b/pypy/module/_cffi_backend/test/_backend_test_c.py --- a/pypy/module/_cffi_backend/test/_backend_test_c.py +++ b/pypy/module/_cffi_backend/test/_backend_test_c.py @@ -858,7 +858,7 @@ def test_a_lot_of_callbacks(): BIGNUM = 10000 - if hasattr(sys, 'pypy_objspaceclass'): BIGNUM = 100 # tests on py.py + if 'PY_DOT_PY' in globals(): BIGNUM = 100 # tests on py.py # BInt = new_primitive_type("int") BFunc = new_function_type((BInt,), BInt, False) @@ -1300,3 +1300,11 @@ p = newp(BArray, 7) assert repr(p) == "<cdata 'int[]' owning 28 bytes>" assert sizeof(p) == 28 + +def test_cannot_dereference_void(): + BVoidP = new_pointer_type(new_void_type()) + p = cast(BVoidP, 123456) + py.test.raises(TypeError, "p[0]") + p = cast(BVoidP, 0) + if 'PY_DOT_PY' in globals(): py.test.skip("NULL crashes early on py.py") + py.test.raises(TypeError, "p[0]") diff --git a/pypy/module/_cffi_backend/test/test_c.py b/pypy/module/_cffi_backend/test/test_c.py --- a/pypy/module/_cffi_backend/test/test_c.py +++ b/pypy/module/_cffi_backend/test/test_c.py @@ -49,6 +49,7 @@ import sys sys.path.append(path) import _all_test_c + _all_test_c.PY_DOT_PY = True _all_test_c.find_and_load_library = func _all_test_c._testfunc = testfunc """) @@ -78,6 +79,7 @@ print >> f, 'class py:' print >> f, ' class test:' print >> f, ' raises = staticmethod(raises)' + print >> f, ' skip = staticmethod(skip)' print >> f, py.path.local(__file__).join('..', '_backend_test_c.py').read() _______________________________________________ pypy-commit mailing list pypy-commit@python.org http://mail.python.org/mailman/listinfo/pypy-commit