From 3c1556f386a6c5866e1b5352571e44ed3e22da76 Mon Sep 17 00:00:00 2001 From: David Lamparter Date: Sat, 20 Jul 2024 16:19:29 -0700 Subject: [PATCH] lib/clippy: expose graph nodes' back pointers There's a wrapper for nodes' outgoing pointers, but not incoming yet. Signed-off-by: David Lamparter --- lib/command_py.c | 26 +++++++++++++++++++++++--- 1 file changed, 23 insertions(+), 3 deletions(-) diff --git a/lib/command_py.c b/lib/command_py.c index 6c051f55cd..411caa52d6 100644 --- a/lib/command_py.c +++ b/lib/command_py.c @@ -109,6 +109,24 @@ static PyObject *graph_node_next(PyObject *self, PyObject *args) pylist = PyList_New(vector_active(wrap->node->to)); for (size_t i = 0; i < vector_active(wrap->node->to); i++) { struct graph_node *gn = vector_slot(wrap->node->to, i); + + PyList_SetItem(pylist, i, graph_to_pyobj(wrap->wgraph, gn)); + } + return pylist; +}; + +static PyObject *graph_node_prev(PyObject *self, PyObject *args) +{ + struct wrap_graph_node *wrap = (struct wrap_graph_node *)self; + PyObject *pylist; + + if (wrap->node->data && + ((struct cmd_token *)wrap->node->data)->type == START_TKN) + return PyList_New(0); + pylist = PyList_New(vector_active(wrap->node->from)); + for (size_t i = 0; i < vector_active(wrap->node->from); i++) { + struct graph_node *gn = vector_slot(wrap->node->from, i); + PyList_SetItem(pylist, i, graph_to_pyobj(wrap->wgraph, gn)); } return pylist; @@ -133,9 +151,11 @@ static PyObject *graph_node_join(PyObject *self, PyObject *args) }; static PyMethodDef methods_graph_node[] = { - {"next", graph_node_next, METH_NOARGS, "outbound graph edge list"}, - {"join", graph_node_join, METH_NOARGS, "outbound join node"}, - {}}; + { "next", graph_node_next, METH_NOARGS, "outbound graph edge list" }, + { "prev", graph_node_prev, METH_NOARGS, "inbound graph edge list" }, + { "join", graph_node_join, METH_NOARGS, "outbound join node" }, + {} +}; static void graph_node_wrap_free(void *arg) { -- 2.39.5