|
@@ -272,9 +272,9 @@ Graph_new_from_rdf (PyTypeObject *cls, PyObject *args)
|
|
|
* > created by fdopen() is closed. The result of applying fdopen() to a
|
|
|
* > shared memory object is undefined.
|
|
|
*
|
|
|
- * This handle must not be closed. Leave open for the Python caller to
|
|
|
- * handle it.
|
|
|
+ * Hence the `dup()`.
|
|
|
*/
|
|
|
+ fd = dup (fd);
|
|
|
FILE *fh = fdopen (fd, "r");
|
|
|
|
|
|
GraphObject *res = (GraphObject *) cls->tp_alloc(cls, 0);
|
|
@@ -291,6 +291,7 @@ Graph_new_from_rdf (PyTypeObject *cls, PyObject *args)
|
|
|
size_t ct;
|
|
|
char *err;
|
|
|
codec->decode_graph (fh, &res->ob_struct, &ct, &err);
|
|
|
+ fclose (fh);
|
|
|
|
|
|
log_debug ("Decoded %lu triples.", ct);
|
|
|
if (UNLIKELY (err)) {
|
|
@@ -334,6 +335,7 @@ inline static int build_trp_pattern (PyObject *args, LSUP_Term *spo[])
|
|
|
}
|
|
|
|
|
|
|
|
|
+/*
|
|
|
static PyObject *
|
|
|
Graph_new_set_from_store_lookup (PyTypeObject *cls, PyObject *args)
|
|
|
{
|
|
@@ -364,6 +366,7 @@ Graph_new_set_from_store_lookup (PyTypeObject *cls, PyObject *args)
|
|
|
Py_INCREF (ret);
|
|
|
return ret;
|
|
|
}
|
|
|
+*/
|
|
|
|
|
|
|
|
|
static PyObject *
|
|
@@ -412,11 +415,11 @@ Graph_add (PyObject *self, PyObject *triples)
|
|
|
|
|
|
PyObject *trp_obj;
|
|
|
int rc = 0;
|
|
|
- size_t i;
|
|
|
+ size_t ct = 0;
|
|
|
LSUP_GraphIterator *it = LSUP_graph_add_init (
|
|
|
((GraphObject *)self)->ob_struct);
|
|
|
|
|
|
- for (i = 0; (trp_obj = PyIter_Next (iter)); i++) {
|
|
|
+ while ((trp_obj = PyIter_Next (iter))) {
|
|
|
if (!PyObject_TypeCheck (trp_obj, &TripleType)) {
|
|
|
PyErr_SetString (
|
|
|
PyExc_ValueError, "Object is not a triple.");
|
|
@@ -424,26 +427,26 @@ Graph_add (PyObject *self, PyObject *triples)
|
|
|
goto finally;
|
|
|
}
|
|
|
|
|
|
- log_trace ("Inserting triple #%lu", i);
|
|
|
+ log_trace ("Inserting triple #%lu", ct);
|
|
|
|
|
|
LSUP_rc db_rc = LSUP_graph_add_iter (
|
|
|
it, ((TripleObject *) trp_obj)->ob_struct);
|
|
|
|
|
|
- if (db_rc == LSUP_OK) rc = LSUP_OK;
|
|
|
- if (UNLIKELY (db_rc < 0)) {
|
|
|
- PyErr_SetString (
|
|
|
- PyExc_ValueError, "Unknown error while adding triples.");
|
|
|
+ if (db_rc == LSUP_OK) {
|
|
|
+ rc = LSUP_OK;
|
|
|
+ ct++;
|
|
|
+ } else if (UNLIKELY (db_rc < 0)) {
|
|
|
+ PyErr_SetString (PyExc_ValueError, "Error while adding triples.");
|
|
|
rc = -1;
|
|
|
goto finally;
|
|
|
}
|
|
|
+ // If db_rc > 0, it's a no-op and the counter is not increased.
|
|
|
}
|
|
|
|
|
|
finally:
|
|
|
LSUP_graph_add_done (it);
|
|
|
|
|
|
- if (rc == LSUP_OK)
|
|
|
- return PyLong_FromSize_t (LSUP_graph_iter_cur (it));
|
|
|
-
|
|
|
+ if (rc == LSUP_OK) return PyLong_FromSize_t (ct);
|
|
|
return NULL;
|
|
|
}
|
|
|
|
|
@@ -550,11 +553,13 @@ static PyMethodDef Graph_methods[] = {
|
|
|
METH_CLASS | METH_VARARGS,
|
|
|
"Create a graph from a RDF file."
|
|
|
},
|
|
|
+ /*
|
|
|
{
|
|
|
"from_lookup", (PyCFunction) Graph_new_set_from_store_lookup,
|
|
|
METH_CLASS | METH_VARARGS,
|
|
|
"Create a set of graphs from a store SPO lookup."
|
|
|
},
|
|
|
+ */
|
|
|
{
|
|
|
"store", (PyCFunction) Graph_store, METH_NOARGS,
|
|
|
"Store a graph into the permanent back end."
|