Browse Source

Do not use duplocale if building for libnix because it isnt supported yet

pull/847/head
Cameron Armstrong (Nightfox) 1 year ago
parent
commit
254b5abef8
4 changed files with 19 additions and 2 deletions
  1. +7
    -1
      CMakeLists.txt
  2. +1
    -1
      README.md
  3. +3
    -0
      cmake/config.h.in
  4. +8
    -0
      json_tokener.c

+ 7
- 1
CMakeLists.txt View File

@@ -84,6 +84,8 @@ if (${CMAKE_SYSTEM_NAME} STREQUAL "AmigaOS")
set(NEWLIB ON) set(NEWLIB ON)
elseif(${M68K_CRT} STREQUAL "clib2") elseif(${M68K_CRT} STREQUAL "clib2")
set(CLIB2 ON) set(CLIB2 ON)
elseif(${M68K_CRT} STREQUAL "ixemul")
set(IXEMUL ON)
elseif(${M68K_CRT} STREQUAL "nix20") elseif(${M68K_CRT} STREQUAL "nix20")
set(NIX20 ON) set(NIX20 ON)
elseif(${M68K_CRT} STREQUAL "nix13") elseif(${M68K_CRT} STREQUAL "nix13")
@@ -205,6 +207,10 @@ endif()
if (HAVE_LOCALE_H) if (HAVE_LOCALE_H)
check_symbol_exists(setlocale "locale.h" HAVE_SETLOCALE) check_symbol_exists(setlocale "locale.h" HAVE_SETLOCALE)
check_symbol_exists(uselocale "locale.h" HAVE_USELOCALE) check_symbol_exists(uselocale "locale.h" HAVE_USELOCALE)
if (NOT NIX20 AND NOT NIX13)
# libnix does not fully support this yet
check_symbol_exists(duplocale "locale.h" HAVE_DUPLOCALE)
endif()
endif() endif()


# uClibc *intentionally* crashes in duplocale(), at least as of: # uClibc *intentionally* crashes in duplocale(), at least as of:
@@ -379,7 +385,7 @@ if (NOT ("${CMAKE_C_COMPILER_FRONTEND_VARIANT}" STREQUAL "MSVC"))


# OSX Mach-O doesn't support linking with '-Bsymbolic-functions'. # OSX Mach-O doesn't support linking with '-Bsymbolic-functions'.
# Others may not support it, too. # Others may not support it, too.
list(APPEND CMAKE_REQUIRED_LIBRARIES "-Wl,-Bsymbolic-functions")
list(APPEND CMAKE_REQUIRED_LIBRARIES "-Wl,-Bsymbolic-functions,-lamiga,-lc")
check_c_source_compiles( check_c_source_compiles(
" "
int main (void) int main (void)


+ 1
- 1
README.md View File

@@ -294,7 +294,7 @@ make


libjson-c.a will get created in the build directory. libjson-c.a will get created in the build directory.


You can change newlib to nix20, nix13 or clib2 if you would like to build the library suited for libnix or clib2 instead. Newlib is default.
You can change newlib to nix20, nix13, ixemul or clib2 if you would like to build the library suited for libnix or clib2 instead. Newlib is default.


### To build for PowerPC Amiga: ### To build for PowerPC Amiga:




+ 3
- 0
cmake/config.h.in View File

@@ -137,6 +137,9 @@
/* Define to 1 if you have the `uselocale' function. */ /* Define to 1 if you have the `uselocale' function. */
#cmakedefine HAVE_USELOCALE #cmakedefine HAVE_USELOCALE


/* Define to 1 if you have the `duplocale' function. */
#cmakedefine HAVE_DUPLOCALE

/* Define to 1 if newlocale() needs freelocale() called on it's `base` argument */ /* Define to 1 if newlocale() needs freelocale() called on it's `base` argument */
#cmakedefine NEWLOCALE_NEEDS_FREELOCALE #cmakedefine NEWLOCALE_NEEDS_FREELOCALE




+ 8
- 0
json_tokener.c View File

@@ -345,6 +345,7 @@ struct json_object *json_tokener_parse_ex(struct json_tokener *tok, const char *


#ifdef HAVE_USELOCALE #ifdef HAVE_USELOCALE
{ {
#ifdef HAVE_DUPLOCALE
locale_t duploc = duplocale(oldlocale); locale_t duploc = duplocale(oldlocale);
if (duploc == NULL && errno == ENOMEM) if (duploc == NULL && errno == ENOMEM)
{ {
@@ -352,16 +353,23 @@ struct json_object *json_tokener_parse_ex(struct json_tokener *tok, const char *
return NULL; return NULL;
} }
newloc = newlocale(LC_NUMERIC_MASK, "C", duploc); newloc = newlocale(LC_NUMERIC_MASK, "C", duploc);
#else
newloc = newlocale(LC_NUMERIC_MASK, "C", oldlocale);
#endif
if (newloc == NULL) if (newloc == NULL)
{ {
tok->err = json_tokener_error_memory; tok->err = json_tokener_error_memory;
#ifdef HAVE_DUPLOCALE
freelocale(duploc); freelocale(duploc);
#endif
return NULL; return NULL;
} }
#ifdef NEWLOCALE_NEEDS_FREELOCALE #ifdef NEWLOCALE_NEEDS_FREELOCALE
#ifdef HAVE_DUPLOCALE
// Older versions of FreeBSD (<12.4) don't free the locale // Older versions of FreeBSD (<12.4) don't free the locale
// passed to newlocale(), so do it here // passed to newlocale(), so do it here
freelocale(duploc); freelocale(duploc);
#endif
#endif #endif
uselocale(newloc); uselocale(newloc);
} }


Loading…
Cancel
Save