diff options
author | Armin Rigo <arigo@tunes.org> | 2017-05-09 18:07:19 +0200 |
---|---|---|
committer | Armin Rigo <arigo@tunes.org> | 2017-05-09 18:07:19 +0200 |
commit | a780b6772eeced3b5b57e313a5b9cf394f722f9e (patch) | |
tree | 4de3378c8d0bbf6d09db4f3aab898e8a65c6b58a /cffi/cparser.py | |
parent | b274305dc3a28495b12ac25430fbad9d66ba40d0 (diff) | |
download | cffi-a780b6772eeced3b5b57e313a5b9cf394f722f9e.tar.gz |
Try to systematically include the line number
Diffstat (limited to 'cffi/cparser.py')
-rw-r--r-- | cffi/cparser.py | 15 |
1 files changed, 12 insertions, 3 deletions
diff --git a/cffi/cparser.py b/cffi/cparser.py index 1c90d80..f7e2e35 100644 --- a/cffi/cparser.py +++ b/cffi/cparser.py @@ -16,6 +16,7 @@ try: except ImportError: lock = None +CDEF_SOURCE_STRING = "<cdef source string>" _r_comment = re.compile(r"/\*.*?\*/|//([^\n\\]|\\.)*?$", re.DOTALL | re.MULTILINE) _r_define = re.compile(r"^\s*#\s*define\s+([A-Za-z_][A-Za-z_0-9]*)" @@ -266,7 +267,7 @@ class Parser(object): ' __dotdotdot__;') # this forces pycparser to consider the following in the file # called <cdef source string> from line 1 - csourcelines.append('# 1 "<cdef source string>"') + csourcelines.append('# 1 "%s"' % (CDEF_SOURCE_STRING,)) csourcelines.append(csource) fullcsource = '\n'.join(csourcelines) if lock is not None: @@ -287,7 +288,7 @@ class Parser(object): # the user gives explicit ``# NUM "FILE"`` directives. line = None msg = str(e) - match = re.match(r"<cdef source string>:(\d+):", msg) + match = re.match(r"%s:(\d+):" % (CDEF_SOURCE_STRING,), msg) if match: linenum = int(match.group(1), 10) csourcelines = csource.splitlines() @@ -327,10 +328,12 @@ class Parser(object): break else: assert 0 + current_decl = None # try: self._inside_extern_python = '__cffi_extern_python_stop' for decl in iterator: + current_decl = decl if isinstance(decl, pycparser.c_ast.Decl): self._parse_decl(decl) elif isinstance(decl, pycparser.c_ast.Typedef): @@ -354,7 +357,13 @@ class Parser(object): elif decl.__class__.__name__ == 'Pragma': pass # skip pragma, only in pycparser 2.15 else: - raise CDefError("unrecognized construct", decl) + raise CDefError("unexpected <%s>: this construct is valid " + "C but not valid in cdef()" % + decl.__class__.__name__, decl) + except CDefError as e: + if len(e.args) == 1: + e.args = e.args + (current_decl,) + raise except FFIError as e: msg = self._convert_pycparser_error(e, csource) if msg: |