diff options
author | Armin Rigo <arigo@tunes.org> | 2017-09-30 08:39:20 +0200 |
---|---|---|
committer | Armin Rigo <arigo@tunes.org> | 2017-09-30 08:39:20 +0200 |
commit | b7ba2fde8896a811736540a594921b670cc1e99d (patch) | |
tree | 66dc5a4d5226fffbaf7d5bf2d0e07af45b61f605 /c/_cffi_backend.c | |
parent | 39d7e026c1daee8f0e7f85181b05524021792025 (diff) | |
download | cffi-b7ba2fde8896a811736540a594921b670cc1e99d.tar.gz |
Turn off the UserWarning when implicitly trying to convert between
"char *" and a pointer to a numeric single-char type.
Diffstat (limited to 'c/_cffi_backend.c')
-rw-r--r-- | c/_cffi_backend.c | 10 |
1 files changed, 8 insertions, 2 deletions
diff --git a/c/_cffi_backend.c b/c/_cffi_backend.c index c6004bb..6451a0c 100644 --- a/c/_cffi_backend.c +++ b/c/_cffi_backend.c @@ -1550,7 +1550,8 @@ convert_from_object(char *data, CTypeDescrObject *ct, PyObject *init) /* for backward compatibility, accept "char *" as either source of target. This is not what C does, though, so emit a warning that will eventually turn into an - error. */ + error. The warning is turned off if both types are + pointers to single bytes. */ char *msg = (ct->ct_flags & CT_IS_VOIDCHAR_PTR ? "implicit cast to 'char *' from a different pointer type: " "will be forbidden in the future (check that the types " @@ -1560,7 +1561,12 @@ convert_from_object(char *data, CTypeDescrObject *ct, PyObject *init) "will be forbidden in the future (check that the types " "are as you expect; use an explicit ffi.cast() if they " "are correct)"); - if (PyErr_WarnEx(PyExc_UserWarning, msg, 1)) + if ((ct->ct_flags & ctinit->ct_flags & CT_POINTER) && + ct->ct_itemdescr->ct_size == 1 && + ctinit->ct_itemdescr->ct_size == 1) { + /* no warning */ + } + else if (PyErr_WarnEx(PyExc_UserWarning, msg, 1)) return -1; } else { |