summaryrefslogtreecommitdiff
path: root/external/dtoa
diff options
context:
space:
mode:
authorMike Kaganski <mike.kaganski@collabora.com>2020-03-02 23:40:06 +0300
committerMike Kaganski <mike.kaganski@collabora.com>2020-03-03 17:34:35 +0100
commit657d8c3e323c7353ce6fa1170532cb6e33d4b74f (patch)
treef024255d34e607e572472d5a9340de261f307d1c /external/dtoa
parent131d5cdbb9526477864ea3bd839deab0e544b821 (diff)
Use thread_local statics in dtoa.c to be thread-safe
We don't use MULTIPLE_THREADS for that to avoid performance penalty due to locking and memory allocation. Use dtoa.cxx stub to compile dtoa.c as C++, to allow using thread_local keyword in MSVC, which still implements pre-C99. Also don't expose dtoa() and other symbols - make them static. And define IEEE_MC68k, not IEEE_8087 on big endian platforms. Change-Id: Ie59fe0cf057b043556a5ac15ec6b11a1a5b41f47 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/89629 Reviewed-by: Michael Meeks <michael.meeks@collabora.com> Tested-by: Jenkins
Diffstat (limited to 'external/dtoa')
-rw-r--r--external/dtoa/StaticLibrary_dtoa.mk15
-rw-r--r--external/dtoa/include_header.patch81
-rw-r--r--external/dtoa/source/dtoa.cxx15
3 files changed, 98 insertions, 13 deletions
diff --git a/external/dtoa/StaticLibrary_dtoa.mk b/external/dtoa/StaticLibrary_dtoa.mk
index 9726ffbbd51f..09f4231a200d 100644
--- a/external/dtoa/StaticLibrary_dtoa.mk
+++ b/external/dtoa/StaticLibrary_dtoa.mk
@@ -11,13 +11,20 @@ $(eval $(call gb_StaticLibrary_StaticLibrary,dtoa))
$(eval $(call gb_StaticLibrary_use_unpacked,dtoa,dtoa))
-# A place that duplicates these settings is jurt/source/pipe/staticsalhack.cxx:
-$(eval $(call gb_StaticLibrary_add_cflags,dtoa,-DIEEE_8087))
+# A place that duplicates these settings is jurt/Library_jpipe.mk
+$(eval $(call gb_StaticLibrary_add_defs,dtoa,\
+ $(if $(filter little,$(ENDIANNESS)),-DIEEE_8087,-DIEEE_MC68k)\
+))
$(eval $(call gb_StaticLibrary_set_warnings_disabled,dtoa))
-$(eval $(call gb_StaticLibrary_add_generated_cobjects,dtoa,\
- UnpackedTarball/dtoa/src/dtoa \
+$(eval $(call gb_StaticLibrary_set_include,dtoa,\
+ -I$(call gb_UnpackedTarball_get_dir,dtoa/src/)\
+ $$(INCLUDE)\
+))
+
+$(eval $(call gb_StaticLibrary_add_exception_objects,dtoa,\
+ external/dtoa/source/dtoa \
))
# vim: set noet sw=4 ts=4:
diff --git a/external/dtoa/include_header.patch b/external/dtoa/include_header.patch
index c34c78d3f6aa..7cf0a8a21471 100644
--- a/external/dtoa/include_header.patch
+++ b/external/dtoa/include_header.patch
@@ -1,23 +1,57 @@
--- /dev/null
+++ dtoa/include/dtoa.h
-@@ -0,0 +1,3 @@
+@@ -0,0 +1,1 @@
+extern "C" double strtod_nolocale(const char *s00, char **se);
-+extern "C" char *dtoa_nolocale(double d, int mode, int ndigits,
-+ int *decpt, int *sign, char **rve);
--- dtoa/src/dtoa.c.orig
+++ dtoa/src/dtoa.c
-@@ -1502,8 +1502,8 @@ static unsigned int maxthreads = 0;
+@@ -268,7 +268,7 @@ #ifndef PRIVATE_MEM
+ #define PRIVATE_MEM 2304
+ #endif
+ #define PRIVATE_mem ((PRIVATE_MEM+sizeof(double)-1)/sizeof(double))
+-static double private_mem[PRIVATE_mem], *pmem_next = private_mem;
++static thread_local double private_mem[PRIVATE_mem], *pmem_next = private_mem;
+ #endif
+
+ #undef IEEE_Arith
+@@ -1502,9 +1502,7 @@ static unsigned int maxthreads = 0;
#define Kmax 7
#ifdef __cplusplus
-extern "C" double strtod(const char *s00, char **se);
-extern "C" char *dtoa(double d, int mode, int ndigits,
+- int *decpt, int *sign, char **rve);
+extern "C" double strtod_nolocale(const char *s00, char **se);
-+extern "C" char *dtoa_nolocale(double d, int mode, int ndigits,
- int *decpt, int *sign, char **rve);
#endif
-@@ -3429,7 +3429,7 @@ retlow1:
+ struct
+@@ -1521,7 +1519,7 @@ ThInfo {
+ Bigint *P5s;
+ } ThInfo;
+
+- static ThInfo TI0;
++ static thread_local ThInfo TI0;
+
+ #ifdef MULTIPLE_THREADS
+ static ThInfo *TI1;
+@@ -1529,7 +1527,7 @@ #ifdef MULTIPLE_THREADS
+ static ThInfo *TI1;
+ static int TI0_used;
+
+- void
++ static void
+ set_max_dtoa_threads(unsigned int n)
+ {
+ size_t L;
+@@ -2717,7 +2715,7 @@ enum { /* rounding values: same as FLT_ROUNDS */
+ Round_down = 3
+ };
+
+- void
++ static void
+ gethex( const char **sp, U *rvp, int rounding, int sign MTd)
+ {
+ Bigint *b;
+@@ -3429,7 +3427,7 @@ retlow1:
#endif /* NO_STRTOD_BIGCOMP */
double
@@ -26,11 +60,40 @@
{
int bb2, bb5, bbe, bd2, bd5, bbbits, bs2, c, e, e1;
int esign, i, j, k, nd, nd0, nf, nz, nz0, nz1, sign;
-@@ -6185,7 +6185,7 @@ dtoa_r(double dd, int mode, int ndigits, int *decpt, int *sign, char **rve, char
+@@ -4851,7 +4849,7 @@ strtod_nolocale(const char *s00, char **se)
+ }
+
+ #ifndef MULTIPLE_THREADS
+- static char *dtoa_result;
++ static thread_local char *dtoa_result;
+ #endif
+
+ static char *
+@@ -4902,7 +4900,7 @@ nrv_alloc(const char *s, char *s0, size_t s0len, char **rve, int n MTd)
+ * when MULTIPLE_THREADS is not defined.
+ */
+
+- void
++ static void
+ freedtoa(char *s)
+ {
+ #ifdef MULTIPLE_THREADS
+@@ -4951,7 +4949,7 @@ freedtoa(char *s)
+ * calculation.
+ */
+
+- char *
++ static char *
+ dtoa_r(double dd, int mode, int ndigits, int *decpt, int *sign, char **rve, char *buf, size_t blen)
+ {
+ /* Arguments ndigits, decpt, sign are similar to those
+@@ -6184,8 +6182,8 @@ dtoa_r(double dd, int mode, int ndigits, int *decpt, int *sign, char **rve, char
+ return buf;
}
- char *
+- char *
-dtoa(double dd, int mode, int ndigits, int *decpt, int *sign, char **rve)
++ static char *
+dtoa_nolocale(double dd, int mode, int ndigits, int *decpt, int *sign, char **rve)
{
/* Sufficient space is allocated to the return value
diff --git a/external/dtoa/source/dtoa.cxx b/external/dtoa/source/dtoa.cxx
new file mode 100644
index 000000000000..d3c8b8211bc8
--- /dev/null
+++ b/external/dtoa/source/dtoa.cxx
@@ -0,0 +1,15 @@
+/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4; fill-column: 100 -*- */
+/*
+ * This file is part of the LibreOffice project.
+ *
+ * This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/.
+ */
+
+#include <sal/config.h>
+
+// build this as C++ code, to allow e.g. thread_local keyword in MSVC
+#include <dtoa.c>
+
+/* vim:set shiftwidth=4 softtabstop=4 expandtab cinoptions=b1,g0,N-s cinkeys+=0=break: */