diff options
-rw-r--r-- | src/lilv_internal.h | 8 | ||||
-rw-r--r-- | src/plugin.c | 28 | ||||
-rw-r--r-- | src/world.c | 70 | ||||
-rw-r--r-- | test/lilv_test.c | 1 | ||||
-rw-r--r-- | wscript | 2 |
5 files changed, 78 insertions, 31 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; } diff --git a/test/lilv_test.c b/test/lilv_test.c index 52d4113..6d652c1 100644 --- a/test/lilv_test.c +++ b/test/lilv_test.c @@ -159,6 +159,7 @@ cleanup(void) #define TEST_ASSERT(check) do {\ test_count++;\ if (!(check)) {\ + assert(false);\ error_count++;\ fprintf(stderr, "lilv_test.c:%d: error: %s\n", __LINE__, #check);\ }\ @@ -80,7 +80,7 @@ def configure(conf): autowaf.check_pkg(conf, 'serd-0', uselib_store='SERD', atleast_version='0.14.0', mandatory=True) autowaf.check_pkg(conf, 'sord-0', uselib_store='SORD', - atleast_version='0.12.0', mandatory=True) + atleast_version='0.13.0', mandatory=True) autowaf.check_pkg(conf, 'sratom-0', uselib_store='SRATOM', atleast_version='0.4.0', mandatory=True) |