From b760711088bb027d7c84eec7c19360d8f02680ec Mon Sep 17 00:00:00 2001 From: David Robillard Date: Mon, 19 Dec 2011 03:04:05 +0000 Subject: Remove locale smashing kludges and use new serd functions for converting nodes to/from numbers. git-svn-id: http://svn.drobilla.net/lad/trunk/lilv@3891 a436a847-0d15-0410-975c-d299462d15a1 --- ChangeLog | 2 ++ src/node.c | 41 ++++++++--------------------------------- utils/lv2info.c | 2 -- wscript | 2 ++ 4 files changed, 12 insertions(+), 35 deletions(-) diff --git a/ChangeLog b/ChangeLog index 3f8e5e2..e582776 100644 --- a/ChangeLog +++ b/ChangeLog @@ -14,6 +14,8 @@ lilv (UNRELEASED) unstable; urgency=low are not directly rdfs:seeAlso linked (e.g. presets) * Add lilv_world_load_resource for related resources (e.g. presets) * Print presets in lv2info + * Remove locale smashing kludges and use new serd functions for converting + nodes to/from numbers. -- David Robillard (UNRELEASED) diff --git a/src/node.c b/src/node.c index dc018c8..3dc4ace 100644 --- a/src/node.c +++ b/src/node.c @@ -15,7 +15,6 @@ */ #include -#include #include #include @@ -24,7 +23,6 @@ static void lilv_node_set_numerics_from_string(LilvNode* val) { - char* locale; char* endptr; switch (val->type) { @@ -33,20 +31,10 @@ lilv_node_set_numerics_from_string(LilvNode* val) case LILV_VALUE_STRING: break; case LILV_VALUE_INT: - // FIXME: locale kludge, need a locale independent strtol - locale = lilv_strdup(setlocale(LC_NUMERIC, NULL)); - setlocale(LC_NUMERIC, "POSIX"); val->val.int_val = strtol(val->str_val, &endptr, 10); - setlocale(LC_NUMERIC, locale); - free(locale); break; case LILV_VALUE_FLOAT: - // FIXME: locale kludge, need a locale independent strtod - locale = lilv_strdup(setlocale(LC_NUMERIC, NULL)); - setlocale(LC_NUMERIC, "POSIX"); - val->val.float_val = strtod(val->str_val, &endptr); - setlocale(LC_NUMERIC, locale); - free(locale); + val->val.float_val = serd_strtod(val->str_val, &endptr); break; case LILV_VALUE_BOOL: val->val.bool_val = (!strcmp(val->str_val, "true")); @@ -258,9 +246,9 @@ LILV_API char* lilv_node_get_turtle_token(const LilvNode* value) { - size_t len = 0; - char* result = NULL; - char* locale = NULL; + size_t len = 0; + char* result = NULL; + SerdNode node; switch (value->type) { case LILV_VALUE_URI: @@ -278,28 +266,15 @@ lilv_node_get_turtle_token(const LilvNode* value) result = lilv_strdup(value->str_val); break; case LILV_VALUE_INT: - // INT64_MAX is 9223372036854775807 (19 digits) + 1 for sign - // FIXME: locale kludge, need a locale independent snprintf - locale = lilv_strdup(setlocale(LC_NUMERIC, NULL)); - len = 20; - result = calloc(len, 1); - setlocale(LC_NUMERIC, "POSIX"); - snprintf(result, len, "%d", value->val.int_val); - setlocale(LC_NUMERIC, locale); + node = serd_node_new_integer(value->val.int_val); + result = (char*)node.buf; break; case LILV_VALUE_FLOAT: - // FIXME: locale kludge, need a locale independent snprintf - locale = lilv_strdup(setlocale(LC_NUMERIC, NULL)); - len = 20; // FIXME: proper maximum value? - result = calloc(len, 1); - setlocale(LC_NUMERIC, "POSIX"); - snprintf(result, len, "%f", value->val.float_val); - setlocale(LC_NUMERIC, locale); + node = serd_node_new_decimal(value->val.float_val, 8); + result = (char*)node.buf; break; } - free(locale); - return result; } diff --git a/utils/lv2info.c b/utils/lv2info.c index 7f231f3..e152bfe 100644 --- a/utils/lv2info.c +++ b/utils/lv2info.c @@ -14,7 +14,6 @@ OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. */ -#include #include #include #include @@ -378,7 +377,6 @@ main(int argc, char** argv) } int ret = 0; - setlocale(LC_ALL, ""); LilvWorld* world = lilv_world_new(); lilv_world_load_all(world); diff --git a/wscript b/wscript index 8a3b9be..8858413 100644 --- a/wscript +++ b/wscript @@ -67,6 +67,8 @@ def configure(conf): autowaf.display_header('Lilv Configuration') autowaf.check_pkg(conf, 'lv2core', uselib_store='LV2CORE', mandatory=True) + autowaf.check_pkg(conf, 'serd-0', uselib_store='SERD', + atleast_version='0.7.0', mandatory=True) autowaf.check_pkg(conf, 'sord-0', uselib_store='SORD', atleast_version='0.5.0', mandatory=True) -- cgit v1.2.1