|
@@ -29,6 +29,10 @@ struct graph_iter_t {
|
|
inline static LSUP_rc
|
|
inline static LSUP_rc
|
|
graph_iter_next_buffer (LSUP_GraphIterator *it, LSUP_BufferTriple *sspo);
|
|
graph_iter_next_buffer (LSUP_GraphIterator *it, LSUP_BufferTriple *sspo);
|
|
|
|
|
|
|
|
+inline static void
|
|
|
|
+graph_iter_free_buffer (LSUP_GraphIterator *it, LSUP_BufferTriple *sspo);
|
|
|
|
+
|
|
|
|
+
|
|
#define ENTRY(a, b) (be) == (LSUP_STORE_##a) ||
|
|
#define ENTRY(a, b) (be) == (LSUP_STORE_##a) ||
|
|
static inline bool
|
|
static inline bool
|
|
check_backend (LSUP_StoreType be)
|
|
check_backend (LSUP_StoreType be)
|
|
@@ -417,17 +421,7 @@ LSUP_graph_lookup (
|
|
LSUP_rc
|
|
LSUP_rc
|
|
LSUP_graph_iter_next (LSUP_GraphIterator *it, LSUP_Triple *spo)
|
|
LSUP_graph_iter_next (LSUP_GraphIterator *it, LSUP_Triple *spo)
|
|
{
|
|
{
|
|
- LSUP_Buffer *ss, *sp, *so;
|
|
|
|
- LSUP_BufferTriple *sspo = NULL;
|
|
|
|
- if (it->graph->store->sif->features & LSUP_STORE_COW) {
|
|
|
|
- CALLOC_GUARD (ss, LSUP_MEM_ERR);
|
|
|
|
- CALLOC_GUARD (sp, LSUP_MEM_ERR);
|
|
|
|
- CALLOC_GUARD (so, LSUP_MEM_ERR);
|
|
|
|
- sspo = LSUP_btriple_new (ss, sp, so);
|
|
|
|
- } else {
|
|
|
|
- // TODO copy-on-retrieval stores. None yet.
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
|
|
+ LSUP_BufferTriple *sspo = BTRP_DUMMY;
|
|
LSUP_rc rc = graph_iter_next_buffer (it, sspo);
|
|
LSUP_rc rc = graph_iter_next_buffer (it, sspo);
|
|
|
|
|
|
if (rc == LSUP_OK) {
|
|
if (rc == LSUP_OK) {
|
|
@@ -439,16 +433,11 @@ LSUP_graph_iter_next (LSUP_GraphIterator *it, LSUP_Triple *spo)
|
|
if (!spo->o) return LSUP_ERROR;
|
|
if (!spo->o) return LSUP_ERROR;
|
|
}
|
|
}
|
|
|
|
|
|
- if (it->graph->store->sif->features & LSUP_STORE_COW) {
|
|
|
|
- LSUP_btriple_free_shallow (sspo);
|
|
|
|
- } else {
|
|
|
|
- // TODO copy-on-retrieval stores. None yet.
|
|
|
|
- }
|
|
|
|
|
|
+ graph_iter_free_buffer (it, sspo);
|
|
|
|
|
|
return rc;
|
|
return rc;
|
|
}
|
|
}
|
|
|
|
|
|
-
|
|
|
|
const LSUP_Graph *
|
|
const LSUP_Graph *
|
|
LSUP_graph_iter_graph (LSUP_GraphIterator *it)
|
|
LSUP_graph_iter_graph (LSUP_GraphIterator *it)
|
|
{ return it->graph; }
|
|
{ return it->graph; }
|
|
@@ -548,6 +537,7 @@ LSUP_graph_connections (
|
|
|
|
|
|
if (ex) LSUP_term_free (ins);
|
|
if (ex) LSUP_term_free (ins);
|
|
}
|
|
}
|
|
|
|
+ graph_iter_free_buffer (it, sspo);
|
|
LSUP_graph_iter_free(it);
|
|
LSUP_graph_iter_free(it);
|
|
|
|
|
|
size_t i = 0;
|
|
size_t i = 0;
|
|
@@ -590,6 +580,7 @@ LSUP_graph_term_set (
|
|
LSUP_term_new_from_buffer (LSUP_btriple_pos (sspo, rpos)),
|
|
LSUP_term_new_from_buffer (LSUP_btriple_pos (sspo, rpos)),
|
|
NULL);
|
|
NULL);
|
|
}
|
|
}
|
|
|
|
+ graph_iter_free_buffer (it, sspo);
|
|
LSUP_graph_iter_free (it);
|
|
LSUP_graph_iter_free (it);
|
|
|
|
|
|
return ts;
|
|
return ts;
|
|
@@ -689,13 +680,42 @@ LSUP_bnode_add_collection (LSUP_GraphIterator *it, LSUP_TermSet *ts)
|
|
*/
|
|
*/
|
|
|
|
|
|
/** @brief Advance an iterator and return a serialized triple.
|
|
/** @brief Advance an iterator and return a serialized triple.
|
|
|
|
+ *
|
|
|
|
+ * The passed triple should be a LSUP_BTRP_DUMMY and must be freed with
|
|
|
|
+ * graph_iter_free_buffer().
|
|
*
|
|
*
|
|
* This is an internal function to pass raw buffers between higher-level
|
|
* This is an internal function to pass raw buffers between higher-level
|
|
* functions without serializing and deserializing triples.
|
|
* functions without serializing and deserializing triples.
|
|
*/
|
|
*/
|
|
inline static LSUP_rc
|
|
inline static LSUP_rc
|
|
graph_iter_next_buffer (LSUP_GraphIterator *it, LSUP_BufferTriple *sspo)
|
|
graph_iter_next_buffer (LSUP_GraphIterator *it, LSUP_BufferTriple *sspo)
|
|
-{ return it->graph->store->sif->lu_next_fn (it->data, sspo, NULL); }
|
|
|
|
|
|
+{
|
|
|
|
+ if (it->graph->store->sif->features & LSUP_STORE_COW) {
|
|
|
|
+ CALLOC_GUARD (sspo->s, LSUP_MEM_ERR);
|
|
|
|
+ CALLOC_GUARD (sspo->p, LSUP_MEM_ERR);
|
|
|
|
+ CALLOC_GUARD (sspo->o, LSUP_MEM_ERR);
|
|
|
|
+ } else {
|
|
|
|
+ // TODO copy-on-retrieval stores. None yet.
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ return it->graph->store->sif->lu_next_fn (it->data, sspo, NULL);
|
|
|
|
+}
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+/** @brief Free a buffer obtained with #graph_iter_next_buffer().
|
|
|
|
+ *
|
|
|
|
+ * This deallocates resources properly by preserving borrowed pointers from the
|
|
|
|
+ * store in case of LSUP_STORE_COW stores.
|
|
|
|
+ */
|
|
|
|
+static void
|
|
|
|
+graph_iter_free_buffer (LSUP_GraphIterator *it, LSUP_BufferTriple *sspo)
|
|
|
|
+{
|
|
|
|
+ if (it->graph->store->sif->features & LSUP_STORE_COW) {
|
|
|
|
+ LSUP_btriple_free_shallow (sspo);
|
|
|
|
+ } else {
|
|
|
|
+ // TODO copy-on-retrieval stores. None yet.
|
|
|
|
+ }
|
|
|
|
+}
|
|
|
|
|
|
|
|
|
|
/**
|
|
/**
|