summaryrefslogtreecommitdiffstats
path: root/src/value.c
diff options
context:
space:
mode:
authorDavid Robillard <d@drobilla.net>2008-12-13 05:47:50 +0000
committerDavid Robillard <d@drobilla.net>2008-12-13 05:47:50 +0000
commit90885da36afd20388a6eeeb58efcd844398bc531 (patch)
treea5cce42b5bae93d1c910a8a12af3d927bd8d114e /src/value.c
parentbaa2354cf47b093117206fd1fc1bae45e46b03c3 (diff)
downloadlilv-90885da36afd20388a6eeeb58efcd844398bc531.tar.gz
lilv-90885da36afd20388a6eeeb58efcd844398bc531.tar.bz2
lilv-90885da36afd20388a6eeeb58efcd844398bc531.zip
Handle librdf failures (NULL values) and crazily typed values etc. more gracefully.
git-svn-id: http://svn.drobilla.net/lad/trunk/slv2@1860 a436a847-0d15-0410-975c-d299462d15a1
Diffstat (limited to 'src/value.c')
-rw-r--r--src/value.c57
1 files changed, 26 insertions, 31 deletions
diff --git a/src/value.c b/src/value.c
index 08c27e5..ba39754 100644
--- a/src/value.c
+++ b/src/value.c
@@ -28,35 +28,9 @@
/* private */
-SLV2Value
-slv2_value_new(SLV2World world, SLV2ValueType type, const char* str)
-{
- SLV2Value val = (SLV2Value)malloc(sizeof(struct _SLV2Value));
- val->type = type;
-
- if (type == SLV2_VALUE_URI) {
- val->val.uri_val = librdf_new_uri(world->world, (const unsigned char*)str);
- if (val->val.uri_val)
- val->str_val = (char*)librdf_uri_as_string(val->val.uri_val);
- else
- return NULL;
- } else {
- val->str_val = strdup(str);
- }
-
- slv2_value_set_numerics_from_string(val);
-
- return val;
-}
-
-
-/* private */
-void
+static void
slv2_value_set_numerics_from_string(SLV2Value val)
{
- if (!val)
- return;
-
// FIXME: locale kludges to work around librdf bug
char* locale = strdup(setlocale(LC_NUMERIC, NULL));
@@ -78,6 +52,27 @@ slv2_value_set_numerics_from_string(SLV2Value val)
/* private */
SLV2Value
+slv2_value_new(SLV2World world, SLV2ValueType type, const char* str)
+{
+ SLV2Value val = (SLV2Value)malloc(sizeof(struct _SLV2Value));
+ val->type = type;
+
+ if (type == SLV2_VALUE_URI) {
+ val->val.uri_val = librdf_new_uri(world->world, (const unsigned char*)str);
+ assert(val->val.uri_val);
+ val->str_val = (char*)librdf_uri_as_string(val->val.uri_val);
+ } else {
+ val->str_val = strdup(str);
+ }
+
+ slv2_value_set_numerics_from_string(val);
+
+ return val;
+}
+
+
+/* private */
+SLV2Value
slv2_value_new_librdf_node(SLV2World world, librdf_node* node)
{
SLV2Value val = (SLV2Value)malloc(sizeof(struct _SLV2Value));
@@ -113,7 +108,9 @@ slv2_value_new_librdf_node(SLV2World world, librdf_node* node)
break;
}
- slv2_value_set_numerics_from_string(val);
+ if (val)
+ slv2_value_set_numerics_from_string(val);
+
return val;
}
@@ -122,9 +119,7 @@ slv2_value_new_librdf_node(SLV2World world, librdf_node* node)
SLV2Value
slv2_value_new_librdf_uri(SLV2World world, librdf_uri* uri)
{
- if (!uri)
- return NULL;
-
+ assert(uri);
SLV2Value val = (SLV2Value)malloc(sizeof(struct _SLV2Value));
val->type = SLV2_VALUE_URI;
val->val.uri_val = librdf_new_uri_from_uri(uri);