|
@@ -198,7 +198,7 @@ Graph_dealloc (GraphObject *self)
|
|
|
static PyObject *
|
|
|
Graph_get_uri (GraphObject *self, void *closure)
|
|
|
{
|
|
|
- LSUP_Term *uri = LSUP_graph_uri (self->ob_struct);
|
|
|
+ const LSUP_Term *uri = LSUP_graph_uri (self->ob_struct);
|
|
|
LOG_DEBUG("Graph URI address: %p", uri);
|
|
|
LOG_DEBUG("Graph URI: %s", uri->data);
|
|
|
|
|
@@ -231,19 +231,6 @@ static PyGetSetDef Graph_getsetters[] = {
|
|
|
};
|
|
|
|
|
|
|
|
|
-static int
|
|
|
-Graph_copy_contents (GraphObject *self, GraphObject *dest)
|
|
|
-{
|
|
|
- if (LSUP_graph_copy_contents (self->ob_struct, dest->ob_struct) < LSUP_OK)
|
|
|
- {
|
|
|
- PyErr_SetString (PyExc_ValueError, "Error copying graph contents.");
|
|
|
- return -1;
|
|
|
- }
|
|
|
-
|
|
|
- return 0;
|
|
|
-};
|
|
|
-
|
|
|
-
|
|
|
static PyObject *
|
|
|
Graph_new_from_rdf (PyTypeObject *cls, PyObject *args)
|
|
|
{
|
|
@@ -335,6 +322,76 @@ inline static int build_trp_pattern (PyObject *args, LSUP_Term *spo[])
|
|
|
return 0;
|
|
|
}
|
|
|
|
|
|
+/** @brief Converter for a term struct in `O&` notation.
|
|
|
+ *
|
|
|
+ * See https://docs.python.org/3/c-api/arg.html#other-objects
|
|
|
+ * Convert a PyObject argument into a LSUP_term. `Py_None` is acceptable.
|
|
|
+ *
|
|
|
+ * @param[in] obj Argument passed to calling function.
|
|
|
+ *
|
|
|
+ * @param[out] result Result of transform process.
|
|
|
+ *
|
|
|
+ * @return 1 on conversion success; 0 in failure.
|
|
|
+ */
|
|
|
+static int arg_term_converter (PyObject *obj, void *result)
|
|
|
+{
|
|
|
+ if (obj != Py_None && !PyObject_TypeCheck (obj, &TermType)) {
|
|
|
+ PyErr_SetString (PyExc_TypeError, "Variable must be a Term or None.");
|
|
|
+ return 0;
|
|
|
+ }
|
|
|
+
|
|
|
+ LSUP_Term **term = result;
|
|
|
+ *term = obj != Py_None ? ((TermObject *)obj)->ob_struct : NULL;
|
|
|
+
|
|
|
+ return 1;
|
|
|
+}
|
|
|
+
|
|
|
+
|
|
|
+/** @brief Converter for a graph struct in `O&` notation.
|
|
|
+ *
|
|
|
+ * See https://docs.python.org/3/c-api/arg.html#other-objects
|
|
|
+ * Convert a PyObject argument into a LSUP_term.
|
|
|
+ *
|
|
|
+ * @param[in] obj Argument passed to calling function.
|
|
|
+ *
|
|
|
+ * @param[out] result Result of transform process.
|
|
|
+ *
|
|
|
+ * @return 1 on conversion success; 0 in failure.
|
|
|
+ */
|
|
|
+static int arg_graph_converter (PyObject *obj, void *result);
|
|
|
+
|
|
|
+
|
|
|
+static PyObject *
|
|
|
+Graph_copy_contents (GraphObject *self, PyObject *args, PyObject *kwargs)
|
|
|
+{
|
|
|
+ assert (!PyErr_Occurred());
|
|
|
+ assert (args || kwargs);
|
|
|
+
|
|
|
+ LSUP_Term *spo[3];
|
|
|
+ LSUP_Graph *dest;
|
|
|
+
|
|
|
+ static char *kwlist[] = {"", "s", "p", "o", NULL};
|
|
|
+ if (!PyArg_ParseTupleAndKeywords(
|
|
|
+ args, kwargs, "O&|O&O&O&", kwlist,
|
|
|
+ arg_graph_converter, &dest,
|
|
|
+ arg_term_converter, spo,
|
|
|
+ arg_term_converter, spo + 1,
|
|
|
+ arg_term_converter, spo + 2
|
|
|
+ )) return NULL;
|
|
|
+
|
|
|
+ if (LSUP_graph_copy_contents (
|
|
|
+ self->ob_struct, dest,
|
|
|
+ spo[0], spo[1], spo[2])
|
|
|
+ < LSUP_OK)
|
|
|
+ {
|
|
|
+ PyErr_SetString (PyExc_ValueError, "Error copying graph contents.");
|
|
|
+
|
|
|
+ return NULL;
|
|
|
+ }
|
|
|
+
|
|
|
+ Py_RETURN_NONE;
|
|
|
+};
|
|
|
+
|
|
|
|
|
|
static PyObject *
|
|
|
Graph_richcmp (PyObject *self, PyObject *other, int op)
|
|
@@ -433,8 +490,13 @@ static PyObject *Graph_remove (PyObject *self, PyObject *args)
|
|
|
LSUP_rc rc;
|
|
|
LSUP_Term *spo[3];
|
|
|
|
|
|
- rc = build_trp_pattern (args, spo);
|
|
|
- if (rc < 0) goto finally;
|
|
|
+ if (!PyArg_ParseTuple (
|
|
|
+ args,
|
|
|
+ "O&O&O&",
|
|
|
+ arg_term_converter, spo,
|
|
|
+ arg_term_converter, spo + 1,
|
|
|
+ arg_term_converter, spo + 2
|
|
|
+ )) Py_RETURN_NONE;
|
|
|
|
|
|
size_t ct;
|
|
|
rc = LSUP_graph_remove (
|
|
@@ -460,8 +522,13 @@ static PyObject *Graph_lookup (PyObject *self, PyObject *args)
|
|
|
GraphIteratorObject *it_obj = NULL;
|
|
|
LSUP_Term *spo[3];
|
|
|
|
|
|
- rc = build_trp_pattern (args, spo);
|
|
|
- if (UNLIKELY (rc < 0)) goto finally;
|
|
|
+ if (!PyArg_ParseTuple (
|
|
|
+ args,
|
|
|
+ "O&O&O&",
|
|
|
+ arg_term_converter, spo,
|
|
|
+ arg_term_converter, spo + 1,
|
|
|
+ arg_term_converter, spo + 2
|
|
|
+ )) Py_RETURN_NONE;
|
|
|
|
|
|
size_t ct;
|
|
|
LSUP_GraphIterator *it = LSUP_graph_lookup (
|
|
@@ -521,7 +588,8 @@ Graph_encode (PyObject *self, PyObject *args)
|
|
|
|
|
|
static PyMethodDef Graph_methods[] = {
|
|
|
{
|
|
|
- "copy", (PyCFunction) Graph_copy_contents, METH_CLASS | METH_VARARGS,
|
|
|
+ "copy", (PyCFunction) Graph_copy_contents,
|
|
|
+ METH_VARARGS | METH_KEYWORDS,
|
|
|
"Copy the contents of a graph into another."
|
|
|
},
|
|
|
{
|
|
@@ -614,4 +682,18 @@ PyTypeObject GraphType = {
|
|
|
.tp_as_sequence = &Graph_seq_methods,
|
|
|
};
|
|
|
|
|
|
+
|
|
|
+static int arg_graph_converter (PyObject *obj, void *result)
|
|
|
+{
|
|
|
+ if (!PyObject_TypeCheck (obj, &GraphType)) {
|
|
|
+ PyErr_SetString (PyExc_TypeError, "Variable must be a Graph object.");
|
|
|
+ return 0;
|
|
|
+ }
|
|
|
+
|
|
|
+ LSUP_Graph **gr = result;
|
|
|
+ *gr = ((GraphObject *)obj)->ob_struct;
|
|
|
+
|
|
|
+ return 1;
|
|
|
+}
|
|
|
+
|
|
|
#endif
|