Changeset 2086

Show
Ignore:
Timestamp:
06/03/09 14:47:19 (9 months ago)
Author:
drobilla
Message:

Consistent error/warning message output.
Fix crash on invalid plugin files.

Location:
trunk/slv2
Files:
9 modified

Legend:

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

    r2000 r2086  
    5454prefix ## _get_at(CollType coll, unsigned index) \ 
    5555{ \ 
    56         if (index > INT_MAX) \ 
     56        if (!coll || index > INT_MAX) \ 
    5757                return NULL; \ 
    5858        else \ 
  • trunk/slv2/src/plugin.c

    r2085 r2086  
    154154                        const char* index = (const char*)librdf_node_get_literal_value(index_node); 
    155155 
    156                         //printf("PORT: %s %s %s\n", type, index, symbol); 
    157  
    158156                        const int this_index = atoi(index); 
    159157                        SLV2Port  this_port  = NULL; 
     
    373371 
    374372        if ( ! (has_type && has_name && has_license && has_port) ) { 
    375                 fprintf(stderr, "Invalid LV2 Plugin %s\n", 
    376                                 slv2_value_as_uri(slv2_plugin_get_uri(plugin))); 
     373                SLV2_WARNF("Invalid plugin <%s>\n", slv2_value_as_uri(slv2_plugin_get_uri(plugin))); 
    377374                return false; 
    378375        } else { 
     
    401398        } 
    402399 
     400        if (!ret) 
     401                SLV2_WARNF("<%s> has no (mandatory) doap:name\n", 
     402                                slv2_value_as_string(slv2_plugin_get_uri(plugin))); 
     403 
    403404        return ret; 
    404405} 
     
    469470{ 
    470471        if ( ! slv2_value_is_uri(subject)) { 
    471                 fprintf(stderr, "slv2_plugin_get_value_for_subject error: " 
    472                                 "subject is not a URI\n"); 
     472                SLV2_ERROR("slv2_plugin_get_value_for_subject: subject not a URI\n"); 
    473473                return NULL; 
    474474        } 
  • trunk/slv2/src/plugininstance.c

    r2000 r2086  
    5454        void* lib = dlopen(lib_path, RTLD_NOW); 
    5555        if (!lib) { 
    56                 fprintf(stderr, "Unable to open library %s (%s)\n", lib_path, dlerror()); 
     56                SLV2_ERRORF("Unable to open library %s (%s)\n", lib_path, dlerror()); 
    5757                return NULL; 
    5858        } 
     
    6161 
    6262        if (!df) { 
    63                 fprintf(stderr, "Could not find symbol 'lv2_descriptor', " 
     63                SLV2_ERRORF("Could not find symbol 'lv2_descriptor', " 
    6464                                "%s is not a LV2 plugin.\n", lib_path); 
    6565                dlclose(lib); 
     
    7272                                        slv2_plugin_get_bundle_uri(plugin))); 
    7373 
    74                 //printf("Bundle path: %s\n", bundle_path); 
    75  
    7674                for (uint32_t i=0; 1; ++i) { 
    7775 
     
    7977 
    8078                        if (!ld) { 
    81                                 fprintf(stderr, "Did not find plugin %s in %s\n", 
     79                                SLV2_ERRORF("Did not find plugin %s in %s\n", 
    8280                                                slv2_value_as_uri(slv2_plugin_get_uri(plugin)), lib_path); 
    8381                                dlclose(lib); 
    8482                                break; // return NULL 
    8583                        } else if (!strcmp(ld->URI, slv2_value_as_uri(slv2_plugin_get_uri(plugin)))) { 
    86  
    8784                                assert(plugin->plugin_uri); 
    88  
    89                                 //printf("Found %s at index %u in:\n\t%s\n\n", 
    90                                 //              librdf_uri_as_string(plugin->plugin_uri), i, lib_path); 
    91  
    9285                                assert(ld->instantiate); 
    9386 
     
    111104                // Failed to instantiate 
    112105                if (result->lv2_handle == NULL) { 
    113                         //printf("Failed to instantiate %s\n", plugin->plugin_uri); 
    114106                        free(result); 
    115107                        return NULL; 
  • trunk/slv2/src/pluginuiinstance.c

    r2000 r2086  
    5757        void* lib = dlopen(lib_path, RTLD_NOW); 
    5858        if (!lib) { 
    59                 fprintf(stderr, "Unable to open UI library %s (%s)\n", lib_path, dlerror()); 
     59                SLV2_ERRORF("Unable to open UI library %s (%s)\n", lib_path, dlerror()); 
    6060                return NULL; 
    6161        } 
     
    6464 
    6565        if (!df) { 
    66                 fprintf(stderr, "Could not find symbol 'lv2ui_descriptor', " 
     66                SLV2_ERRORF("Could not find symbol 'lv2ui_descriptor', " 
    6767                                "%s is not a LV2 plugin UI.\n", lib_path); 
    6868                dlclose(lib); 
     
    7777 
    7878                        if (!ld) { 
    79                                 fprintf(stderr, "Did not find UI %s in %s\n", 
     79                                SLV2_ERRORF("Did not find UI %s in %s\n", 
    8080                                                slv2_value_as_uri(slv2_ui_get_uri(ui)), lib_path); 
    8181                                dlclose(lib); 
    8282                                break; // return NULL 
    8383                        } else if (!strcmp(ld->URI, slv2_value_as_uri(slv2_ui_get_uri(ui)))) { 
    84  
    8584                                assert(plugin->plugin_uri); 
    86  
    87                                 printf("Found UI %s at index %u in:\n\t%s\n\n", 
    88                                        slv2_value_as_uri(plugin->plugin_uri), i, lib_path); 
    89  
    9085                                assert(ld->instantiate); 
    9186 
     
    111106        // Failed to instantiate 
    112107        if (result == NULL || result->pimpl->lv2ui_handle == NULL) { 
    113                 //printf("Failed to instantiate %s\n", plugin->plugin_uri); 
    114108                free(result); 
    115109                return NULL; 
  • trunk/slv2/src/query.c

    r2007 r2086  
    6565                                type = SLV2_VALUE_FLOAT; 
    6666                        else 
    67                                 fprintf(stderr, "Unknown datatype %s\n", librdf_uri_as_string(datatype_uri)); 
     67                                SLV2_ERRORF("Unknown datatype %s\n", librdf_uri_as_string(datatype_uri)); 
    6868                } 
    6969                result = slv2_value_new(world, type, (const char*)librdf_node_get_literal_value(node)); 
     
    7575        case LIBRDF_NODE_TYPE_UNKNOWN: 
    7676        default: 
    77                 fprintf(stderr, "Unknown RDF node type %d\n", librdf_node_get_type(node)); 
     77                SLV2_ERRORF("Unknown RDF node type %d\n", librdf_node_get_type(node)); 
    7878                break; 
    7979        } 
     
    9797 
    9898                if (node == NULL) { 
    99                         fprintf(stderr, "SLV2 ERROR: Variable %d bound to NULL.\n", variable); 
     99                        SLV2_ERRORF("Variable %d bound to NULL.\n", variable); 
    100100                        librdf_query_results_next(results->rdf_results); 
    101101                        continue; 
     
    138138        char* query_str = slv2_strjoin(slv2_query_prefixes, sparql_str, NULL); 
    139139 
    140         //printf("******** Query \n%s********\n", query_str); 
    141  
    142140        librdf_query* query = librdf_new_query(plugin->world->world, "sparql", NULL, 
    143141                        (const unsigned char*)query_str, base_uri); 
    144142 
    145143        if (!query) { 
    146                 fprintf(stderr, "ERROR: Could not create query\n"); 
     144                SLV2_ERRORF("Failed to create query:\n%s", query_str); 
    147145                return NULL; 
    148146        } 
    149147 
    150         // FIXME: locale kludges to work around librdf bug 
     148        // Reset numeric locale to correctly interpret turtle numeric constants 
    151149        char* locale = strdup(setlocale(LC_NUMERIC, NULL)); 
    152  
    153150        setlocale(LC_NUMERIC, "POSIX"); 
     151 
    154152        librdf_query_results* results = librdf_query_execute(query, plugin->rdf); 
     153 
     154        // Restore numeric locale 
    155155        setlocale(LC_NUMERIC, locale); 
    156156 
  • trunk/slv2/src/slv2_internal.h

    r2000 r2086  
    241241char* slv2_get_lang(); 
    242242 
     243#define SLV2_ERROR(str)       fprintf(stderr, "ERROR: %s: " str, __func__) 
     244#define SLV2_ERRORF(fmt, ...) fprintf(stderr, "ERROR: %s: " fmt, __func__, __VA_ARGS__) 
     245 
     246#define SLV2_WARN(str) fprintf(stderr, "WARNING: %s: " str, __func__) 
     247#define SLV2_WARNF(fmt, ...) fprintf(stderr, "WARNING: %s: " fmt, __func__, __VA_ARGS__) 
    243248 
    244249#ifdef __cplusplus 
  • trunk/slv2/src/value.c

    r2007 r2086  
    9797                                val->type = SLV2_VALUE_FLOAT; 
    9898                        else 
    99                                 fprintf(stderr, "Unknown datatype %s\n", librdf_uri_as_string(datatype_uri)); 
     99                                SLV2_ERRORF("Unknown datatype %s\n", librdf_uri_as_string(datatype_uri)); 
    100100                } 
    101101                val->str_val = strdup((char*)librdf_node_get_literal_value(node)); 
     
    104104        case LIBRDF_NODE_TYPE_UNKNOWN: 
    105105        default: 
    106                 fprintf(stderr, "slv2_value_new_librdf_node error: Unknown node type."); 
     106                SLV2_ERROR("Unknown node type"); 
    107107                free(val); 
    108108                val = NULL; 
  • trunk/slv2/src/world.c

    r2085 r2086  
    4545        world->storage = librdf_new_storage(world->world, "trees", NULL, NULL); 
    4646        if (!world->storage) { 
    47                 fprintf(stderr, "Warning: Unable to create \"trees\" RDF storage.\n" 
    48                                 "Performance can be improved by upgrading librdf.\n"); 
     47                SLV2_WARN("Warning: Unable to create \"trees\" RDF storage.\n" 
     48                                "Performance can be improved by upgrading librdf.\n"); 
    4949                world->storage = librdf_new_storage(world->world, "hashes", NULL, 
    5050                                "hash-type='memory'"); 
     
    178178{ 
    179179        if (!slv2_value_is_uri(bundle_uri)) { 
    180                 fprintf(stderr, "ERROR: slv2_world_load_bundle called with non-URI argument\n"); 
     180                SLV2_ERROR("Bundle 'URI' is not a URI\n"); 
    181181                return; 
    182182        } 
  • trunk/slv2/utils/lv2_inspect.c

    r2000 r2086  
    103103 
    104104        val = slv2_plugin_get_name(p); 
    105         printf("\tName:              %s\n", slv2_value_as_string(val)); 
    106         slv2_value_free(val); 
     105        if (val) { 
     106                printf("\tName:              %s\n", slv2_value_as_string(val)); 
     107                slv2_value_free(val); 
     108        } 
    107109 
    108110        SLV2Value class_label = slv2_plugin_class_get_label(slv2_plugin_get_class(p)); 
    109         printf("\tClass:             %s\n", slv2_value_as_string(class_label)); 
     111        if (class_label) { 
     112                printf("\tClass:             %s\n", slv2_value_as_string(class_label)); 
     113        } 
    110114 
    111115        val = slv2_plugin_get_author_name(p);