]> git.puffer.fish Git - matthieu/frr.git/commitdiff
lib/clippy: allow creating empty graph
authorDavid Lamparter <equinox@opensourcerouting.org>
Sat, 20 Jul 2024 22:30:09 +0000 (15:30 -0700)
committerDonald Sharp <sharpd@nvidia.com>
Wed, 31 Jul 2024 12:08:53 +0000 (08:08 -0400)
When merging graphs, it makes sense to allow starting with an empty one.

Signed-off-by: David Lamparter <equinox@opensourcerouting.org>
lib/command_py.c

index ccdbfc5f8e738e5d3cfa10cf9ad5c91a18a1e752..ada0f0d38609e4f479a465fa035c537d1f3117c6 100644 (file)
@@ -296,7 +296,7 @@ static PyObject *graph_parse(PyTypeObject *type, PyObject *args, PyObject *kwds)
        if (!gwrap)
                return NULL;
 
-       if (!PyArg_ParseTupleAndKeywords(args, kwds, "s|s", (char **)kwnames,
+       if (!PyArg_ParseTupleAndKeywords(args, kwds, "z|s", (char **)kwnames,
                                         &def, &doc))
                return NULL;
 
@@ -304,12 +304,18 @@ static PyObject *graph_parse(PyTypeObject *type, PyObject *args, PyObject *kwds)
        struct cmd_token *token = cmd_token_new(START_TKN, 0, NULL, NULL);
        graph_new_node(graph, token, (void (*)(void *)) & cmd_token_del);
 
-       struct cmd_element cmd = {.string = def, .doc = doc};
-       cmd_graph_parse(graph, &cmd);
-       cmd_graph_names(graph);
+       if (def) {
+               struct cmd_element cmd = { .string = def, .doc = doc };
+
+               cmd_graph_parse(graph, &cmd);
+               cmd_graph_names(graph);
+
+               gwrap->definition = strdup(def);
+       } else {
+               gwrap->definition = strdup("NULL");
+       }
 
        gwrap->graph = graph;
-       gwrap->definition = strdup(def);
        return (PyObject *)gwrap;
 }