summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorDavid Robillard <d@drobilla.net>2009-06-03 22:07:02 +0000
committerDavid Robillard <d@drobilla.net>2009-06-03 22:07:02 +0000
commitc68a20ee1fca5d6c076d0f754653f48f508279d0 (patch)
tree5129e1288d1a09e773756124b69b957d46bc79e4 /src
parent3ee5e87fc15363c104f08e61ba8ed0da76f97152 (diff)
downloadlilv-c68a20ee1fca5d6c076d0f754653f48f508279d0.tar.gz
lilv-c68a20ee1fca5d6c076d0f754653f48f508279d0.tar.bz2
lilv-c68a20ee1fca5d6c076d0f754653f48f508279d0.zip
Tolerate lv2_inspect of broken plugins with illegal ports.
Shave some overhead from port loading. git-svn-id: http://svn.drobilla.net/lad/trunk/slv2@2087 a436a847-0d15-0410-975c-d299462d15a1
Diffstat (limited to 'src')
-rw-r--r--src/plugin.c40
1 files changed, 11 insertions, 29 deletions
diff --git a/src/plugin.c b/src/plugin.c
index 6bc232a..21239f3 100644
--- a/src/plugin.c
+++ b/src/plugin.c
@@ -131,48 +131,31 @@ slv2_plugin_load_ports_if_necessary(SLV2Plugin p)
"?port a ?type ;\n"
" :symbol ?symbol ;\n"
" :index ?index .\n"
- "} ORDER BY (?index)";
+ "}";
librdf_query* q = librdf_new_query(p->world->world, "sparql",
NULL, query, slv2_value_as_librdf_uri(p->plugin_uri));
librdf_query_results* results = librdf_query_execute(q, p->rdf);
- int num_ports = 0;
- int last_index = -1;
-
while (!librdf_query_results_finished(results)) {
-
librdf_node* type_node = librdf_query_results_get_binding_value(results, 0);
librdf_node* symbol_node = librdf_query_results_get_binding_value(results, 1);
librdf_node* index_node = librdf_query_results_get_binding_value(results, 2);
- assert(librdf_node_is_literal(symbol_node));
- assert(librdf_node_is_literal(index_node));
-
- const char* symbol = (const char*)librdf_node_get_literal_value(symbol_node);
- const char* index = (const char*)librdf_node_get_literal_value(index_node);
-
- const int this_index = atoi(index);
- SLV2Port this_port = NULL;
+ if (librdf_node_is_literal(symbol_node) &&librdf_node_is_literal(index_node)) {
+ const char* symbol = (const char*)librdf_node_get_literal_value(symbol_node);
+ const char* index = (const char*)librdf_node_get_literal_value(index_node);
- // ORDER BY guarantees order
- assert(this_index <= num_ports);
+ const int this_index = atoi(index);
+ SLV2Port this_port = raptor_sequence_get_at(p->ports, this_index);
- // Create a new SLV2Port, and add to template
- if (this_index == num_ports) {
- assert(this_index == last_index + 1);
- this_port = slv2_port_new(p->world, (unsigned)atoi(index), symbol);
- raptor_sequence_push(p->ports, this_port);
- ++num_ports;
- ++last_index;
-
- // More information about a port we already created
- } else if (this_index < num_ports) {
- this_port = slv2_plugin_get_port_by_index(p, this_index);
- }
+ // Havn't seen this port yet, add it to sequence
+ if (!this_port) {
+ this_port = slv2_port_new(p->world, this_index, symbol);
+ raptor_sequence_set_at(p->ports, this_index, this_port);
+ }
- if (this_port) {
raptor_sequence_push(this_port->classes,
slv2_value_new_librdf_uri(p->world, librdf_node_get_uri(type_node)));
}
@@ -180,7 +163,6 @@ slv2_plugin_load_ports_if_necessary(SLV2Plugin p)
librdf_free_node(type_node);
librdf_free_node(symbol_node);
librdf_free_node(index_node);
-
librdf_query_results_next(results);
}