Skip to content

Commit

Permalink
merged r7083 from trunk
Browse files Browse the repository at this point in the history
refs #1273: use a safe check for the locale-dependent versions of strtod and strtol on GNU/Linux


git-svn-id: https://svn.modelica.org/projects/Modelica/branches/maintenance/3.2.1@7084 7ce873d0-865f-4ce7-a662-4bb36ea78beb
  • Loading branch information
beutlich committed Oct 17, 2013
1 parent a61381d commit 3fa1b52
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 13 deletions.
16 changes: 8 additions & 8 deletions Modelica/Resources/C-Sources/ModelicaStandardTables.c
Expand Up @@ -51,7 +51,7 @@
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/

#if defined(__linux__) && !defined(NO_FILE_SYSTEM)
#if defined(__gnu_linux__) && !defined(NO_FILE_SYSTEM)
#define _GNU_SOURCE 1
#endif
#include "ModelicaStandardTables.h"
Expand Down Expand Up @@ -3828,7 +3828,7 @@ static double* readTxtTable(const char* tableName, const char* fileName,
unsigned long lineNo = 1;
#if defined(_MSC_VER) && _MSC_VER >= 1400
_locale_t loc;
#elif defined(__linux__)
#elif defined(__GNU_LIBRARY__) && __GNU_LIBRARY__ >= 6 && __GLIBC_PREREQ(2, 3)
locale_t loc;
#else
char* dec;
Expand Down Expand Up @@ -3894,7 +3894,7 @@ static double* readTxtTable(const char* tableName, const char* fileName,

#if defined(_MSC_VER) && _MSC_VER >= 1400
loc = _create_locale(LC_NUMERIC, "C");
#elif defined(__linux__)
#elif defined(__GNU_LIBRARY__) && __GNU_LIBRARY__ >= 6 && __GLIBC_PREREQ(2, 3)
loc = newlocale(LC_NUMERIC, "C", NULL);
#else
dec = localeconv()->decimal_point;
Expand Down Expand Up @@ -3930,7 +3930,7 @@ static double* readTxtTable(const char* tableName, const char* fileName,
}
#if defined(_MSC_VER) && _MSC_VER >= 1400
nRow = (unsigned long)_strtol_l(token, &endptr, 10, loc);
#elif defined(__linux__)
#elif defined(__GNU_LIBRARY__) && __GNU_LIBRARY__ >= 6 && __GLIBC_PREREQ(2, 3)
nRow = (unsigned long)strtol_l(token, &endptr, 10, loc);
#else
nRow = (unsigned long)strtol(token, &endptr, 10);
Expand All @@ -3944,7 +3944,7 @@ static double* readTxtTable(const char* tableName, const char* fileName,
}
#if defined(_MSC_VER) && _MSC_VER >= 1400
nCol = (unsigned long)_strtol_l(token, &endptr, 10, loc);
#elif defined(__linux__)
#elif defined(__GNU_LIBRARY__) && __GNU_LIBRARY__ >= 6 && __GLIBC_PREREQ(2, 3)
nCol = (unsigned long)strtol_l(token, &endptr, 10, loc);
#else
nCol = (unsigned long)strtol(token, &endptr, 10);
Expand All @@ -3965,7 +3965,7 @@ static double* readTxtTable(const char* tableName, const char* fileName,
fclose(fp);
#if defined(_MSC_VER) && _MSC_VER >= 1400
_free_locale(loc);
#elif defined(__linux__)
#elif defined(__GNU_LIBRARY__) && __GNU_LIBRARY__ >= 6 && __GLIBC_PREREQ(2, 3)
freelocale(loc);
#endif
ModelicaError("Memory allocation error\n");
Expand Down Expand Up @@ -4005,7 +4005,7 @@ static double* readTxtTable(const char* tableName, const char* fileName,
if (*endptr != 0) {
tableReadError = 1;
}
#elif defined(__linux__)
#elif defined(__GNU_LIBRARY__) && __GNU_LIBRARY__ >= 6 && __GLIBC_PREREQ(2, 3)
TABLE(i, j) = strtod_l(token, &endptr, loc);
if (*endptr != 0) {
tableReadError = 1;
Expand Down Expand Up @@ -4067,7 +4067,7 @@ static double* readTxtTable(const char* tableName, const char* fileName,
fclose(fp);
#if defined(_MSC_VER) && _MSC_VER >= 1400
_free_locale(loc);
#elif defined(__linux__)
#elif defined(__GNU_LIBRARY__) && __GNU_LIBRARY__ >= 6 && __GLIBC_PREREQ(2, 3)
freelocale(loc);
#endif
if (foundTable == 0) {
Expand Down
10 changes: 5 additions & 5 deletions Modelica/Resources/C-Sources/ModelicaStrings.c
Expand Up @@ -47,7 +47,7 @@
#if !defined(MODELICA_EXPORT)
# define MODELICA_EXPORT
#endif
#if defined(__linux__) && !defined(_DS1006)
#if defined(__gnu_linux__)
#define _GNU_SOURCE 1
#endif

Expand Down Expand Up @@ -261,7 +261,7 @@ MODELICA_EXPORT void ModelicaStrings_scanInteger(const char* string, int startIn
&& string[next] != 'E') ) {
#if defined(_MSC_VER) && _MSC_VER >= 1400
_locale_t loc = _create_locale(LC_NUMERIC, "C");
#elif defined(__linux__) && !defined(_DS1006)
#elif defined(__GNU_LIBRARY__) && __GNU_LIBRARY__ >= 6 && __GLIBC_PREREQ(2, 3)
locale_t loc = newlocale(LC_NUMERIC, "C", NULL);
#endif
char buf[MAX_TOKEN_SIZE+1];
Expand All @@ -276,7 +276,7 @@ MODELICA_EXPORT void ModelicaStrings_scanInteger(const char* string, int startIn
#if defined(_MSC_VER) && _MSC_VER >= 1400
x = (int)_strtol_l(buf, &endptr, 10, loc);
_free_locale(loc);
#elif defined(__linux__) && !defined(_DS1006)
#elif defined(__GNU_LIBRARY__) && __GNU_LIBRARY__ >= 6 && __GLIBC_PREREQ(2, 3)
x = (int)strtol_l(buf, &endptr, 10, loc);
freelocale(loc);
#else
Expand Down Expand Up @@ -367,7 +367,7 @@ MODELICA_EXPORT void ModelicaStrings_scanReal(const char* string, int startIndex
if (total_length > 0 && total_length < MAX_TOKEN_SIZE) {
#if defined(_MSC_VER) && _MSC_VER >= 1400
_locale_t loc = _create_locale(LC_NUMERIC, "C");
#elif defined(__linux__) && !defined(_DS1006)
#elif defined(__GNU_LIBRARY__) && __GNU_LIBRARY__ >= 6 && __GLIBC_PREREQ(2, 3)
locale_t loc = newlocale(LC_NUMERIC, "C", NULL);
#else
char* dec = localeconv()->decimal_point;
Expand All @@ -384,7 +384,7 @@ MODELICA_EXPORT void ModelicaStrings_scanReal(const char* string, int startIndex
#if defined(_MSC_VER) && _MSC_VER >= 1400
x = _strtod_l(buf, &endptr, loc);
_free_locale(loc);
#elif defined(__linux__) && !defined(_DS1006)
#elif defined(__GNU_LIBRARY__) && __GNU_LIBRARY__ >= 6 && __GLIBC_PREREQ(2, 3)
x = strtod_l(buf, &endptr, loc);
freelocale(loc);
#else
Expand Down

0 comments on commit 3fa1b52

Please sign in to comment.