Browse Source

Copy graph name URI into graph struct.

scossu 1 year ago
parent
commit
05b9010e4e
5 changed files with 12 additions and 12 deletions
  1. 7 7
      cpython/py_graph.h
  2. 2 1
      include/graph.h
  3. 1 1
      src/codec/lexer_nt.re
  4. 1 1
      src/codec/lexer_ttl.re
  5. 1 2
      src/graph.c

+ 7 - 7
cpython/py_graph.h

@@ -155,7 +155,7 @@ Graph_init (GraphObject *self, PyObject *args, PyObject *kwargs)
             return -1;
         }
 
-    } else uri = LSUP_iriref_new (NULL, NULL);
+    }
 
     // Set up the store if a function for that is defined.
     const LSUP_StoreInt *sif = LSUP_store_int (store_type);
@@ -165,6 +165,9 @@ Graph_init (GraphObject *self, PyObject *args, PyObject *kwargs)
                     "No interface defined for given store type.");
             return -1;
     }
+
+    // TODO Move store creation fn and handle into a separate module.
+    LSUP_store *store = LSUP_store_new (store_type, NULL, 0);
     if (sif->setup_fn) {
         if (sif->setup_fn(NULL, false) < LSUP_OK) {
             PyErr_SetString (
@@ -174,14 +177,12 @@ Graph_init (GraphObject *self, PyObject *args, PyObject *kwargs)
     }
 
     // TODO Make store ID, nsm and initial size accessible.
-    self->ob_struct = LSUP_graph_new (
-            uri, (LSUP_StoreType) store_type, NULL, NULL, 0);
+    self->ob_struct = LSUP_graph_new (store, uri, NULL);
     if (!self->ob_struct) {
         PyErr_SetString (PyExc_ValueError, "Could not create graph.");
         return -1;
     }
-    LSUP_Term *uri2 = LSUP_graph_uri (self->ob_struct);
-    log_debug("Graph URI (%p): %s", uri2, uri2->data);
+    if (uri) LSUP_term_free (uri);
 
     return 0;
 }
@@ -359,8 +360,7 @@ Graph_bool_op (
     GraphObject *res = (GraphObject *) cls->tp_alloc (cls, 0);
     if (!res) return NULL;
 
-    LSUP_Graph *dest = LSUP_graph_new (
-            NULL, LSUP_STORE_HTABLE, NULL, NULL, 0);
+    LSUP_Graph *dest = LSUP_graph_new (NULL, NULL, NULL);
     if (!dest) {
         PyErr_SetString (PyExc_Exception, "Could not create destination graph.");
         return NULL;

+ 2 - 1
include/graph.h

@@ -26,7 +26,8 @@ typedef struct graph_iter_t LSUP_GraphIterator;
  * HTable store that is freed together with the graph.
  *
  * @param[in] uri URI of the new graph. If NULL, a UUID4 URN is generated. The
- *  graph owns the handle.
+ *  term is copied into the graph and may be freed after this function is
+ *  called.
  *
  * @param[in] nsm Namespace map to use for an in-memory graph. This is ignored
  *  by graphs backed by permanent stores, which handle their own namespace map.

+ 1 - 1
src/codec/lexer_nt.re

@@ -267,7 +267,7 @@ LSUP_nt_parse_doc (FILE *fh, LSUP_Graph **gr_p, size_t *ct, char **err_p)
 
     LSUP_rc rc;
 
-    LSUP_Graph *gr = LSUP_graph_new (NULL, LSUP_iriref_new (NULL, NULL), NULL);
+    LSUP_Graph *gr = LSUP_graph_new (NULL, NULL, NULL);
     if (UNLIKELY (!gr)) return LSUP_MEM_ERR;
 
     LSUP_GraphIterator *it = LSUP_graph_add_init (gr);

+ 1 - 1
src/codec/lexer_ttl.re

@@ -376,7 +376,7 @@ LSUP_ttl_parse_doc (FILE *fh, LSUP_Graph **gr_p, size_t *ct, char **err_p)
     void *parser = TTLParseAlloc (malloc);
 
     // TODO add basic NS, critically xsd: and rdf:
-    LSUP_Graph *gr = LSUP_graph_new (NULL, LSUP_iriref_new (NULL, NULL), NULL);
+    LSUP_Graph *gr = LSUP_graph_new (NULL, NULL, NULL);
     if (UNLIKELY (!gr)) return LSUP_MEM_ERR;
 
     state->it = LSUP_graph_add_init (gr);

+ 1 - 2
src/graph.c

@@ -53,8 +53,7 @@ LSUP_graph_new (LSUP_Store *store, LSUP_Term *uri, LSUP_NSMap *nsm)
     LSUP_Graph *gr;
     MALLOC_GUARD (gr, NULL);
 
-    if (!uri) uri = LSUP_iriref_new (NULL, NULL);
-    gr->uri = uri;
+    gr->uri = uri? LSUP_term_copy (uri) : LSUP_iriref_new (NULL, NULL);
     gr->store = store;
 
     if (gr->store->sif->features & LSUP_STORE_PERM) gr->nsm = NULL;