diff options
author | Armin Rigo <arigo@tunes.org> | 2018-10-11 11:23:35 +0200 |
---|---|---|
committer | Armin Rigo <arigo@tunes.org> | 2018-10-11 11:23:35 +0200 |
commit | 7ff5c9b50467b4b3409e424f75b90edcf8ad4c93 (patch) | |
tree | cfc53ac8121e0848104c2b1e9c98637eb82f3d8f /cffi | |
parent | d501464d7433dc02a46e4697f057cb04e7449a1c (diff) | |
download | cffi-7ff5c9b50467b4b3409e424f75b90edcf8ad4c93.tar.gz |
#389
Warn when using string literals in the cdef() source
Diffstat (limited to 'cffi')
-rw-r--r-- | cffi/cparser.py | 9 |
1 files changed, 9 insertions, 0 deletions
diff --git a/cffi/cparser.py b/cffi/cparser.py index 6a9a8d2..ab2fea5 100644 --- a/cffi/cparser.py +++ b/cffi/cparser.py @@ -137,6 +137,14 @@ def _preprocess_extern_python(csource): parts.append(csource) return ''.join(parts) +def _warn_for_string_literal(csource): + if '"' in csource: + import warnings + warnings.warn("String literal found in cdef() or type source. " + "String literals are ignored here, but you should " + "remove them anyway because some character sequences " + "confuse pre-parsing.") + def _preprocess(csource): # Remove comments. NOTE: this only work because the cdef() section # should not contain any string literal! @@ -148,6 +156,7 @@ def _preprocess(csource): macrovalue = macrovalue.replace('\\\n', '').strip() macros[macroname] = macrovalue csource = _r_define.sub('', csource) + _warn_for_string_literal(csource) # if pycparser.__version__ < '2.14': csource = _workaround_for_old_pycparser(csource) |