diff options
author | Armin Rigo <armin.rigo@gmail.com> | 2018-04-24 07:54:17 +0000 |
---|---|---|
committer | Armin Rigo <armin.rigo@gmail.com> | 2018-04-24 07:54:17 +0000 |
commit | a1119cf22fda5b1f3cdc51a6883d1a35416036ae (patch) | |
tree | 0b1c385570d59c3d40032020326f5ce2784c7965 | |
parent | 75df01271d44bfc43f98f5ce1b3a667ca581ba47 (diff) | |
parent | 284818f236839d78065a5086e08fab6c6007ee23 (diff) | |
download | cffi-a1119cf22fda5b1f3cdc51a6883d1a35416036ae.tar.gz |
Merged in jdufresne/cffi (pull request #86)
Include license file in the generated wheel package
-rw-r--r-- | c/_cffi_backend.c | 8 | ||||
-rw-r--r-- | c/test_c.py | 6 |
2 files changed, 13 insertions, 1 deletions
diff --git a/c/_cffi_backend.c b/c/_cffi_backend.c index b660867..edacb15 100644 --- a/c/_cffi_backend.c +++ b/c/_cffi_backend.c @@ -1288,7 +1288,13 @@ get_new_array_length(CTypeDescrObject *ctitem, PyObject **pvalue) Py_ssize_t explicitlength; explicitlength = PyNumber_AsSsize_t(value, PyExc_OverflowError); if (explicitlength < 0) { - if (!PyErr_Occurred()) + if (PyErr_Occurred()) { + if (PyErr_ExceptionMatches(PyExc_TypeError)) + PyErr_Format(PyExc_TypeError, + "expected new array length or list/tuple/str, " + "not %.200s", Py_TYPE(value)->tp_name); + } + else PyErr_SetString(PyExc_ValueError, "negative array length"); return -1; } diff --git a/c/test_c.py b/c/test_c.py index caecbec..d5f62c6 100644 --- a/c/test_c.py +++ b/c/test_c.py @@ -289,6 +289,9 @@ def test_pointer_to_int(): assert repr(q).startswith("<cdata 'int *' 0x") assert p == q assert hash(p) == hash(q) + e = py.test.raises(TypeError, newp, new_array_type(BPtr, None), None) + assert str(e.value) == ( + "expected new array length or list/tuple/str, not NoneType") def test_pointer_bool(): BInt = new_primitive_type("int") @@ -370,6 +373,9 @@ def test_reading_pointer_to_char(): assert int(c) == ord(b'A') py.test.raises(TypeError, cast, BChar, b'foo') py.test.raises(TypeError, cast, BChar, u+'foo') + e = py.test.raises(TypeError, newp, new_array_type(BPtr, None), 12.3) + assert str(e.value) == ( + "expected new array length or list/tuple/str, not float") def test_reading_pointer_to_pointer(): BVoidP = new_pointer_type(new_void_type()) |