[pypy-commit] cffi default: Test and fix
arigo
noreply at buildbot.pypy.org
Sat Jul 7 12:51:54 CEST 2012
Author: Armin Rigo <arigo at tunes.org>
Branch:
Changeset: r587:ab5fef220d88
Date: 2012-07-07 12:51 +0200
http://bitbucket.org/cffi/cffi/changeset/ab5fef220d88/
Log: Test and fix
diff --git a/c/_cffi_backend.c b/c/_cffi_backend.c
--- a/c/_cffi_backend.c
+++ b/c/_cffi_backend.c
@@ -1289,7 +1289,7 @@
char *c = _cdata_get_indexed_ptr(cd, key);
/* use 'mp_subscript' instead of 'sq_item' because we don't want
negative indexes to be corrected automatically */
- if (c == NULL)
+ if (c == NULL && PyErr_Occurred())
return NULL;
if (cd->c_type->ct_flags & CT_IS_PTR_TO_OWNED) {
@@ -1308,7 +1308,7 @@
char *c = _cdata_get_indexed_ptr(cd, key);
/* use 'mp_subscript' instead of 'sq_item' because we don't want
negative indexes to be corrected automatically */
- if (c == NULL)
+ if (c == NULL && PyErr_Occurred())
return NULL;
return convert_to_object(c, cd->c_type->ct_itemdescr);
}
@@ -1320,7 +1320,7 @@
CTypeDescrObject *ctitem = cd->c_type->ct_itemdescr;
/* use 'mp_ass_subscript' instead of 'sq_ass_item' because we don't want
negative indexes to be corrected automatically */
- if (c == NULL)
+ if (c == NULL && PyErr_Occurred())
return -1;
return convert_from_object(c, ctitem, v);
}
diff --git a/c/test_c.py b/c/test_c.py
--- a/c/test_c.py
+++ b/c/test_c.py
@@ -1310,3 +1310,10 @@
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)
+ py.test.raises(TypeError, "p[0]")
More information about the pypy-commit
mailing list