diff options
author | Armin Rigo <arigo@tunes.org> | 2019-04-02 16:39:56 +0200 |
---|---|---|
committer | Armin Rigo <arigo@tunes.org> | 2019-04-02 16:39:56 +0200 |
commit | f474398bd2ca7eea2fdb7e61ce9d4b8dd1aa7afa (patch) | |
tree | 67f458fdee73c70c07378e06beb14df054030ce6 /c | |
parent | 2746f3611a64a46e91b516ea1bf9c045d9dfcf69 (diff) | |
download | cffi-f474398bd2ca7eea2fdb7e61ce9d4b8dd1aa7afa.tar.gz |
Shut down a warning from recent CPython versions: int() should
always return an int, not a bool
Diffstat (limited to 'c')
-rw-r--r-- | c/_cffi_backend.c | 5 | ||||
-rw-r--r-- | c/test_c.py | 5 |
2 files changed, 9 insertions, 1 deletions
diff --git a/c/_cffi_backend.c b/c/_cffi_backend.c index ac0bc2a..bc7de37 100644 --- a/c/_cffi_backend.c +++ b/c/_cffi_backend.c @@ -2193,7 +2193,10 @@ static PyObject *cdata_int(CDataObject *cd) return PyInt_FromLong(value); } if (cd->c_type->ct_flags & (CT_PRIMITIVE_SIGNED|CT_PRIMITIVE_UNSIGNED)) { - return convert_to_object(cd->c_data, cd->c_type); + PyObject *result = convert_to_object(cd->c_data, cd->c_type); + if (result != NULL && PyBool_Check(result)) + result = PyInt_FromLong(PyInt_AsLong(result)); + return result; } else if (cd->c_type->ct_flags & CT_PRIMITIVE_CHAR) { /*READ(cd->c_data, cd->c_type->ct_size)*/ diff --git a/c/test_c.py b/c/test_c.py index 63b195a..6987f76 100644 --- a/c/test_c.py +++ b/c/test_c.py @@ -4356,3 +4356,8 @@ def test_explicit_release_bytearray_on_cpython(): release(p) # no effect a += b'w' * 1000 assert a == bytearray(b"xyz" + b't' * 10 + b'v' * 100 + b'w' * 1000) + +def test_int_doesnt_give_bool(): + BBool = new_primitive_type("_Bool") + x = int(cast(BBool, 42)) + assert type(x) is int and x == 1 |