1
From e02cabecf0d025ec4f4ddee290bdf7aadb873bb3 Mon Sep 17 00:00:00 2001
2
From: Joseph Myers <joseph@codesourcery.com>
3
Date: Tue, 24 Nov 2015 22:24:52 +0000
4
Subject: [PATCH] Refactor strtod parsing of NaN payloads.
6
The nan* functions handle their string argument by constructing a
7
NAN(...) string on the stack as a VLA and passing it to strtod
10
This approach has problems discussed in bug 16961 and bug 16962: the
11
stack usage is unbounded, and it gives incorrect results in certain
12
cases where the argument is not a valid n-char-sequence.
14
The natural fix for both issues is to refactor the NaN payload parsing
15
out of strtod into a separate function that the nan* functions can
16
call directly, so that no temporary string needs constructing on the
17
stack at all. This patch does that refactoring in preparation for
18
fixing those bugs (but without actually using the new functions from
19
nan* - which will also require exporting them from libc at version
20
GLIBC_PRIVATE). This patch is not intended to change any user-visible
21
behavior, so no tests are added (fixes for the above bugs will of
22
course add tests for them).
24
This patch builds on my recent fixes for strtol and strtod issues in
25
Turkish locales. Given those fixes, the parsing of NaN payloads is
26
locale-independent; thus, the new functions do not need to take a
29
Tested for x86_64, x86, mips64 and powerpc.
31
* stdlib/strtod_nan.c: New file.
32
* stdlib/strtod_nan_double.h: Likewise.
33
* stdlib/strtod_nan_float.h: Likewise.
34
* stdlib/strtod_nan_main.c: Likewise.
35
* stdlib/strtod_nan_narrow.h: Likewise.
36
* stdlib/strtod_nan_wide.h: Likewise.
37
* stdlib/strtof_nan.c: Likewise.
38
* stdlib/strtold_nan.c: Likewise.
39
* sysdeps/ieee754/ldbl-128/strtod_nan_ldouble.h: Likewise.
40
* sysdeps/ieee754/ldbl-128ibm/strtod_nan_ldouble.h: Likewise.
41
* sysdeps/ieee754/ldbl-96/strtod_nan_ldouble.h: Likewise.
42
* wcsmbs/wcstod_nan.c: Likewise.
43
* wcsmbs/wcstof_nan.c: Likewise.
44
* wcsmbs/wcstold_nan.c: Likewise.
45
* stdlib/Makefile (routines): Add strtof_nan, strtod_nan and
47
* wcsmbs/Makefile (routines): Add wcstod_nan, wcstold_nan and
49
* include/stdlib.h (__strtof_nan): Declare and use
51
(__strtod_nan): Likewise.
52
(__strtold_nan): Likewise.
53
(__wcstof_nan): Likewise.
54
(__wcstod_nan): Likewise.
55
(__wcstold_nan): Likewise.
56
* include/wchar.h (____wcstoull_l_internal): Declare.
57
* stdlib/strtod_l.c: Do not include <ieee754.h>.
58
(____strtoull_l_internal): Remove declaration.
59
(STRTOF_NAN): Define macro.
60
(SET_MANTISSA): Remove macro.
62
(____STRTOF_INTERNAL): Use STRTOF_NAN to parse NaN payload.
63
* stdlib/strtof_l.c (____strtoull_l_internal): Remove declaration.
64
(STRTOF_NAN): Define macro.
65
(SET_MANTISSA): Remove macro.
66
* sysdeps/ieee754/ldbl-128/strtold_l.c (STRTOF_NAN): Define macro.
67
(SET_MANTISSA): Remove macro.
68
* sysdeps/ieee754/ldbl-128ibm/strtold_l.c (STRTOF_NAN): Define
70
(SET_MANTISSA): Remove macro.
71
* sysdeps/ieee754/ldbl-64-128/strtold_l.c (STRTOF_NAN): Define
73
(SET_MANTISSA): Remove macro.
74
* sysdeps/ieee754/ldbl-96/strtold_l.c (STRTOF_NAN): Define macro.
75
(SET_MANTISSA): Remove macro.
76
* wcsmbs/wcstod_l.c (____wcstoull_l_internal): Remove declaration.
77
* wcsmbs/wcstof_l.c (____wcstoull_l_internal): Likewise.
78
* wcsmbs/wcstold_l.c (____wcstoull_l_internal): Likewise.
80
[Note: patch differs from upstream commit in that the entries in the
81
Changelog were dropped to avoid patch conflicts, and adjust
82
stdlib/strtod_l.c hunk 5 change to match existing code. -- sbeattie]
85
include/stdlib.h | 18 ++++++
88
stdlib/strtod_l.c | 48 +++--------------
89
stdlib/strtod_nan.c | 24 ++++++++
90
stdlib/strtod_nan_double.h | 30 ++++++++++
91
stdlib/strtod_nan_float.h | 29 ++++++++++
92
stdlib/strtod_nan_main.c | 63 +++++++++++++++++++++++
93
stdlib/strtod_nan_narrow.h | 22 ++++++++
94
stdlib/strtod_nan_wide.h | 22 ++++++++
95
stdlib/strtof_l.c | 11 ----
96
stdlib/strtof_nan.c | 24 ++++++++
97
stdlib/strtold_nan.c | 30 ++++++++++
98
sysdeps/ieee754/ldbl-128/strtod_nan_ldouble.h | 33 ++++++++++++
99
sysdeps/ieee754/ldbl-128/strtold_l.c | 13 ----
100
sysdeps/ieee754/ldbl-128ibm/strtod_nan_ldouble.h | 30 ++++++++++
101
sysdeps/ieee754/ldbl-128ibm/strtold_l.c | 10 ---
102
sysdeps/ieee754/ldbl-64-128/strtold_l.c | 13 ----
103
sysdeps/ieee754/ldbl-96/strtod_nan_ldouble.h | 30 ++++++++++
104
sysdeps/ieee754/ldbl-96/strtold_l.c | 10 ---
106
wcsmbs/wcstod_l.c | 3 -
107
wcsmbs/wcstod_nan.c | 23 ++++++++
108
wcsmbs/wcstof_l.c | 3 -
109
wcsmbs/wcstof_nan.c | 23 ++++++++
110
wcsmbs/wcstold_l.c | 3 -
111
wcsmbs/wcstold_nan.c | 30 ++++++++++
112
27 files changed, 455 insertions(+), 95 deletions(-)
113
create mode 100644 stdlib/strtod_nan.c
114
create mode 100644 stdlib/strtod_nan_double.h
115
create mode 100644 stdlib/strtod_nan_float.h
116
create mode 100644 stdlib/strtod_nan_main.c
117
create mode 100644 stdlib/strtod_nan_narrow.h
118
create mode 100644 stdlib/strtod_nan_wide.h
119
create mode 100644 stdlib/strtof_nan.c
120
create mode 100644 stdlib/strtold_nan.c
121
create mode 100644 sysdeps/ieee754/ldbl-128/strtod_nan_ldouble.h
122
create mode 100644 sysdeps/ieee754/ldbl-128ibm/strtod_nan_ldouble.h
123
create mode 100644 sysdeps/ieee754/ldbl-96/strtod_nan_ldouble.h
124
create mode 100644 wcsmbs/wcstod_nan.c
125
create mode 100644 wcsmbs/wcstof_nan.c
126
create mode 100644 wcsmbs/wcstold_nan.c
128
Index: b/include/stdlib.h
129
===================================================================
130
--- a/include/stdlib.h
131
+++ b/include/stdlib.h
132
@@ -203,6 +203,24 @@ libc_hidden_proto (strtoll)
133
libc_hidden_proto (strtoul)
134
libc_hidden_proto (strtoull)
136
+extern float __strtof_nan (const char *, char **, char) internal_function;
137
+extern double __strtod_nan (const char *, char **, char) internal_function;
138
+extern long double __strtold_nan (const char *, char **, char)
140
+extern float __wcstof_nan (const wchar_t *, wchar_t **, wchar_t)
142
+extern double __wcstod_nan (const wchar_t *, wchar_t **, wchar_t)
144
+extern long double __wcstold_nan (const wchar_t *, wchar_t **, wchar_t)
147
+libc_hidden_proto (__strtof_nan)
148
+libc_hidden_proto (__strtod_nan)
149
+libc_hidden_proto (__strtold_nan)
150
+libc_hidden_proto (__wcstof_nan)
151
+libc_hidden_proto (__wcstod_nan)
152
+libc_hidden_proto (__wcstold_nan)
154
extern char *__ecvt (double __value, int __ndigit, int *__restrict __decpt,
155
int *__restrict __sign);
156
extern char *__fcvt (double __value, int __ndigit, int *__restrict __decpt,
157
Index: b/include/wchar.h
158
===================================================================
159
--- a/include/wchar.h
160
+++ b/include/wchar.h
161
@@ -52,6 +52,9 @@ extern unsigned long long int __wcstoull
164
int __group) __THROW;
165
+extern unsigned long long int ____wcstoull_l_internal (const wchar_t *,
166
+ wchar_t **, int, int,
168
libc_hidden_proto (__wcstof_internal)
169
libc_hidden_proto (__wcstod_internal)
170
libc_hidden_proto (__wcstold_internal)
171
Index: b/stdlib/Makefile
172
===================================================================
173
--- a/stdlib/Makefile
174
+++ b/stdlib/Makefile
175
@@ -49,6 +49,7 @@ routines-y := \
176
strtol_l strtoul_l strtoll_l strtoull_l \
177
strtof strtod strtold \
178
strtof_l strtod_l strtold_l \
179
+ strtof_nan strtod_nan strtold_nan \
180
system canonicalize \
182
getsubopt xpg_basename \
183
Index: b/stdlib/strtod_l.c
184
===================================================================
185
--- a/stdlib/strtod_l.c
186
+++ b/stdlib/strtod_l.c
190
extern double ____strtod_l_internal (const char *, char **, int, __locale_t);
191
-extern unsigned long long int ____strtoull_l_internal (const char *, char **,
192
- int, int, __locale_t);
194
/* Configuration part. These macros are defined by `strtold.c',
195
`strtof.c', `wcstod.c', `wcstold.c', and `wcstof.c' to produce the
196
@@ -34,27 +32,20 @@ extern unsigned long long int ____strtou
197
# ifdef USE_WIDE_CHAR
198
# define STRTOF wcstod_l
199
# define __STRTOF __wcstod_l
200
+# define STRTOF_NAN __wcstod_nan
202
# define STRTOF strtod_l
203
# define __STRTOF __strtod_l
204
+# define STRTOF_NAN __strtod_nan
206
# define MPN2FLOAT __mpn_construct_double
207
# define FLOAT_HUGE_VAL HUGE_VAL
208
-# define SET_MANTISSA(flt, mant) \
209
- do { union ieee754_double u; \
211
- u.ieee_nan.mantissa0 = (mant) >> 32; \
212
- u.ieee_nan.mantissa1 = (mant); \
213
- if ((u.ieee.mantissa0 | u.ieee.mantissa1) != 0) \
217
/* End of configuration part. */
222
-#include <ieee754.h>
223
#include "../locale/localeinfo.h"
226
@@ -105,7 +96,6 @@ extern unsigned long long int ____strtou
227
# define TOLOWER_C(Ch) __towlower_l ((Ch), _nl_C_locobj_ptr)
228
# define STRNCASECMP(S1, S2, N) \
229
__wcsncasecmp_l ((S1), (S2), (N), _nl_C_locobj_ptr)
230
-# define STRTOULL(S, E, B) ____wcstoull_l_internal ((S), (E), (B), 0, loc)
232
# define STRING_TYPE char
233
# define CHAR_TYPE char
234
@@ -117,7 +107,6 @@ extern unsigned long long int ____strtou
235
# define TOLOWER_C(Ch) __tolower_l ((Ch), _nl_C_locobj_ptr)
236
# define STRNCASECMP(S1, S2, N) \
237
__strncasecmp_l ((S1), (S2), (N), _nl_C_locobj_ptr)
238
-# define STRTOULL(S, E, B) ____strtoull_l_internal ((S), (E), (B), 0, loc)
242
@@ -663,33 +652,14 @@ ____STRTOF_INTERNAL (nptr, endptr, group
245
const STRING_TYPE *startp = cp;
248
- while ((*cp >= L_('0') && *cp <= L_('9'))
249
- || ({ CHAR_TYPE lo = TOLOWER (*cp);
250
- lo >= L_('a') && lo <= L_('z'); })
251
- || *cp == L_('_'));
253
- if (*cp != L_(')'))
254
- /* The closing brace is missing. Only match the NAN
258
+ retval = STRTOF_NAN (cp + 1, &endp, L_(')'));
259
+ if (*endp == L_(')'))
260
+ /* Consume the closing parenthesis. */
264
- /* This is a system-dependent way to specify the
265
- bitmask used for the NaN. We expect it to be
266
- a number which is put in the mantissa of the
269
- unsigned long long int mant;
271
- mant = STRTOULL (startp + 1, &endp, 0);
273
- SET_MANTISSA (retval, mant);
275
- /* Consume the closing brace. */
278
+ /* Only match the NAN part. */
283
Index: b/stdlib/strtod_nan.c
284
===================================================================
286
+++ b/stdlib/strtod_nan.c
288
+/* Convert string for NaN payload to corresponding NaN. Narrow
290
+ Copyright (C) 2015 Free Software Foundation, Inc.
291
+ This file is part of the GNU C Library.
293
+ The GNU C Library is free software; you can redistribute it and/or
294
+ modify it under the terms of the GNU Lesser General Public
295
+ License as published by the Free Software Foundation; either
296
+ version 2.1 of the License, or (at your option) any later version.
298
+ The GNU C Library is distributed in the hope that it will be useful,
299
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
300
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
301
+ Lesser General Public License for more details.
303
+ You should have received a copy of the GNU Lesser General Public
304
+ License along with the GNU C Library; if not, see
305
+ <http://www.gnu.org/licenses/>. */
307
+#include <strtod_nan_narrow.h>
308
+#include <strtod_nan_double.h>
310
+#define STRTOD_NAN __strtod_nan
311
+#include <strtod_nan_main.c>
312
Index: b/stdlib/strtod_nan_double.h
313
===================================================================
315
+++ b/stdlib/strtod_nan_double.h
317
+/* Convert string for NaN payload to corresponding NaN. For double.
318
+ Copyright (C) 1997-2015 Free Software Foundation, Inc.
319
+ This file is part of the GNU C Library.
321
+ The GNU C Library is free software; you can redistribute it and/or
322
+ modify it under the terms of the GNU Lesser General Public
323
+ License as published by the Free Software Foundation; either
324
+ version 2.1 of the License, or (at your option) any later version.
326
+ The GNU C Library is distributed in the hope that it will be useful,
327
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
328
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
329
+ Lesser General Public License for more details.
331
+ You should have received a copy of the GNU Lesser General Public
332
+ License along with the GNU C Library; if not, see
333
+ <http://www.gnu.org/licenses/>. */
335
+#define FLOAT double
336
+#define SET_MANTISSA(flt, mant) \
339
+ union ieee754_double u; \
341
+ u.ieee_nan.mantissa0 = (mant) >> 32; \
342
+ u.ieee_nan.mantissa1 = (mant); \
343
+ if ((u.ieee.mantissa0 | u.ieee.mantissa1) != 0) \
347
Index: b/stdlib/strtod_nan_float.h
348
===================================================================
350
+++ b/stdlib/strtod_nan_float.h
352
+/* Convert string for NaN payload to corresponding NaN. For float.
353
+ Copyright (C) 1997-2015 Free Software Foundation, Inc.
354
+ This file is part of the GNU C Library.
356
+ The GNU C Library is free software; you can redistribute it and/or
357
+ modify it under the terms of the GNU Lesser General Public
358
+ License as published by the Free Software Foundation; either
359
+ version 2.1 of the License, or (at your option) any later version.
361
+ The GNU C Library is distributed in the hope that it will be useful,
362
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
363
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
364
+ Lesser General Public License for more details.
366
+ You should have received a copy of the GNU Lesser General Public
367
+ License along with the GNU C Library; if not, see
368
+ <http://www.gnu.org/licenses/>. */
371
+#define SET_MANTISSA(flt, mant) \
374
+ union ieee754_float u; \
376
+ u.ieee_nan.mantissa = (mant); \
377
+ if (u.ieee.mantissa != 0) \
381
Index: b/stdlib/strtod_nan_main.c
382
===================================================================
384
+++ b/stdlib/strtod_nan_main.c
386
+/* Convert string for NaN payload to corresponding NaN.
387
+ Copyright (C) 1997-2015 Free Software Foundation, Inc.
388
+ This file is part of the GNU C Library.
390
+ The GNU C Library is free software; you can redistribute it and/or
391
+ modify it under the terms of the GNU Lesser General Public
392
+ License as published by the Free Software Foundation; either
393
+ version 2.1 of the License, or (at your option) any later version.
395
+ The GNU C Library is distributed in the hope that it will be useful,
396
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
397
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
398
+ Lesser General Public License for more details.
400
+ You should have received a copy of the GNU Lesser General Public
401
+ License along with the GNU C Library; if not, see
402
+ <http://www.gnu.org/licenses/>. */
404
+#include <ieee754.h>
411
+/* If STR starts with an optional n-char-sequence as defined by ISO C
412
+ (a sequence of ASCII letters, digits and underscores), followed by
413
+ ENDC, return a NaN whose payload is set based on STR. Otherwise,
414
+ return a default NAN. If ENDPTR is not NULL, set *ENDPTR to point
415
+ to the character after the initial n-char-sequence. */
419
+STRTOD_NAN (const STRING_TYPE *str, STRING_TYPE **endptr, STRING_TYPE endc)
421
+ const STRING_TYPE *cp = str;
423
+ while ((*cp >= L_('0') && *cp <= L_('9'))
424
+ || (*cp >= L_('A') && *cp <= L_('Z'))
425
+ || (*cp >= L_('a') && *cp <= L_('z'))
429
+ FLOAT retval = NAN;
433
+ /* This is a system-dependent way to specify the bitmask used for
434
+ the NaN. We expect it to be a number which is put in the
435
+ mantissa of the number. */
437
+ unsigned long long int mant;
439
+ mant = STRTOULL (str, &endp, 0);
441
+ SET_MANTISSA (retval, mant);
444
+ if (endptr != NULL)
445
+ *endptr = (STRING_TYPE *) cp;
448
+libc_hidden_def (STRTOD_NAN)
449
Index: b/stdlib/strtod_nan_narrow.h
450
===================================================================
452
+++ b/stdlib/strtod_nan_narrow.h
454
+/* Convert string for NaN payload to corresponding NaN. Narrow strings.
455
+ Copyright (C) 1997-2015 Free Software Foundation, Inc.
456
+ This file is part of the GNU C Library.
458
+ The GNU C Library is free software; you can redistribute it and/or
459
+ modify it under the terms of the GNU Lesser General Public
460
+ License as published by the Free Software Foundation; either
461
+ version 2.1 of the License, or (at your option) any later version.
463
+ The GNU C Library is distributed in the hope that it will be useful,
464
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
465
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
466
+ Lesser General Public License for more details.
468
+ You should have received a copy of the GNU Lesser General Public
469
+ License along with the GNU C Library; if not, see
470
+ <http://www.gnu.org/licenses/>. */
472
+#define STRING_TYPE char
474
+#define STRTOULL(S, E, B) ____strtoull_l_internal ((S), (E), (B), 0, \
476
Index: b/stdlib/strtod_nan_wide.h
477
===================================================================
479
+++ b/stdlib/strtod_nan_wide.h
481
+/* Convert string for NaN payload to corresponding NaN. Wide strings.
482
+ Copyright (C) 1997-2015 Free Software Foundation, Inc.
483
+ This file is part of the GNU C Library.
485
+ The GNU C Library is free software; you can redistribute it and/or
486
+ modify it under the terms of the GNU Lesser General Public
487
+ License as published by the Free Software Foundation; either
488
+ version 2.1 of the License, or (at your option) any later version.
490
+ The GNU C Library is distributed in the hope that it will be useful,
491
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
492
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
493
+ Lesser General Public License for more details.
495
+ You should have received a copy of the GNU Lesser General Public
496
+ License along with the GNU C Library; if not, see
497
+ <http://www.gnu.org/licenses/>. */
499
+#define STRING_TYPE wchar_t
500
+#define L_(Ch) L##Ch
501
+#define STRTOULL(S, E, B) ____wcstoull_l_internal ((S), (E), (B), 0, \
503
Index: b/stdlib/strtof_l.c
504
===================================================================
505
--- a/stdlib/strtof_l.c
506
+++ b/stdlib/strtof_l.c
510
extern float ____strtof_l_internal (const char *, char **, int, __locale_t);
511
-extern unsigned long long int ____strtoull_l_internal (const char *, char **,
512
- int, int, __locale_t);
517
# define STRTOF wcstof_l
518
# define __STRTOF __wcstof_l
519
+# define STRTOF_NAN __wcstof_nan
521
# define STRTOF strtof_l
522
# define __STRTOF __strtof_l
523
+# define STRTOF_NAN __strtof_nan
525
#define MPN2FLOAT __mpn_construct_float
526
#define FLOAT_HUGE_VAL HUGE_VALF
527
-#define SET_MANTISSA(flt, mant) \
528
- do { union ieee754_float u; \
530
- u.ieee_nan.mantissa = (mant); \
531
- if (u.ieee.mantissa != 0) \
535
#include "strtod_l.c"
536
Index: b/stdlib/strtof_nan.c
537
===================================================================
539
+++ b/stdlib/strtof_nan.c
541
+/* Convert string for NaN payload to corresponding NaN. Narrow
543
+ Copyright (C) 2015 Free Software Foundation, Inc.
544
+ This file is part of the GNU C Library.
546
+ The GNU C Library is free software; you can redistribute it and/or
547
+ modify it under the terms of the GNU Lesser General Public
548
+ License as published by the Free Software Foundation; either
549
+ version 2.1 of the License, or (at your option) any later version.
551
+ The GNU C Library is distributed in the hope that it will be useful,
552
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
553
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
554
+ Lesser General Public License for more details.
556
+ You should have received a copy of the GNU Lesser General Public
557
+ License along with the GNU C Library; if not, see
558
+ <http://www.gnu.org/licenses/>. */
560
+#include <strtod_nan_narrow.h>
561
+#include <strtod_nan_float.h>
563
+#define STRTOD_NAN __strtof_nan
564
+#include <strtod_nan_main.c>
565
Index: b/stdlib/strtold_nan.c
566
===================================================================
568
+++ b/stdlib/strtold_nan.c
570
+/* Convert string for NaN payload to corresponding NaN. Narrow
571
+ strings, long double.
572
+ Copyright (C) 2015 Free Software Foundation, Inc.
573
+ This file is part of the GNU C Library.
575
+ The GNU C Library is free software; you can redistribute it and/or
576
+ modify it under the terms of the GNU Lesser General Public
577
+ License as published by the Free Software Foundation; either
578
+ version 2.1 of the License, or (at your option) any later version.
580
+ The GNU C Library is distributed in the hope that it will be useful,
581
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
582
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
583
+ Lesser General Public License for more details.
585
+ You should have received a copy of the GNU Lesser General Public
586
+ License along with the GNU C Library; if not, see
587
+ <http://www.gnu.org/licenses/>. */
591
+/* This function is unused if long double and double have the same
593
+#ifndef __NO_LONG_DOUBLE_MATH
594
+# include <strtod_nan_narrow.h>
595
+# include <strtod_nan_ldouble.h>
597
+# define STRTOD_NAN __strtold_nan
598
+# include <strtod_nan_main.c>
600
Index: b/sysdeps/ieee754/ldbl-128/strtod_nan_ldouble.h
601
===================================================================
603
+++ b/sysdeps/ieee754/ldbl-128/strtod_nan_ldouble.h
605
+/* Convert string for NaN payload to corresponding NaN. For ldbl-128.
606
+ Copyright (C) 1997-2015 Free Software Foundation, Inc.
607
+ This file is part of the GNU C Library.
609
+ The GNU C Library is free software; you can redistribute it and/or
610
+ modify it under the terms of the GNU Lesser General Public
611
+ License as published by the Free Software Foundation; either
612
+ version 2.1 of the License, or (at your option) any later version.
614
+ The GNU C Library is distributed in the hope that it will be useful,
615
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
616
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
617
+ Lesser General Public License for more details.
619
+ You should have received a copy of the GNU Lesser General Public
620
+ License along with the GNU C Library; if not, see
621
+ <http://www.gnu.org/licenses/>. */
623
+#define FLOAT long double
624
+#define SET_MANTISSA(flt, mant) \
627
+ union ieee854_long_double u; \
629
+ u.ieee_nan.mantissa0 = 0; \
630
+ u.ieee_nan.mantissa1 = 0; \
631
+ u.ieee_nan.mantissa2 = (mant) >> 32; \
632
+ u.ieee_nan.mantissa3 = (mant); \
633
+ if ((u.ieee.mantissa0 | u.ieee.mantissa1 \
634
+ | u.ieee.mantissa2 | u.ieee.mantissa3) != 0) \
638
Index: b/sysdeps/ieee754/ldbl-128/strtold_l.c
639
===================================================================
640
--- a/sysdeps/ieee754/ldbl-128/strtold_l.c
641
+++ b/sysdeps/ieee754/ldbl-128/strtold_l.c
644
# define STRTOF wcstold_l
645
# define __STRTOF __wcstold_l
646
+# define STRTOF_NAN __wcstold_nan
648
# define STRTOF strtold_l
649
# define __STRTOF __strtold_l
650
+# define STRTOF_NAN __strtold_nan
652
#define MPN2FLOAT __mpn_construct_long_double
653
#define FLOAT_HUGE_VAL HUGE_VALL
654
-#define SET_MANTISSA(flt, mant) \
655
- do { union ieee854_long_double u; \
657
- u.ieee_nan.mantissa0 = 0; \
658
- u.ieee_nan.mantissa1 = 0; \
659
- u.ieee_nan.mantissa2 = (mant) >> 32; \
660
- u.ieee_nan.mantissa3 = (mant); \
661
- if ((u.ieee.mantissa0 | u.ieee.mantissa1 \
662
- | u.ieee.mantissa2 | u.ieee.mantissa3) != 0) \
666
#include <strtod_l.c>
667
Index: b/sysdeps/ieee754/ldbl-128ibm/strtod_nan_ldouble.h
668
===================================================================
670
+++ b/sysdeps/ieee754/ldbl-128ibm/strtod_nan_ldouble.h
672
+/* Convert string for NaN payload to corresponding NaN. For ldbl-128ibm.
673
+ Copyright (C) 1997-2015 Free Software Foundation, Inc.
674
+ This file is part of the GNU C Library.
676
+ The GNU C Library is free software; you can redistribute it and/or
677
+ modify it under the terms of the GNU Lesser General Public
678
+ License as published by the Free Software Foundation; either
679
+ version 2.1 of the License, or (at your option) any later version.
681
+ The GNU C Library is distributed in the hope that it will be useful,
682
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
683
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
684
+ Lesser General Public License for more details.
686
+ You should have received a copy of the GNU Lesser General Public
687
+ License along with the GNU C Library; if not, see
688
+ <http://www.gnu.org/licenses/>. */
690
+#define FLOAT long double
691
+#define SET_MANTISSA(flt, mant) \
694
+ union ibm_extended_long_double u; \
696
+ u.d[0].ieee_nan.mantissa0 = (mant) >> 32; \
697
+ u.d[0].ieee_nan.mantissa1 = (mant); \
698
+ if ((u.d[0].ieee.mantissa0 | u.d[0].ieee.mantissa1) != 0) \
702
Index: b/sysdeps/ieee754/ldbl-128ibm/strtold_l.c
703
===================================================================
704
--- a/sysdeps/ieee754/ldbl-128ibm/strtold_l.c
705
+++ b/sysdeps/ieee754/ldbl-128ibm/strtold_l.c
706
@@ -30,25 +30,19 @@ extern long double ____new_wcstold_l (co
707
# define STRTOF __new_wcstold_l
708
# define __STRTOF ____new_wcstold_l
709
# define ____STRTOF_INTERNAL ____wcstold_l_internal
710
+# define STRTOF_NAN __wcstold_nan
712
extern long double ____new_strtold_l (const char *, char **, __locale_t);
713
# define STRTOF __new_strtold_l
714
# define __STRTOF ____new_strtold_l
715
# define ____STRTOF_INTERNAL ____strtold_l_internal
716
+# define STRTOF_NAN __strtold_nan
718
extern __typeof (__STRTOF) STRTOF;
719
libc_hidden_proto (__STRTOF)
720
libc_hidden_proto (STRTOF)
721
#define MPN2FLOAT __mpn_construct_long_double
722
#define FLOAT_HUGE_VAL HUGE_VALL
723
-# define SET_MANTISSA(flt, mant) \
724
- do { union ibm_extended_long_double u; \
726
- u.d[0].ieee_nan.mantissa0 = (mant) >> 32; \
727
- u.d[0].ieee_nan.mantissa1 = (mant); \
728
- if ((u.d[0].ieee.mantissa0 | u.d[0].ieee.mantissa1) != 0) \
732
#include <strtod_l.c>
734
Index: b/sysdeps/ieee754/ldbl-64-128/strtold_l.c
735
===================================================================
736
--- a/sysdeps/ieee754/ldbl-64-128/strtold_l.c
737
+++ b/sysdeps/ieee754/ldbl-64-128/strtold_l.c
738
@@ -30,28 +30,19 @@ extern long double ____new_wcstold_l (co
739
# define STRTOF __new_wcstold_l
740
# define __STRTOF ____new_wcstold_l
741
# define ____STRTOF_INTERNAL ____wcstold_l_internal
742
+# define STRTOF_NAN __wcstold_nan
744
extern long double ____new_strtold_l (const char *, char **, __locale_t);
745
# define STRTOF __new_strtold_l
746
# define __STRTOF ____new_strtold_l
747
# define ____STRTOF_INTERNAL ____strtold_l_internal
748
+# define STRTOF_NAN __strtold_nan
750
extern __typeof (__STRTOF) STRTOF;
751
libc_hidden_proto (__STRTOF)
752
libc_hidden_proto (STRTOF)
753
#define MPN2FLOAT __mpn_construct_long_double
754
#define FLOAT_HUGE_VAL HUGE_VALL
755
-#define SET_MANTISSA(flt, mant) \
756
- do { union ieee854_long_double u; \
758
- u.ieee_nan.mantissa0 = 0; \
759
- u.ieee_nan.mantissa1 = 0; \
760
- u.ieee_nan.mantissa2 = (mant) >> 32; \
761
- u.ieee_nan.mantissa3 = (mant); \
762
- if ((u.ieee.mantissa0 | u.ieee.mantissa1 \
763
- | u.ieee.mantissa2 | u.ieee.mantissa3) != 0) \
767
#include <strtod_l.c>
769
Index: b/sysdeps/ieee754/ldbl-96/strtod_nan_ldouble.h
770
===================================================================
772
+++ b/sysdeps/ieee754/ldbl-96/strtod_nan_ldouble.h
774
+/* Convert string for NaN payload to corresponding NaN. For ldbl-96.
775
+ Copyright (C) 1997-2015 Free Software Foundation, Inc.
776
+ This file is part of the GNU C Library.
778
+ The GNU C Library is free software; you can redistribute it and/or
779
+ modify it under the terms of the GNU Lesser General Public
780
+ License as published by the Free Software Foundation; either
781
+ version 2.1 of the License, or (at your option) any later version.
783
+ The GNU C Library is distributed in the hope that it will be useful,
784
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
785
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
786
+ Lesser General Public License for more details.
788
+ You should have received a copy of the GNU Lesser General Public
789
+ License along with the GNU C Library; if not, see
790
+ <http://www.gnu.org/licenses/>. */
792
+#define FLOAT long double
793
+#define SET_MANTISSA(flt, mant) \
796
+ union ieee854_long_double u; \
798
+ u.ieee_nan.mantissa0 = (mant) >> 32; \
799
+ u.ieee_nan.mantissa1 = (mant); \
800
+ if ((u.ieee.mantissa0 | u.ieee.mantissa1) != 0) \
804
Index: b/sysdeps/ieee754/ldbl-96/strtold_l.c
805
===================================================================
806
--- a/sysdeps/ieee754/ldbl-96/strtold_l.c
807
+++ b/sysdeps/ieee754/ldbl-96/strtold_l.c
810
# define STRTOF wcstold_l
811
# define __STRTOF __wcstold_l
812
+# define STRTOF_NAN __wcstold_nan
814
# define STRTOF strtold_l
815
# define __STRTOF __strtold_l
816
+# define STRTOF_NAN __strtold_nan
818
#define MPN2FLOAT __mpn_construct_long_double
819
#define FLOAT_HUGE_VAL HUGE_VALL
820
-#define SET_MANTISSA(flt, mant) \
821
- do { union ieee854_long_double u; \
823
- u.ieee_nan.mantissa0 = (mant) >> 32; \
824
- u.ieee_nan.mantissa1 = (mant); \
825
- if ((u.ieee.mantissa0 | u.ieee.mantissa1) != 0) \
829
#include <stdlib/strtod_l.c>
830
Index: b/wcsmbs/Makefile
831
===================================================================
832
--- a/wcsmbs/Makefile
833
+++ b/wcsmbs/Makefile
834
@@ -37,6 +37,7 @@ routines-$(OPTION_POSIX_C_LANG_WIDE_CHAR
835
wcstol wcstoul wcstoll wcstoull wcstod wcstold wcstof \
836
wcstol_l wcstoul_l wcstoll_l wcstoull_l \
837
wcstod_l wcstold_l wcstof_l \
838
+ wcstod_nan wcstold_nan wcstof_nan \
841
wcscoll_l wcsxfrm_l \
842
Index: b/wcsmbs/wcstod_l.c
843
===================================================================
844
--- a/wcsmbs/wcstod_l.c
845
+++ b/wcsmbs/wcstod_l.c
848
extern double ____wcstod_l_internal (const wchar_t *, wchar_t **, int,
850
-extern unsigned long long int ____wcstoull_l_internal (const wchar_t *,
851
- wchar_t **, int, int,
854
#define USE_WIDE_CHAR 1
856
Index: b/wcsmbs/wcstod_nan.c
857
===================================================================
859
+++ b/wcsmbs/wcstod_nan.c
861
+/* Convert string for NaN payload to corresponding NaN. Wide strings, double.
862
+ Copyright (C) 2015 Free Software Foundation, Inc.
863
+ This file is part of the GNU C Library.
865
+ The GNU C Library is free software; you can redistribute it and/or
866
+ modify it under the terms of the GNU Lesser General Public
867
+ License as published by the Free Software Foundation; either
868
+ version 2.1 of the License, or (at your option) any later version.
870
+ The GNU C Library is distributed in the hope that it will be useful,
871
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
872
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
873
+ Lesser General Public License for more details.
875
+ You should have received a copy of the GNU Lesser General Public
876
+ License along with the GNU C Library; if not, see
877
+ <http://www.gnu.org/licenses/>. */
879
+#include "../stdlib/strtod_nan_wide.h"
880
+#include "../stdlib/strtod_nan_double.h"
882
+#define STRTOD_NAN __wcstod_nan
883
+#include "../stdlib/strtod_nan_main.c"
884
Index: b/wcsmbs/wcstof_l.c
885
===================================================================
886
--- a/wcsmbs/wcstof_l.c
887
+++ b/wcsmbs/wcstof_l.c
890
extern float ____wcstof_l_internal (const wchar_t *, wchar_t **, int,
892
-extern unsigned long long int ____wcstoull_l_internal (const wchar_t *,
893
- wchar_t **, int, int,
896
#include <stdlib/strtof_l.c>
897
Index: b/wcsmbs/wcstof_nan.c
898
===================================================================
900
+++ b/wcsmbs/wcstof_nan.c
902
+/* Convert string for NaN payload to corresponding NaN. Wide strings, float.
903
+ Copyright (C) 2015 Free Software Foundation, Inc.
904
+ This file is part of the GNU C Library.
906
+ The GNU C Library is free software; you can redistribute it and/or
907
+ modify it under the terms of the GNU Lesser General Public
908
+ License as published by the Free Software Foundation; either
909
+ version 2.1 of the License, or (at your option) any later version.
911
+ The GNU C Library is distributed in the hope that it will be useful,
912
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
913
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
914
+ Lesser General Public License for more details.
916
+ You should have received a copy of the GNU Lesser General Public
917
+ License along with the GNU C Library; if not, see
918
+ <http://www.gnu.org/licenses/>. */
920
+#include "../stdlib/strtod_nan_wide.h"
921
+#include "../stdlib/strtod_nan_float.h"
923
+#define STRTOD_NAN __wcstof_nan
924
+#include "../stdlib/strtod_nan_main.c"
925
Index: b/wcsmbs/wcstold_l.c
926
===================================================================
927
--- a/wcsmbs/wcstold_l.c
928
+++ b/wcsmbs/wcstold_l.c
931
extern long double ____wcstold_l_internal (const wchar_t *, wchar_t **, int,
933
-extern unsigned long long int ____wcstoull_l_internal (const wchar_t *,
934
- wchar_t **, int, int,
937
#include <strtold_l.c>
938
Index: b/wcsmbs/wcstold_nan.c
939
===================================================================
941
+++ b/wcsmbs/wcstold_nan.c
943
+/* Convert string for NaN payload to corresponding NaN. Wide strings,
945
+ Copyright (C) 2015 Free Software Foundation, Inc.
946
+ This file is part of the GNU C Library.
948
+ The GNU C Library is free software; you can redistribute it and/or
949
+ modify it under the terms of the GNU Lesser General Public
950
+ License as published by the Free Software Foundation; either
951
+ version 2.1 of the License, or (at your option) any later version.
953
+ The GNU C Library is distributed in the hope that it will be useful,
954
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
955
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
956
+ Lesser General Public License for more details.
958
+ You should have received a copy of the GNU Lesser General Public
959
+ License along with the GNU C Library; if not, see
960
+ <http://www.gnu.org/licenses/>. */
964
+/* This function is unused if long double and double have the same
966
+#ifndef __NO_LONG_DOUBLE_MATH
967
+# include "../stdlib/strtod_nan_wide.h"
968
+# include <strtod_nan_ldouble.h>
970
+# define STRTOD_NAN __wcstold_nan
971
+# include "../stdlib/strtod_nan_main.c"