office-gobmx/external/dtoa/include_header.patch
Mike Kaganski 657d8c3e32 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
2020-03-03 17:34:35 +01:00

100 lines
2.6 KiB
Diff

--- /dev/null
+++ dtoa/include/dtoa.h
@@ -0,0 +1,1 @@
+extern "C" double strtod_nolocale(const char *s00, char **se);
--- dtoa/src/dtoa.c.orig
+++ dtoa/src/dtoa.c
@@ -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);
#endif
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
-strtod(const char *s00, char **se)
+strtod_nolocale(const char *s00, char **se)
{
int bb2, bb5, bbe, bd2, bd5, bbbits, bs2, c, e, e1;
int esign, i, j, k, nd, nd0, nf, nz, nz0, nz1, sign;
@@ -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 *
-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
to hold the suppressed trailing zeros.