summaryrefslogtreecommitdiffstats
path: root/external/dtoa
diff options
context:
space:
mode:
Diffstat (limited to 'external/dtoa')
-rw-r--r--external/dtoa/Makefile14
-rw-r--r--external/dtoa/Module_dtoa.mk17
-rw-r--r--external/dtoa/README10
-rw-r--r--external/dtoa/StaticLibrary_dtoa.mk30
-rw-r--r--external/dtoa/UnpackedTarball_dtoa.mk22
-rw-r--r--external/dtoa/coverity.patch51
-rw-r--r--external/dtoa/include_header.patch100
-rw-r--r--external/dtoa/source/dtoa.cxx15
-rw-r--r--external/dtoa/ubsan.patch.011
9 files changed, 270 insertions, 0 deletions
diff --git a/external/dtoa/Makefile b/external/dtoa/Makefile
new file mode 100644
index 0000000000..6427d44e37
--- /dev/null
+++ b/external/dtoa/Makefile
@@ -0,0 +1,14 @@
+# -*- Mode: makefile-gmake; tab-width: 4; indent-tabs-mode: t; 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/.
+#
+
+module_directory:=$(dir $(realpath $(firstword $(MAKEFILE_LIST))))
+
+include $(module_directory)/../../solenv/gbuild/partial_build.mk
+
+# vim: set noet sw=4 ts=4:
diff --git a/external/dtoa/Module_dtoa.mk b/external/dtoa/Module_dtoa.mk
new file mode 100644
index 0000000000..c652f97e0b
--- /dev/null
+++ b/external/dtoa/Module_dtoa.mk
@@ -0,0 +1,17 @@
+# -*- Mode: makefile-gmake; tab-width: 4; indent-tabs-mode: t -*-
+#
+# 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/.
+#
+
+$(eval $(call gb_Module_Module,dtoa))
+
+$(eval $(call gb_Module_add_targets,dtoa,\
+ UnpackedTarball_dtoa \
+ StaticLibrary_dtoa \
+))
+
+# vim: set noet sw=4 ts=4:
diff --git a/external/dtoa/README b/external/dtoa/README
new file mode 100644
index 0000000000..9f46b9865d
--- /dev/null
+++ b/external/dtoa/README
@@ -0,0 +1,10 @@
+dtoa is available from [ https://www.netlib.org/fp/ ].
+
+Used to convert a decimal string to double (until std::from_chars is available on used compilers).
+Packaged using
+
+ mkdir dtoa && mkdir dtoa/src && wget https://www.netlib.org/fp/dtoa.c -O dtoa/src/dtoa.c && \
+ printf 'd8bab255476f39ea495c8c8ed164f9077da926e6ca7afb9ad3c56d337c4484fe dtoa/src/dtoa.c' | sha256sum -c && \
+ tar -c --owner=0 --group=0 --mode=go=r,u=rw --mtime='Wed, 11 Apr 2018 15:59:39 GMT' dtoa/src/dtoa.c | gzip -n > dtoa-20180411.tgz && \
+ printf '0082d0684f7db6f62361b76c4b7faba19e0c7ce5cb8e36c4b65fea8281e711b4 dtoa-20180411.tgz' | sha256sum -c
+(where the date "Wed, 11 Apr 2018 15:59:39 GMT" is from `wget -S https://www.netlib.org/fp/dtoa.c` "Last-Modified: Wed, 11 Apr 2018 15:59:39 GMT" header).
diff --git a/external/dtoa/StaticLibrary_dtoa.mk b/external/dtoa/StaticLibrary_dtoa.mk
new file mode 100644
index 0000000000..09f4231a20
--- /dev/null
+++ b/external/dtoa/StaticLibrary_dtoa.mk
@@ -0,0 +1,30 @@
+# -*- Mode: makefile-gmake; tab-width: 4; indent-tabs-mode: t -*-
+#
+# 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/.
+#
+
+$(eval $(call gb_StaticLibrary_StaticLibrary,dtoa))
+
+$(eval $(call gb_StaticLibrary_use_unpacked,dtoa,dtoa))
+
+# 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_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/UnpackedTarball_dtoa.mk b/external/dtoa/UnpackedTarball_dtoa.mk
new file mode 100644
index 0000000000..bc4fe55b5a
--- /dev/null
+++ b/external/dtoa/UnpackedTarball_dtoa.mk
@@ -0,0 +1,22 @@
+#-*- Mode: makefile-gmake; tab-width: 4; indent-tabs-mode: t -*-
+#
+# 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/.
+#
+
+$(eval $(call gb_UnpackedTarball_UnpackedTarball,dtoa))
+
+$(eval $(call gb_UnpackedTarball_set_tarball,dtoa,$(DTOA_TARBALL)))
+
+$(eval $(call gb_UnpackedTarball_set_patchlevel,dtoa,1))
+
+$(eval $(call gb_UnpackedTarball_add_patches,dtoa, \
+ external/dtoa/include_header.patch \
+ external/dtoa/coverity.patch \
+ external/dtoa/ubsan.patch.0 \
+))
+
+# vim: set noet sw=4 ts=4:
diff --git a/external/dtoa/coverity.patch b/external/dtoa/coverity.patch
new file mode 100644
index 0000000000..8fb1765315
--- /dev/null
+++ b/external/dtoa/coverity.patch
@@ -0,0 +1,51 @@
+--- dtor/src/dtoa.c.coverity
++++ dtor/src/dtoa.c
+@@ -216,14 +216,14 @@
+ typedef unsigned Long ULong;
+ #endif
+
+-#ifdef DEBUG
+ #include <assert.h>
++
++#ifdef DEBUG
+ #include "stdio.h"
+ #define Bug(x) {fprintf(stderr, "%s\n", x); exit(1);}
+ #define Debug(x) x
+ int dtoa_stats[7]; /* strtod_{64,96,bigcomp},dtoa_{exact,64,96,bigcomp} */
+ #else
+-#define assert(x) /*nothing*/
+ #define Debug(x) /*nothing*/
+ #endif
+
+@@ -2301,6 +2301,7 @@
+ if ((y = d1)) {
+ if ((k = lo0bits(&y))) {
+ x[0] = y | z << (32 - k);
++ assert(k < 32); /* https://bugs.python.org/issue23999 */
+ z >>= k;
+ }
+ else
+@@ -3029,6 +3030,7 @@
+ || ((n = nbits & kmask) !=0
+ && hi0bits(x[k-1]) < 32-n)) {
+ rshift(b,1);
++ /* coverity[dead_error_line] - not worth investigating */
+ if (++e > Emax)
+ goto ovfl;
+ }
+@@ -3345,6 +3347,7 @@
+ if ((dd = s0[j++] - '0' - dig))
+ goto ret;
+ if (!b->x[0] && b->wds == 1) {
++ /* coverity[copy_paste_error : FALSE] */
+ if (i < nd)
+ dd = 1;
+ goto ret;
+@@ -3607,6 +3610,7 @@
+ switch(c = *++s) {
+ case '-':
+ esign = 1;
++ /* fall through */
+ case '+':
+ c = *++s;
+ }
diff --git a/external/dtoa/include_header.patch b/external/dtoa/include_header.patch
new file mode 100644
index 0000000000..7cf0a8a214
--- /dev/null
+++ b/external/dtoa/include_header.patch
@@ -0,0 +1,100 @@
+--- /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.
diff --git a/external/dtoa/source/dtoa.cxx b/external/dtoa/source/dtoa.cxx
new file mode 100644
index 0000000000..d3c8b8211b
--- /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: */
diff --git a/external/dtoa/ubsan.patch.0 b/external/dtoa/ubsan.patch.0
new file mode 100644
index 0000000000..de39d41aca
--- /dev/null
+++ b/external/dtoa/ubsan.patch.0
@@ -0,0 +1,11 @@
+--- src/dtoa.c
++++ src/dtoa.c
+@@ -3618,7 +3618,7 @@
+ while(c == '0')
+ c = *++s;
+ if (c > '0' && c <= '9') {
+- L = c - '0';
++ ULong L = c - '0';
+ s1 = s;
+ while((c = *++s) >= '0' && c <= '9')
+ L = 10*L + c - '0';