From 34a4f858b7823c07fd1d7faa385f6a692136fc2f Mon Sep 17 00:00:00 2001 From: David Lamparter Date: Sat, 20 Jul 2024 15:36:20 -0700 Subject: [PATCH] lib/clippy: wrap cmd_graph_merge via Graph.merge() Export cmd_graph_merge() to python code via graph1.merge(graph2). Signed-off-by: David Lamparter --- lib/command_py.c | 22 ++++++++++++++++++++-- 1 file changed, 20 insertions(+), 2 deletions(-) diff --git a/lib/command_py.c b/lib/command_py.c index ada0f0d386..82ca5a8ffc 100644 --- a/lib/command_py.c +++ b/lib/command_py.c @@ -258,9 +258,13 @@ static PyObject *graph_first(PyObject *self, PyObject *args) return graph_to_pyobj(gwrap, gn); }; +static PyObject *graph_merge(PyObject *self, PyObject *args); + static PyMethodDef methods_graph[] = { - {"first", graph_first, METH_NOARGS, "first graph node"}, - {}}; + { "first", graph_first, METH_NOARGS, "first graph node" }, + { "merge", graph_merge, METH_VARARGS, "merge graphs" }, + {} +}; static PyObject *graph_parse(PyTypeObject *type, PyObject *args, PyObject *kwds); @@ -285,6 +289,20 @@ static PyTypeObject typeobj_graph = { .tp_methods = methods_graph, }; +static PyObject *graph_merge(PyObject *self, PyObject *args) +{ + PyObject *py_other; + struct wrap_graph *gwrap = (struct wrap_graph *)self; + struct wrap_graph *gother; + + if (!PyArg_ParseTuple(args, "O!", &typeobj_graph, &py_other)) + return NULL; + + gother = (struct wrap_graph *)py_other; + cmd_graph_merge(gwrap->graph, gother->graph, +1); + Py_RETURN_NONE; +} + /* top call / entrypoint for python code */ static PyObject *graph_parse(PyTypeObject *type, PyObject *args, PyObject *kwds) {