summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorDavid Robillard <d@drobilla.net>2009-06-03 21:47:19 +0000
committerDavid Robillard <d@drobilla.net>2009-06-03 21:47:19 +0000
commit3ee5e87fc15363c104f08e61ba8ed0da76f97152 (patch)
tree983ddefeeb5194e0a86887244c6b12ddba38ab1d /src
parentc220a3ce918293855ed6b53b97dc604573fd031a (diff)
downloadlilv-3ee5e87fc15363c104f08e61ba8ed0da76f97152.tar.gz
lilv-3ee5e87fc15363c104f08e61ba8ed0da76f97152.tar.bz2
lilv-3ee5e87fc15363c104f08e61ba8ed0da76f97152.zip
Consistent error/warning message output.
Fix crash on invalid plugin files. git-svn-id: http://svn.drobilla.net/lad/trunk/slv2@2086 a436a847-0d15-0410-975c-d299462d15a1
Diffstat (limited to 'src')
-rw-r--r--src/collections.c2
-rw-r--r--src/plugin.c12
-rw-r--r--src/plugininstance.c14
-rw-r--r--src/pluginuiinstance.c12
-rw-r--r--src/query.c16
-rw-r--r--src/slv2_internal.h5
-rw-r--r--src/value.c4
-rw-r--r--src/world.c6
8 files changed, 31 insertions, 40 deletions
diff --git a/src/collections.c b/src/collections.c
index be4d898..337f0f6 100644
--- a/src/collections.c
+++ b/src/collections.c
@@ -53,7 +53,7 @@ prefix ## _size(CollType coll) \
ElemType \
prefix ## _get_at(CollType coll, unsigned index) \
{ \
- if (index > INT_MAX) \
+ if (!coll || index > INT_MAX) \
return NULL; \
else \
return (ElemType)raptor_sequence_get_at(coll, (int)index); \
diff --git a/src/plugin.c b/src/plugin.c
index baea5f5..6bc232a 100644
--- a/src/plugin.c
+++ b/src/plugin.c
@@ -153,8 +153,6 @@ slv2_plugin_load_ports_if_necessary(SLV2Plugin p)
const char* symbol = (const char*)librdf_node_get_literal_value(symbol_node);
const char* index = (const char*)librdf_node_get_literal_value(index_node);
- //printf("PORT: %s %s %s\n", type, index, symbol);
-
const int this_index = atoi(index);
SLV2Port this_port = NULL;
@@ -372,8 +370,7 @@ slv2_plugin_verify(SLV2Plugin plugin)
slv2_results_free(results);
if ( ! (has_type && has_name && has_license && has_port) ) {
- fprintf(stderr, "Invalid LV2 Plugin %s\n",
- slv2_value_as_uri(slv2_plugin_get_uri(plugin)));
+ SLV2_WARNF("Invalid plugin <%s>\n", slv2_value_as_uri(slv2_plugin_get_uri(plugin)));
return false;
} else {
return true;
@@ -400,6 +397,10 @@ slv2_plugin_get_name(SLV2Plugin plugin)
slv2_values_free(results);
}
+ if (!ret)
+ SLV2_WARNF("<%s> has no (mandatory) doap:name\n",
+ slv2_value_as_string(slv2_plugin_get_uri(plugin)));
+
return ret;
}
@@ -468,8 +469,7 @@ slv2_plugin_get_value_for_subject(SLV2Plugin p,
SLV2Value predicate)
{
if ( ! slv2_value_is_uri(subject)) {
- fprintf(stderr, "slv2_plugin_get_value_for_subject error: "
- "subject is not a URI\n");
+ SLV2_ERROR("slv2_plugin_get_value_for_subject: subject not a URI\n");
return NULL;
}
diff --git a/src/plugininstance.c b/src/plugininstance.c
index 26fd503..2089951 100644
--- a/src/plugininstance.c
+++ b/src/plugininstance.c
@@ -53,14 +53,14 @@ slv2_plugin_instantiate(SLV2Plugin plugin,
dlerror();
void* lib = dlopen(lib_path, RTLD_NOW);
if (!lib) {
- fprintf(stderr, "Unable to open library %s (%s)\n", lib_path, dlerror());
+ SLV2_ERRORF("Unable to open library %s (%s)\n", lib_path, dlerror());
return NULL;
}
LV2_Descriptor_Function df = dlsym(lib, "lv2_descriptor");
if (!df) {
- fprintf(stderr, "Could not find symbol 'lv2_descriptor', "
+ SLV2_ERRORF("Could not find symbol 'lv2_descriptor', "
"%s is not a LV2 plugin.\n", lib_path);
dlclose(lib);
return NULL;
@@ -71,24 +71,17 @@ slv2_plugin_instantiate(SLV2Plugin plugin,
const char* bundle_path = slv2_uri_to_path(slv2_value_as_uri(
slv2_plugin_get_bundle_uri(plugin)));
- //printf("Bundle path: %s\n", bundle_path);
-
for (uint32_t i=0; 1; ++i) {
const LV2_Descriptor* ld = df(i);
if (!ld) {
- fprintf(stderr, "Did not find plugin %s in %s\n",
+ SLV2_ERRORF("Did not find plugin %s in %s\n",
slv2_value_as_uri(slv2_plugin_get_uri(plugin)), lib_path);
dlclose(lib);
break; // return NULL
} else if (!strcmp(ld->URI, slv2_value_as_uri(slv2_plugin_get_uri(plugin)))) {
-
assert(plugin->plugin_uri);
-
- //printf("Found %s at index %u in:\n\t%s\n\n",
- // librdf_uri_as_string(plugin->plugin_uri), i, lib_path);
-
assert(ld->instantiate);
// Create SLV2Instance to return
@@ -110,7 +103,6 @@ slv2_plugin_instantiate(SLV2Plugin plugin,
// Failed to instantiate
if (result->lv2_handle == NULL) {
- //printf("Failed to instantiate %s\n", plugin->plugin_uri);
free(result);
return NULL;
}
diff --git a/src/pluginuiinstance.c b/src/pluginuiinstance.c
index 2c59537..cc53d53 100644
--- a/src/pluginuiinstance.c
+++ b/src/pluginuiinstance.c
@@ -56,14 +56,14 @@ slv2_ui_instantiate(SLV2Plugin plugin,
dlerror();
void* lib = dlopen(lib_path, RTLD_NOW);
if (!lib) {
- fprintf(stderr, "Unable to open UI library %s (%s)\n", lib_path, dlerror());
+ SLV2_ERRORF("Unable to open UI library %s (%s)\n", lib_path, dlerror());
return NULL;
}
LV2UI_DescriptorFunction df = dlsym(lib, "lv2ui_descriptor");
if (!df) {
- fprintf(stderr, "Could not find symbol 'lv2ui_descriptor', "
+ SLV2_ERRORF("Could not find symbol 'lv2ui_descriptor', "
"%s is not a LV2 plugin UI.\n", lib_path);
dlclose(lib);
return NULL;
@@ -76,17 +76,12 @@ slv2_ui_instantiate(SLV2Plugin plugin,
const LV2UI_Descriptor* ld = df(i);
if (!ld) {
- fprintf(stderr, "Did not find UI %s in %s\n",
+ SLV2_ERRORF("Did not find UI %s in %s\n",
slv2_value_as_uri(slv2_ui_get_uri(ui)), lib_path);
dlclose(lib);
break; // return NULL
} else if (!strcmp(ld->URI, slv2_value_as_uri(slv2_ui_get_uri(ui)))) {
-
assert(plugin->plugin_uri);
-
- printf("Found UI %s at index %u in:\n\t%s\n\n",
- slv2_value_as_uri(plugin->plugin_uri), i, lib_path);
-
assert(ld->instantiate);
// Create SLV2UIInstance to return
@@ -110,7 +105,6 @@ slv2_ui_instantiate(SLV2Plugin plugin,
// Failed to instantiate
if (result == NULL || result->pimpl->lv2ui_handle == NULL) {
- //printf("Failed to instantiate %s\n", plugin->plugin_uri);
free(result);
return NULL;
}
diff --git a/src/query.c b/src/query.c
index 7176f35..ee709cb 100644
--- a/src/query.c
+++ b/src/query.c
@@ -64,7 +64,7 @@ slv2_value_from_librdf_node(SLV2World world, librdf_node* node)
"http://www.w3.org/2001/XMLSchema#decimal"))
type = SLV2_VALUE_FLOAT;
else
- fprintf(stderr, "Unknown datatype %s\n", librdf_uri_as_string(datatype_uri));
+ SLV2_ERRORF("Unknown datatype %s\n", librdf_uri_as_string(datatype_uri));
}
result = slv2_value_new(world, type, (const char*)librdf_node_get_literal_value(node));
break;
@@ -74,7 +74,7 @@ slv2_value_from_librdf_node(SLV2World world, librdf_node* node)
break;
case LIBRDF_NODE_TYPE_UNKNOWN:
default:
- fprintf(stderr, "Unknown RDF node type %d\n", librdf_node_get_type(node));
+ SLV2_ERRORF("Unknown RDF node type %d\n", librdf_node_get_type(node));
break;
}
@@ -96,7 +96,7 @@ slv2_query_get_variable_bindings(SLV2World world,
librdf_node* node = librdf_query_results_get_binding_value(results->rdf_results, variable);
if (node == NULL) {
- fprintf(stderr, "SLV2 ERROR: Variable %d bound to NULL.\n", variable);
+ SLV2_ERRORF("Variable %d bound to NULL.\n", variable);
librdf_query_results_next(results->rdf_results);
continue;
}
@@ -137,21 +137,21 @@ slv2_plugin_query_sparql(SLV2Plugin plugin,
char* query_str = slv2_strjoin(slv2_query_prefixes, sparql_str, NULL);
- //printf("******** Query \n%s********\n", query_str);
-
librdf_query* query = librdf_new_query(plugin->world->world, "sparql", NULL,
(const unsigned char*)query_str, base_uri);
if (!query) {
- fprintf(stderr, "ERROR: Could not create query\n");
+ SLV2_ERRORF("Failed to create query:\n%s", query_str);
return NULL;
}
- // FIXME: locale kludges to work around librdf bug
+ // Reset numeric locale to correctly interpret turtle numeric constants
char* locale = strdup(setlocale(LC_NUMERIC, NULL));
-
setlocale(LC_NUMERIC, "POSIX");
+
librdf_query_results* results = librdf_query_execute(query, plugin->rdf);
+
+ // Restore numeric locale
setlocale(LC_NUMERIC, locale);
free(locale);
diff --git a/src/slv2_internal.h b/src/slv2_internal.h
index a24570f..b4b23b3 100644
--- a/src/slv2_internal.h
+++ b/src/slv2_internal.h
@@ -240,6 +240,11 @@ struct _SLV2Results {
char* slv2_strjoin(const char* first, ...);
char* slv2_get_lang();
+#define SLV2_ERROR(str) fprintf(stderr, "ERROR: %s: " str, __func__)
+#define SLV2_ERRORF(fmt, ...) fprintf(stderr, "ERROR: %s: " fmt, __func__, __VA_ARGS__)
+
+#define SLV2_WARN(str) fprintf(stderr, "WARNING: %s: " str, __func__)
+#define SLV2_WARNF(fmt, ...) fprintf(stderr, "WARNING: %s: " fmt, __func__, __VA_ARGS__)
#ifdef __cplusplus
}
diff --git a/src/value.c b/src/value.c
index ed2f95a..3ef7542 100644
--- a/src/value.c
+++ b/src/value.c
@@ -96,14 +96,14 @@ slv2_value_new_librdf_node(SLV2World world, librdf_node* node)
else if (librdf_uri_equals(datatype_uri, librdf_node_get_uri(world->xsd_decimal_node)))
val->type = SLV2_VALUE_FLOAT;
else
- fprintf(stderr, "Unknown datatype %s\n", librdf_uri_as_string(datatype_uri));
+ SLV2_ERRORF("Unknown datatype %s\n", librdf_uri_as_string(datatype_uri));
}
val->str_val = strdup((char*)librdf_node_get_literal_value(node));
break;
case LIBRDF_NODE_TYPE_BLANK:
case LIBRDF_NODE_TYPE_UNKNOWN:
default:
- fprintf(stderr, "slv2_value_new_librdf_node error: Unknown node type.");
+ SLV2_ERROR("Unknown node type");
free(val);
val = NULL;
break;
diff --git a/src/world.c b/src/world.c
index 5b0d25a..bd38fd2 100644
--- a/src/world.c
+++ b/src/world.c
@@ -44,8 +44,8 @@ slv2_world_new_internal(SLV2World world)
world->storage = librdf_new_storage(world->world, "trees", NULL, NULL);
if (!world->storage) {
- fprintf(stderr, "Warning: Unable to create \"trees\" RDF storage.\n"
- "Performance can be improved by upgrading librdf.\n");
+ SLV2_WARN("Warning: Unable to create \"trees\" RDF storage.\n"
+ "Performance can be improved by upgrading librdf.\n");
world->storage = librdf_new_storage(world->world, "hashes", NULL,
"hash-type='memory'");
}
@@ -177,7 +177,7 @@ void
slv2_world_load_bundle(SLV2World world, SLV2Value bundle_uri)
{
if (!slv2_value_is_uri(bundle_uri)) {
- fprintf(stderr, "ERROR: slv2_world_load_bundle called with non-URI argument\n");
+ SLV2_ERROR("Bundle 'URI' is not a URI\n");
return;
}