Remove xlocale use now that isn't available in most distros

Our CI bots don't detect it in Alpine, ArchLinux, Ubuntu and Fedora
so let's get rid of it use the fallback we are using anyway for a
long time.
This commit is contained in:
Ebrahim Byagowi 2020-03-25 16:36:48 +04:30
parent eea99d7b72
commit 44fe1c8ff1
5 changed files with 4 additions and 89 deletions

View File

@ -88,7 +88,7 @@ endmacro ()
if (UNIX) if (UNIX)
list(APPEND CMAKE_REQUIRED_LIBRARIES m) list(APPEND CMAKE_REQUIRED_LIBRARIES m)
endif () endif ()
check_funcs(atexit mprotect sysconf getpagesize mmap isatty newlocale strtod_l roundf) check_funcs(atexit mprotect sysconf getpagesize mmap isatty roundf)
check_include_file(unistd.h HAVE_UNISTD_H) check_include_file(unistd.h HAVE_UNISTD_H)
if (${HAVE_UNISTD_H}) if (${HAVE_UNISTD_H})
add_definitions(-DHAVE_UNISTD_H) add_definitions(-DHAVE_UNISTD_H)
@ -97,10 +97,6 @@ check_include_file(sys/mman.h HAVE_SYS_MMAN_H)
if (${HAVE_SYS_MMAN_H}) if (${HAVE_SYS_MMAN_H})
add_definitions(-DHAVE_SYS_MMAN_H) add_definitions(-DHAVE_SYS_MMAN_H)
endif () endif ()
check_include_file(xlocale.h HAVE_XLOCALE_H)
if (${HAVE_XLOCALE_H})
add_definitions(-DHAVE_XLOCALE_H)
endif ()
check_include_file(stdbool.h HAVE_STDBOOL_H) check_include_file(stdbool.h HAVE_STDBOOL_H)
if (${HAVE_STDBOOL_H}) if (${HAVE_STDBOOL_H})
add_definitions(-DHAVE_STDBOOL_H) add_definitions(-DHAVE_STDBOOL_H)

View File

@ -77,8 +77,8 @@ GTK_DOC_CHECK([1.15],[--flavour no-tmpl])
]) ])
# Functions and headers # Functions and headers
AC_CHECK_FUNCS(atexit mprotect sysconf getpagesize mmap isatty newlocale strtod_l roundf) AC_CHECK_FUNCS(atexit mprotect sysconf getpagesize mmap isatty roundf)
AC_CHECK_HEADERS(unistd.h sys/mman.h xlocale.h stdbool.h) AC_CHECK_HEADERS(unistd.h sys/mman.h stdbool.h)
# Compiler flags # Compiler flags
AC_CANONICAL_HOST AC_CANONICAL_HOST

View File

@ -59,7 +59,6 @@ python3 = import('python').find_installation('python3')
check_headers = [ check_headers = [
['unistd.h'], ['unistd.h'],
['sys/mman.h'], ['sys/mman.h'],
['xlocale.h'],
['stdbool.h'], ['stdbool.h'],
] ]
@ -70,8 +69,6 @@ check_funcs = [
['getpagesize'], ['getpagesize'],
['mmap'], ['mmap'],
['isatty'], ['isatty'],
['newlocale'],
['strtod_l'],
['roundf'], ['roundf'],
] ]

View File

@ -28,11 +28,6 @@
#include "hb-number.hh" #include "hb-number.hh"
#include "hb-number-parser.hh" #include "hb-number-parser.hh"
#include <locale.h>
#ifdef HAVE_XLOCALE_H
#include <xlocale.h>
#endif
template<typename T, typename Func> template<typename T, typename Func>
static bool static bool
_parse_number (const char **pp, const char *end, T *pv, _parse_number (const char **pp, const char *end, T *pv,
@ -74,75 +69,11 @@ hb_parse_uint (const char **pp, const char *end, unsigned int *pv,
{ return strtoul (p, end, base); }); { return strtoul (p, end, base); });
} }
#if defined (HAVE_NEWLOCALE) && defined (HAVE_STRTOD_L)
#define USE_XLOCALE 1
#define HB_LOCALE_T locale_t
#define HB_CREATE_LOCALE(locName) newlocale (LC_ALL_MASK, locName, nullptr)
#define HB_FREE_LOCALE(loc) freelocale (loc)
#elif defined(_MSC_VER)
#define USE_XLOCALE 1
#define HB_LOCALE_T _locale_t
#define HB_CREATE_LOCALE(locName) _create_locale (LC_ALL, locName)
#define HB_FREE_LOCALE(loc) _free_locale (loc)
#define strtod_l(a, b, c) _strtod_l ((a), (b), (c))
#endif
#ifdef USE_XLOCALE
#if HB_USE_ATEXIT
static void free_static_C_locale ();
#endif
static struct hb_C_locale_lazy_loader_t : hb_lazy_loader_t<hb_remove_pointer<HB_LOCALE_T>,
hb_C_locale_lazy_loader_t>
{
static HB_LOCALE_T create ()
{
HB_LOCALE_T C_locale = HB_CREATE_LOCALE ("C");
#if HB_USE_ATEXIT
atexit (free_static_C_locale);
#endif
return C_locale;
}
static void destroy (HB_LOCALE_T p)
{
HB_FREE_LOCALE (p);
}
static HB_LOCALE_T get_null ()
{
return nullptr;
}
} static_C_locale;
#if HB_USE_ATEXIT
static
void free_static_C_locale ()
{
static_C_locale.free_instance ();
}
#endif
static HB_LOCALE_T
get_C_locale ()
{
return static_C_locale.get_unconst ();
}
#endif /* USE_XLOCALE */
bool bool
hb_parse_double (const char **pp, const char *end, double *pv, hb_parse_double (const char **pp, const char *end, double *pv,
bool whole_buffer) bool whole_buffer)
{ {
return _parse_number<double> (pp, end, pv, whole_buffer, return _parse_number<double> (pp, end, pv, whole_buffer,
[] (const char *p, char **end) [] (const char *p, char **end)
{ { return strtod_rl (p, end); });
#ifdef USE_XLOCALE
return strtod_l (p, end, get_C_locale ());
#else
return strtod_rl (p, end);
#endif
});
} }

View File

@ -146,11 +146,6 @@ main (int argc, char **argv)
assert ((int) roundf (pv * 1000.) == 123); assert ((int) roundf (pv * 1000.) == 123);
assert (pp - str == 4); assert (pp - str == 4);
assert (end - pp == 1); assert (end - pp == 1);
/* Test strtod_rl even if libc's strtod_l is used */
char *pend;
assert ((int) roundf (strtod_rl (str, &pend) * 1000.) == 123);
assert (pend - str == 4);
} }
{ {
@ -163,10 +158,6 @@ main (int argc, char **argv)
assert ((int) roundf (pv * 1000.) == 123); assert ((int) roundf (pv * 1000.) == 123);
assert (pp - str == 5); assert (pp - str == 5);
assert (end - pp == 0); assert (end - pp == 0);
char *pend;
assert ((int) roundf (strtod_rl (str, &pend) * 1000.) == 123);
assert (pend - str == 5);
} }
{ {