summaryrefslogtreecommitdiff
path: root/lib/defun_lex.l
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 /lib/defun_lex.l
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 'lib/defun_lex.l')
-rw-r--r--lib/defun_lex.l17
1 files changed, 15 insertions, 2 deletions
diff --git a/lib/defun_lex.l b/lib/defun_lex.l
index 6c0805a4fa..19b06f51b8 100644
--- a/lib/defun_lex.l
+++ b/lib/defun_lex.l
@@ -163,7 +163,7 @@ static int yylex_clr(char **retbuf)
return rv;
}
-static PyObject *get_args(void)
+static PyObject *get_args(const char *filename, int lineno)
{
PyObject *pyObj = PyList_New(0);
PyObject *pyArg = NULL;
@@ -190,6 +190,13 @@ static PyObject *get_args(void)
free(tval);
continue;
}
+ if (token == PREPROC) {
+ free(tval);
+ Py_DECREF(pyObj);
+ return PyErr_Format(PyExc_ValueError,
+ "%s:%d: cannot process CPP directive within argument list",
+ filename, lineno);
+ }
if (token == SPECIAL) {
if (depth == 1 && (tval[0] == ',' || tval[0] == ')')) {
if (pyArg)
@@ -244,7 +251,12 @@ PyObject *clippy_parse(PyObject *self, PyObject *args)
case DEFUNNY:
case INSTALL:
case AUXILIARY:
- pyArgs = get_args();
+ pyArgs = get_args(filename, lineno);
+ if (!pyArgs) {
+ free(tval);
+ Py_DECREF(pyCont);
+ return NULL;
+ }
pyItem = PyDict_New();
PyDict_SetItemString(pyItem, "type", PyUnicode_FromString(tval));
PyDict_SetItemString(pyItem, "args", pyArgs);
@@ -260,6 +272,7 @@ PyObject *clippy_parse(PyObject *self, PyObject *args)
pyItem = PyDict_New();
PyDict_SetItemString(pyItem, "type", PyUnicode_FromString("PREPROC"));
PyDict_SetItemString(pyItem, "line", PyUnicode_FromString(tval));
+ lineno--;
break;
}
if (pyItem) {