[HarfBuzz] strtod_l and Windows

Jean Ghali jghali at libertysurf.fr
Mon Nov 13 00:47:14 UTC 2017


Hi all,

Commit 3ca69c8c32b8408dd9f8e6e866cd07e58c0d79b7 has introduced the use of <xlocale> and
strtod_l in order to correctly parse decimal numbers in French & other locales (per commit
message). I'm bit late, but having faced in the past similar issue in Scribus and Windows,
I would like to contribute the equivalent code for Windows MSVC. MSVC C library has indeed
a similar api to the one provided by <xlocale.h>:
- locale_t becomes _locale_t
- newlocale() becomes _create_locale()
- freelocale() becomes _free_locale()
- strtod_l() becomes _strtod_l()

So please find in attachments a patch which does the necessary modifications for MVSC
compiler. Unfortunately it seems MinGW C library does not provide this api yet, so I had
to keep those modifications MSVC specific.

Best regards,
Jean Ghali
-------------- next part --------------
diff -r -u a/src/hb-common.cc b/src/hb-common.cc
--- a/src/hb-common.cc	2017-11-10 17:14:26.000000000 +0100
+++ b/src/hb-common.cc	2017-11-12 02:28:19.883451600 +0100
@@ -699,34 +699,43 @@
 
 #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
 
-static locale_t C_locale;
+static HB_LOCALE_T C_locale;
 
 #ifdef HB_USE_ATEXIT
 static void
 free_C_locale (void)
 {
   if (C_locale)
-    freelocale (C_locale);
+    HB_FREE_LOCALE (C_locale);
 }
 #endif
 
-static locale_t
+static HB_LOCALE_T
 get_C_locale (void)
 {
 retry:
-  locale_t C = (locale_t) hb_atomic_ptr_get (&C_locale);
+  HB_LOCALE_T C = (HB_LOCALE_T) hb_atomic_ptr_get (&C_locale);
 
   if (unlikely (!C))
   {
-    C = newlocale (LC_ALL_MASK, "C", nullptr);
+    C = HB_CREATE_LOCALE("C");
 
     if (!hb_atomic_ptr_cmpexch (&C_locale, nullptr, C))
     {
-      freelocale (C_locale);
+      HB_FREE_LOCALE (C_locale);
       goto retry;
     }
 


More information about the HarfBuzz mailing list