summaryrefslogtreecommitdiff
path: root/python
diff options
context:
space:
mode:
authorDavid Lamparter <equinox@diac24.net>2019-06-04 17:07:57 +0200
committerDavid Lamparter <equinox@diac24.net>2019-06-12 19:22:59 +0200
commit3779776a39d81168b701b2cc2ce50a3b2331d3e8 (patch)
tree57d3126699bf2e56509b085f370eee899cfe8ab5 /python
parent72ad94d5482298a7bb8d099bee3b7bfeab2a222b (diff)
lib/clippy: error out on unsupported bits
clippy can't process #ifdef or similar bits inside of an argument list (e.g. within the braces of a DEFUN or DEFPY statement.) Improve error reporting to catch these cases instead of generating broken C code. Fixes: #3840 Signed-off-by: David Lamparter <equinox@diac24.net>
Diffstat (limited to 'python')
-rw-r--r--python/clidef.py20
1 files changed, 19 insertions, 1 deletions
diff --git a/python/clidef.py b/python/clidef.py
index f8d96115bd..68682eea6c 100644
--- a/python/clidef.py
+++ b/python/clidef.py
@@ -183,11 +183,25 @@ argblock = Template('''
}''')
def process_file(fn, ofd, dumpfd, all_defun):
+ errors = 0
filedata = clippy.parse(fn)
for entry in filedata['data']:
if entry['type'].startswith('DEFPY') or (all_defun and entry['type'].startswith('DEFUN')):
+ if len(entry['args'][0]) != 1:
+ sys.stderr.write('%s:%d: DEFPY function name not parseable (%r)\n' % (fn, entry['lineno'], entry['args'][0]))
+ errors += 1
+ continue
+
cmddef = entry['args'][2]
+ for i in cmddef:
+ if not (i.startswith('"') and i.endswith('"')):
+ sys.stderr.write('%s:%d: DEFPY command string not parseable (%r)\n' % (fn, entry['lineno'], cmddef))
+ errors += 1
+ cmddef = None
+ break
+ if cmddef is None:
+ continue
cmddef = ''.join([i[1:-1] for i in cmddef])
graph = clippy.Graph(cmddef)
@@ -251,6 +265,8 @@ def process_file(fn, ofd, dumpfd, all_defun):
params['nonempty'] = len(argblocks)
ofd.write(templ.substitute(params))
+ return errors
+
if __name__ == '__main__':
import argparse
@@ -274,7 +290,9 @@ if __name__ == '__main__':
if args.show:
dumpfd = sys.stderr
- process_file(args.cfile, ofd, dumpfd, args.all_defun)
+ errors = process_file(args.cfile, ofd, dumpfd, args.all_defun)
+ if errors != 0:
+ sys.exit(1)
if args.o is not None:
clippy.wrdiff(args.o, ofd, [args.cfile, os.path.realpath(__file__), sys.executable])