Skip to content

Commit 254b5ab

Browse files
committed
Do not use duplocale if building for libnix because it isnt supported yet
1 parent d31d635 commit 254b5ab

File tree

4 files changed

+19
-2
lines changed

4 files changed

+19
-2
lines changed

CMakeLists.txt

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,8 @@ if (${CMAKE_SYSTEM_NAME} STREQUAL "AmigaOS")
8484
set(NEWLIB ON)
8585
elseif(${M68K_CRT} STREQUAL "clib2")
8686
set(CLIB2 ON)
87+
elseif(${M68K_CRT} STREQUAL "ixemul")
88+
set(IXEMUL ON)
8789
elseif(${M68K_CRT} STREQUAL "nix20")
8890
set(NIX20 ON)
8991
elseif(${M68K_CRT} STREQUAL "nix13")
@@ -205,6 +207,10 @@ endif()
205207
if (HAVE_LOCALE_H)
206208
check_symbol_exists(setlocale "locale.h" HAVE_SETLOCALE)
207209
check_symbol_exists(uselocale "locale.h" HAVE_USELOCALE)
210+
if (NOT NIX20 AND NOT NIX13)
211+
# libnix does not fully support this yet
212+
check_symbol_exists(duplocale "locale.h" HAVE_DUPLOCALE)
213+
endif()
208214
endif()
209215

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

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

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -294,7 +294,7 @@ make
294294

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

297-
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.
297+
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.
298298

299299
### To build for PowerPC Amiga:
300300

cmake/config.h.in

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -137,6 +137,9 @@
137137
/* Define to 1 if you have the `uselocale' function. */
138138
#cmakedefine HAVE_USELOCALE
139139

140+
/* Define to 1 if you have the `duplocale' function. */
141+
#cmakedefine HAVE_DUPLOCALE
142+
140143
/* Define to 1 if newlocale() needs freelocale() called on it's `base` argument */
141144
#cmakedefine NEWLOCALE_NEEDS_FREELOCALE
142145

json_tokener.c

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -345,23 +345,31 @@ struct json_object *json_tokener_parse_ex(struct json_tokener *tok, const char *
345345

346346
#ifdef HAVE_USELOCALE
347347
{
348+
#ifdef HAVE_DUPLOCALE
348349
locale_t duploc = duplocale(oldlocale);
349350
if (duploc == NULL && errno == ENOMEM)
350351
{
351352
tok->err = json_tokener_error_memory;
352353
return NULL;
353354
}
354355
newloc = newlocale(LC_NUMERIC_MASK, "C", duploc);
356+
#else
357+
newloc = newlocale(LC_NUMERIC_MASK, "C", oldlocale);
358+
#endif
355359
if (newloc == NULL)
356360
{
357361
tok->err = json_tokener_error_memory;
362+
#ifdef HAVE_DUPLOCALE
358363
freelocale(duploc);
364+
#endif
359365
return NULL;
360366
}
361367
#ifdef NEWLOCALE_NEEDS_FREELOCALE
368+
#ifdef HAVE_DUPLOCALE
362369
// Older versions of FreeBSD (<12.4) don't free the locale
363370
// passed to newlocale(), so do it here
364371
freelocale(duploc);
372+
#endif
365373
#endif
366374
uselocale(newloc);
367375
}

0 commit comments

Comments
 (0)