mirror of
https://git.proxmox.com/git/mirror_frr
synced 2025-05-25 10:08:09 +00:00
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>
This commit is contained in:
parent
67a76894b7
commit
cf37c79f31
@ -68,6 +68,7 @@ struct wrap_graph {
|
|||||||
|
|
||||||
char *definition;
|
char *definition;
|
||||||
struct graph *graph;
|
struct graph *graph;
|
||||||
|
size_t n_nodewrappers;
|
||||||
struct wrap_graph_node **nodewrappers;
|
struct wrap_graph_node **nodewrappers;
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -138,6 +139,8 @@ static PyMethodDef methods_graph_node[] = {
|
|||||||
static void graph_node_wrap_free(void *arg)
|
static void graph_node_wrap_free(void *arg)
|
||||||
{
|
{
|
||||||
struct wrap_graph_node *wrap = arg;
|
struct wrap_graph_node *wrap = arg;
|
||||||
|
|
||||||
|
assert(wrap->idx < wrap->wgraph->n_nodewrappers);
|
||||||
wrap->wgraph->nodewrappers[wrap->idx] = NULL;
|
wrap->wgraph->nodewrappers[wrap->idx] = NULL;
|
||||||
Py_DECREF(wrap->wgraph);
|
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");
|
PyErr_SetString(PyExc_ValueError, "cannot find node in graph");
|
||||||
return NULL;
|
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]) {
|
if (wgraph->nodewrappers[i]) {
|
||||||
PyObject *obj = (PyObject *)wgraph->nodewrappers[i];
|
PyObject *obj = (PyObject *)wgraph->nodewrappers[i];
|
||||||
Py_INCREF(obj);
|
Py_INCREF(obj);
|
||||||
@ -298,8 +310,6 @@ static PyObject *graph_parse(PyTypeObject *type, PyObject *args, PyObject *kwds)
|
|||||||
|
|
||||||
gwrap->graph = graph;
|
gwrap->graph = graph;
|
||||||
gwrap->definition = strdup(def);
|
gwrap->definition = strdup(def);
|
||||||
gwrap->nodewrappers = calloc(vector_active(graph->nodes),
|
|
||||||
sizeof(gwrap->nodewrappers[0]));
|
|
||||||
return (PyObject *)gwrap;
|
return (PyObject *)gwrap;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user