summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorDavid Robillard <d@drobilla.net>2014-09-24 23:47:31 +0000
committerDavid Robillard <d@drobilla.net>2014-09-24 23:47:31 +0000
commit7ce406f8881c8d598daa179468a9eda90459c32f (patch)
treeb27249c59a2197de6cef2d7ddeab2f42630065cf /src
parent4807519449ac21e9565774f1641ea14323fe82d5 (diff)
downloadlilv-7ce406f8881c8d598daa179468a9eda90459c32f.tar.gz
lilv-7ce406f8881c8d598daa179468a9eda90459c32f.tar.bz2
lilv-7ce406f8881c8d598daa179468a9eda90459c32f.zip
Fixes for new sord.
git-svn-id: http://svn.drobilla.net/lad/trunk/lilv@5465 a436a847-0d15-0410-975c-d299462d15a1
Diffstat (limited to 'src')
-rw-r--r--src/lilv_internal.h8
-rw-r--r--src/plugin.c28
-rw-r--r--src/world.c70
3 files changed, 76 insertions, 30 deletions
diff --git a/src/lilv_internal.h b/src/lilv_internal.h
index ed2c13a..25850d3 100644
--- a/src/lilv_internal.h
+++ b/src/lilv_internal.h
@@ -326,6 +326,14 @@ lilv_world_find_nodes_internal(LilvWorld* world,
const SordNode* predicate,
const SordNode* object);
+SordModel*
+lilv_world_filter_model(LilvWorld* world,
+ SordModel* model,
+ const SordNode* subject,
+ const SordNode* predicate,
+ const SordNode* object,
+ const SordNode* graph);
+
#define FOREACH_MATCH(iter) \
for (; !sord_iter_end(iter); sord_iter_next(iter))
diff --git a/src/plugin.c b/src/plugin.c
index 9c966b6..8729314 100644
--- a/src/plugin.c
+++ b/src/plugin.c
@@ -142,12 +142,15 @@ lilv_plugin_load(LilvPlugin* p)
SerdReader* reader = sord_new_reader(p->world->model, env, SERD_TURTLE,
bundle_uri_node);
- SordIter* prototypes = sord_search(p->world->model,
- p->plugin_uri->node,
- p->world->uris.lv2_prototype,
- NULL, NULL);
- FOREACH_MATCH(prototypes) {
- const SordNode* t = sord_iter_get_node(prototypes, SORD_OBJECT);
+ SordModel* prototypes = lilv_world_filter_model(p->world,
+ p->world->model,
+ p->plugin_uri->node,
+ p->world->uris.lv2_prototype,
+ NULL, NULL);
+ SordModel* skel = sord_new(p->world->world, SORD_SPO, false);
+ SordIter* iter = sord_begin(prototypes);
+ for (; !sord_iter_end(iter); sord_iter_next(iter)) {
+ const SordNode* t = sord_iter_get_node(iter, SORD_OBJECT);
LilvNode* prototype = lilv_node_new_from_node(p->world, t);
lilv_world_load_resource(p->world, prototype);
@@ -158,13 +161,22 @@ lilv_plugin_load(LilvPlugin* p)
SordQuad quad;
sord_iter_get(statements, quad);
quad[0] = p->plugin_uri->node;
- sord_add(p->world->model, quad);
+ sord_add(skel, quad);
}
sord_iter_free(statements);
lilv_node_free(prototype);
}
- sord_iter_free(prototypes);
+ sord_iter_free(iter);
+
+ for (iter = sord_begin(skel); !sord_iter_end(iter); sord_iter_next(iter)) {
+ SordQuad quad;
+ sord_iter_get(iter, quad);
+ sord_add(p->world->model, quad);
+ }
+ sord_iter_free(iter);
+ sord_free(skel);
+ sord_free(prototypes);
// Parse all the plugin's data files into RDF model
LILV_FOREACH(nodes, i, p->data_uris) {
diff --git a/src/world.c b/src/world.c
index 41fe16f..552cf2a 100644
--- a/src/world.c
+++ b/src/world.c
@@ -241,6 +241,25 @@ lilv_world_ask(LilvWorld* world,
world->model, subject->node, predicate->node, object->node, NULL);
}
+SordModel*
+lilv_world_filter_model(LilvWorld* world,
+ SordModel* model,
+ const SordNode* subject,
+ const SordNode* predicate,
+ const SordNode* object,
+ const SordNode* graph)
+{
+ SordModel* results = sord_new(world->world, SORD_SPO, false);
+ SordIter* i = sord_search(model, subject, predicate, object, graph);
+ for (; !sord_iter_end(i); sord_iter_next(i)) {
+ SordQuad quad;
+ sord_iter_get(i, quad);
+ sord_add(results, quad);
+ }
+ sord_iter_free(i);
+ return results;
+}
+
LilvNodes*
lilv_world_find_nodes_internal(LilvWorld* world,
const SordNode* subject,
@@ -508,6 +527,7 @@ lilv_world_load_dyn_manifest(LilvWorld* world,
rewind(fd);
// Parse generated data file
+ // FIXME
const SerdNode* base = sord_node_to_serd_node(dmanifest);
SerdEnv* env = serd_env_new(base);
SerdReader* reader = sord_new_reader(
@@ -606,15 +626,13 @@ static int
lilv_world_drop_graph(LilvWorld* world, LilvNode* graph)
{
SordIter* i = sord_search(world->model, NULL, NULL, NULL, graph->node);
-
while (!sord_iter_end(i)) {
- // Get quad and increment iter so sord_remove doesn't invalidate it
- SordQuad quad;
- sord_iter_get(i, quad);
- sord_iter_next(i);
-
- // Remove quad (nodes may now be deleted, quad is invalid)
- sord_remove(world->model, quad);
+ const SerdStatus st = sord_erase(world->model, i);
+ if (st) {
+ LILV_ERRORF("Error removing statement from <%s> (%s)\n",
+ lilv_node_as_uri(graph), serd_strerror(st));
+ return st;
+ }
}
sord_iter_free(i);
@@ -825,13 +843,16 @@ lilv_world_load_resource(LilvWorld* world,
return -1;
}
+ SordModel* files = lilv_world_filter_model(world,
+ world->model,
+ resource->node,
+ world->uris.rdfs_seeAlso,
+ NULL, NULL);
+
+ SordIter* f = sord_begin(files);
int n_read = 0;
- SordIter* files = sord_search(world->model,
- resource->node,
- world->uris.rdfs_seeAlso,
- NULL, NULL);
- FOREACH_MATCH(files) {
- const SordNode* file = sord_iter_get_node(files, SORD_OBJECT);
+ FOREACH_MATCH(f) {
+ const SordNode* file = sord_iter_get_node(f, SORD_OBJECT);
const uint8_t* file_str = sord_node_get_string(file);
LilvNode* file_node = lilv_node_new_from_node(world, file);
if (sord_node_get_type(file) != SORD_URI) {
@@ -841,8 +862,9 @@ lilv_world_load_resource(LilvWorld* world,
}
lilv_node_free(file_node);
}
- sord_iter_free(files);
+ sord_iter_free(f);
+ sord_free(files);
return n_read;
}
@@ -856,13 +878,16 @@ lilv_world_unload_resource(LilvWorld* world,
return -1;
}
+ SordModel* files = lilv_world_filter_model(world,
+ world->model,
+ resource->node,
+ world->uris.rdfs_seeAlso,
+ NULL, NULL);
+
+ SordIter* f = sord_begin(files);
int n_dropped = 0;
- SordIter* files = sord_search(world->model,
- resource->node,
- world->uris.rdfs_seeAlso,
- NULL, NULL);
- FOREACH_MATCH(files) {
- const SordNode* file = sord_iter_get_node(files, SORD_OBJECT);
+ FOREACH_MATCH(f) {
+ const SordNode* file = sord_iter_get_node(f, SORD_OBJECT);
LilvNode* file_node = lilv_node_new_from_node(world, file);
if (sord_node_get_type(file) != SORD_URI) {
LILV_ERRORF("rdfs:seeAlso node `%s' is not a URI\n",
@@ -873,8 +898,9 @@ lilv_world_unload_resource(LilvWorld* world,
}
lilv_node_free(file_node);
}
- sord_iter_free(files);
+ sord_iter_free(f);
+ sord_free(files);
return n_dropped;
}