From e3f54b745b7d9ae7587929a0adbfd1f00cd805e8 Mon Sep 17 00:00:00 2001 From: David Sansome Date: Sat, 24 Jul 2010 12:26:28 +0000 Subject: [PATCH] Patch libprojectM to make it ignore the decimal-point locale setting when parsing Milkdrop presets. Fixes issue #455 --- .../MilkdropPresetFactory/Parser.cpp | 46 ++--------- .../patches/06-fix-numeric-locale.patch | 81 +++++++++++++++++++ 2 files changed, 88 insertions(+), 39 deletions(-) create mode 100644 3rdparty/libprojectm/patches/06-fix-numeric-locale.patch diff --git a/3rdparty/libprojectm/MilkdropPresetFactory/Parser.cpp b/3rdparty/libprojectm/MilkdropPresetFactory/Parser.cpp index d410028ee..cdf8256c1 100755 --- a/3rdparty/libprojectm/MilkdropPresetFactory/Parser.cpp +++ b/3rdparty/libprojectm/MilkdropPresetFactory/Parser.cpp @@ -1269,28 +1269,13 @@ int Parser::parse_int(std::istream & fs, int * int_ptr) /* Parses a floating point number */ int Parser::string_to_float(char * string, float * float_ptr) { + std::istringstream stream(string); + stream >> *float_ptr; - char ** error_ptr; - - if (*string == 0) + if (stream.fail()) return PROJECTM_PARSE_ERROR; - error_ptr = (char**)wipemalloc(sizeof(char**)); - - (*float_ptr) = strtod(string, error_ptr); - - /* These imply a succesful parse of the string */ - if ((**error_ptr == '\0') || (**error_ptr == '\r')) - { - free(error_ptr); - error_ptr = NULL; - return PROJECTM_SUCCESS; - } - - (*float_ptr) = 0; - free(error_ptr); - error_ptr = NULL; - return PROJECTM_PARSE_ERROR; + return PROJECTM_SUCCESS; } /* Parses a floating point number */ @@ -1298,11 +1283,9 @@ int Parser::parse_float(std::istream & fs, float * float_ptr) { char string[MAX_TOKEN_SIZE]; - char ** error_ptr; token_t token; int sign; - error_ptr =(char**) wipemalloc(sizeof(char**)); token = parseToken(fs, string); @@ -1322,28 +1305,13 @@ int Parser::parse_float(std::istream & fs, float * float_ptr) if (string[0] == 0) { - free(error_ptr); - error_ptr = NULL; return PROJECTM_PARSE_ERROR; } - (*float_ptr) = sign*strtod(string, error_ptr); - - /* No conversion was performed */ - if ((**error_ptr == '\0') || (**error_ptr == '\r')) - { - free(error_ptr); - error_ptr = NULL; - return PROJECTM_SUCCESS; - } - - if (PARSE_DEBUG) printf("parse_float: float conversion failed for string \"%s\"\n", string); - - (*float_ptr) = 0; - free(error_ptr); - error_ptr = NULL; - return PROJECTM_PARSE_ERROR; + std::istringstream stream(string); + stream >> *float_ptr; + return PROJECTM_SUCCESS; } /* Parses a per frame equation. That is, interprets a stream of data as a per frame equation */ diff --git a/3rdparty/libprojectm/patches/06-fix-numeric-locale.patch b/3rdparty/libprojectm/patches/06-fix-numeric-locale.patch new file mode 100644 index 000000000..dfbf59f15 --- /dev/null +++ b/3rdparty/libprojectm/patches/06-fix-numeric-locale.patch @@ -0,0 +1,81 @@ +Index: MilkdropPresetFactory/Parser.cpp +=================================================================== +--- MilkdropPresetFactory/Parser.cpp (revision 1510) ++++ MilkdropPresetFactory/Parser.cpp (working copy) +@@ -1269,28 +1269,13 @@ + /* Parses a floating point number */ + int Parser::string_to_float(char * string, float * float_ptr) + { ++ std::istringstream stream(string); ++ stream >> *float_ptr; + +- char ** error_ptr; +- +- if (*string == 0) ++ if (stream.fail()) + return PROJECTM_PARSE_ERROR; + +- error_ptr = (char**)wipemalloc(sizeof(char**)); +- +- (*float_ptr) = strtod(string, error_ptr); +- +- /* These imply a succesful parse of the string */ +- if ((**error_ptr == '\0') || (**error_ptr == '\r')) +- { +- free(error_ptr); +- error_ptr = NULL; +- return PROJECTM_SUCCESS; +- } +- +- (*float_ptr) = 0; +- free(error_ptr); +- error_ptr = NULL; +- return PROJECTM_PARSE_ERROR; ++ return PROJECTM_SUCCESS; + } + + /* Parses a floating point number */ +@@ -1298,11 +1283,9 @@ + { + + char string[MAX_TOKEN_SIZE]; +- char ** error_ptr; + token_t token; + int sign; + +- error_ptr =(char**) wipemalloc(sizeof(char**)); + + token = parseToken(fs, string); + +@@ -1322,28 +1305,13 @@ + + if (string[0] == 0) + { +- free(error_ptr); +- error_ptr = NULL; + return PROJECTM_PARSE_ERROR; + } + +- (*float_ptr) = sign*strtod(string, error_ptr); ++ std::istringstream stream(string); ++ stream >> *float_ptr; + +- /* No conversion was performed */ +- if ((**error_ptr == '\0') || (**error_ptr == '\r')) +- { +- free(error_ptr); +- error_ptr = NULL; +- return PROJECTM_SUCCESS; +- } +- +- if (PARSE_DEBUG) printf("parse_float: float conversion failed for string \"%s\"\n", string); +- +- (*float_ptr) = 0; +- free(error_ptr); +- error_ptr = NULL; +- return PROJECTM_PARSE_ERROR; +- ++ return PROJECTM_SUCCESS; + } + + /* Parses a per frame equation. That is, interprets a stream of data as a per frame equation */