summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDavid Lamparter <equinox@opensourcerouting.org>2024-07-20 15:29:59 -0700
committerDonald Sharp <sharpd@nvidia.com>2024-07-31 08:08:53 -0400
commitcf37c79f3132285a7d02f54573b1cfa85cb6b919 (patch)
tree84a8e98016d853c8f9ea42e6c8a4832493afa423
parent67a76894b70f73c62b7eb2d05a02ef282c16ec82 (diff)
lib/clippy: dynamically wrap graph nodes
The number of nodes in a graph will change as soon as cmd_graph_merge is supported as an operation, therefore size this dynamically. Signed-off-by: David Lamparter <equinox@opensourcerouting.org>
-rw-r--r--lib/command_py.c14
1 files changed, 12 insertions, 2 deletions
diff --git a/lib/command_py.c b/lib/command_py.c
index f8abcf8ef4..ccdbfc5f8e 100644
--- a/lib/command_py.c
+++ b/lib/command_py.c
@@ -68,6 +68,7 @@ struct wrap_graph {
char *definition;
struct graph *graph;
+ size_t n_nodewrappers;
struct wrap_graph_node **nodewrappers;
};
@@ -138,6 +139,8 @@ static PyMethodDef methods_graph_node[] = {
static void graph_node_wrap_free(void *arg)
{
struct wrap_graph_node *wrap = arg;
+
+ assert(wrap->idx < wrap->wgraph->n_nodewrappers);
wrap->wgraph->nodewrappers[wrap->idx] = NULL;
Py_DECREF(wrap->wgraph);
}
@@ -166,6 +169,15 @@ static PyObject *graph_to_pyobj(struct wrap_graph *wgraph,
PyErr_SetString(PyExc_ValueError, "cannot find node in graph");
return NULL;
}
+ if (i >= wgraph->n_nodewrappers) {
+ wgraph->nodewrappers =
+ realloc(wgraph->nodewrappers,
+ (i + 1) * sizeof(wgraph->nodewrappers[0]));
+ memset(wgraph->nodewrappers + wgraph->n_nodewrappers, 0,
+ sizeof(wgraph->nodewrappers[0]) *
+ (i + 1 - wgraph->n_nodewrappers));
+ wgraph->n_nodewrappers = i + 1;
+ }
if (wgraph->nodewrappers[i]) {
PyObject *obj = (PyObject *)wgraph->nodewrappers[i];
Py_INCREF(obj);
@@ -298,8 +310,6 @@ static PyObject *graph_parse(PyTypeObject *type, PyObject *args, PyObject *kwds)
gwrap->graph = graph;
gwrap->definition = strdup(def);
- gwrap->nodewrappers = calloc(vector_active(graph->nodes),
- sizeof(gwrap->nodewrappers[0]));
return (PyObject *)gwrap;
}