Changeset 2087

Show
Ignore:
Timestamp:
06/03/09 15:07:02 (15 months ago)
Author:
drobilla
Message:

Tolerate lv2_inspect of broken plugins with illegal ports.
Shave some overhead from port loading.

Location:
trunk/slv2
Files:
2 modified

Legend:

Unmodified
Added
Removed
  • trunk/slv2/src/plugin.c

    r2086 r2087  
    132132                        "      :symbol  ?symbol ;\n" 
    133133                        "      :index   ?index .\n" 
    134                         "} ORDER BY (?index)"; 
     134                        "}"; 
    135135 
    136136                librdf_query* q = librdf_new_query(p->world->world, "sparql", 
     
    139139                librdf_query_results* results = librdf_query_execute(q, p->rdf); 
    140140 
    141                 int num_ports  = 0; 
    142                 int last_index = -1; 
    143  
    144141                while (!librdf_query_results_finished(results)) { 
    145  
    146142                        librdf_node* type_node = librdf_query_results_get_binding_value(results, 0); 
    147143                        librdf_node* symbol_node = librdf_query_results_get_binding_value(results, 1); 
    148144                        librdf_node* index_node = librdf_query_results_get_binding_value(results, 2); 
    149145 
    150                         assert(librdf_node_is_literal(symbol_node)); 
    151                         assert(librdf_node_is_literal(index_node)); 
    152  
    153                         const char* symbol = (const char*)librdf_node_get_literal_value(symbol_node); 
    154                         const char* index = (const char*)librdf_node_get_literal_value(index_node); 
    155  
    156                         const int this_index = atoi(index); 
    157                         SLV2Port  this_port  = NULL; 
    158  
    159                         // ORDER BY guarantees order 
    160                         assert(this_index <= num_ports); 
    161  
    162                         // Create a new SLV2Port, and add to template 
    163                         if (this_index == num_ports) { 
    164                                 assert(this_index == last_index + 1); 
    165                                 this_port = slv2_port_new(p->world, (unsigned)atoi(index), symbol); 
    166                                 raptor_sequence_push(p->ports, this_port); 
    167                                 ++num_ports; 
    168                                 ++last_index; 
    169  
    170                         // More information about a port we already created 
    171                         } else if (this_index < num_ports) { 
    172                                 this_port = slv2_plugin_get_port_by_index(p, this_index); 
    173                         } 
    174  
    175                         if (this_port) { 
     146                        if (librdf_node_is_literal(symbol_node) &&librdf_node_is_literal(index_node)) { 
     147                                const char* symbol = (const char*)librdf_node_get_literal_value(symbol_node); 
     148                                const char* index = (const char*)librdf_node_get_literal_value(index_node); 
     149 
     150                                const int this_index = atoi(index); 
     151                                SLV2Port  this_port  = raptor_sequence_get_at(p->ports, this_index); 
     152 
     153                                // Havn't seen this port yet, add it to sequence 
     154                                if (!this_port) { 
     155                                        this_port = slv2_port_new(p->world, this_index, symbol); 
     156                                        raptor_sequence_set_at(p->ports, this_index, this_port); 
     157                                } 
     158 
    176159                                raptor_sequence_push(this_port->classes, 
    177160                                                slv2_value_new_librdf_uri(p->world, librdf_node_get_uri(type_node))); 
     
    181164                        librdf_free_node(symbol_node); 
    182165                        librdf_free_node(index_node); 
    183  
    184166                        librdf_query_results_next(results); 
    185167                } 
  • trunk/slv2/utils/lv2_inspect.c

    r2086 r2087  
    3535        printf("\n\tPort %d:\n", index); 
    3636 
     37        if (!port) { 
     38                printf("\t\tERROR: Illegal/nonexistent port\n"); 
     39                return; 
     40        } 
     41 
    3742        SLV2Values classes = slv2_port_get_classes(p, port); 
    3843