]> git.proxmox.com Git - mirror_frr.git/blobdiff - lib/defun_lex.l
Merge pull request #5625 from qlyoung/fix-zapi-ipset-name-nullterm
[mirror_frr.git] / lib / defun_lex.l
index 8aa37a62a205ee9d691735c993702dc39257589f..19b06f51b8d633373a63cb6c4500c8c6d2bad93b 100644 (file)
@@ -1,4 +1,3 @@
-%{
 /*
  * clippy (CLI preparator in python) C pseudo-lexer
  * Copyright (C) 2016-2017  David Lamparter for NetDEF, Inc.
  * code documentation in it.
  */
 
-/* ignore harmless bug in old versions of flex */
+%top{
+#ifdef HAVE_CONFIG_H
+#include "config.h"
+#endif
+}
+%{
+/* ignore harmless bugs in old versions of flex */
 #pragma GCC diagnostic ignored "-Wsign-compare"
+#pragma GCC diagnostic ignored "-Wunused-value"
 
 #include "config.h"
 #include <Python.h>
@@ -85,7 +91,7 @@ SPECIAL               [(),]
 %option noyywrap
 %option noinput
 %option nounput
-%option outfile="defun_lex.c"
+%option outfile="lib/defun_lex.c"
 %option prefix="def_yy"
 %option 8bit
 
@@ -131,6 +137,9 @@ SPECIAL             [(),]
 "DEFUN_NOSH"                   value = strdup(yytext); return DEFUNNY;
 "DEFUN_HIDDEN"                 value = strdup(yytext); return DEFUNNY;
 "DEFPY"                                value = strdup(yytext); return DEFUNNY;
+"DEFPY_NOSH"                   value = strdup(yytext); return DEFUNNY;
+"DEFPY_ATTR"                   value = strdup(yytext); return DEFUNNY;
+"DEFPY_HIDDEN"                 value = strdup(yytext); return DEFUNNY;
 "ALIAS"                                value = strdup(yytext); return DEFUNNY;
 "ALIAS_HIDDEN"                 value = strdup(yytext); return DEFUNNY;
 "install_element"              value = strdup(yytext); return INSTALL;
@@ -154,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;
@@ -181,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)
@@ -235,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);
@@ -251,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) {