1 These changes are mostly inherited from previous iterations
2 of gnulib-printf-in-glib.
4 Here are explanations for some of them:
5 * g-gnulib.h is a minimal replacement for gnulib config.h
6 * gnulib_math.h is a processed copy of gnulib math.in.h
7 We can't keep it named math.h, since we need to include
8 both the system math.h and this header in some places.
9 * gnulib_math.h needs _GL_ATTRIBUTE_CONST, put it directly
10 there instead of getting it from config.h
11 Also, instead of copying _GL_FUNCDECL_RPL and _GL_WARN_ON_USE
12 we simply include headers where these macros are defined.
13 * isnan source files get extra includes, in gnulib these
14 were probably handled by makefiles and/or configure scripts
15 * glib has a test result named HAVE_LONG_LONG instead of HAVE_LONG_LONG_INT,
16 so make the code use that
17 * One of the goals of using this gnulib implementation in glib is
18 to have C99-compliant 3-digit exponent, therefore gnulib
19 ifdefs that *disable* that behaviour are altered to keep it enabled.
20 Another possible location for such a change is where %n use is
21 being enabled or disabled. That, however, is not activated anyway,
22 because this code is made not to use snprintf
23 * glib has G_MAXSIZE instead of SIZE_MAX, so use that
24 * The code is made to use glib alloca header
25 --- glib-82c3e92/glib/gnulib/asnprintf.c 2019-02-09 09:44:55.013866300 +0000
26 +++ glib-82c3e92/glib/gnulib/asnprintf.c 2019-02-09 10:08:46.444859600 +0000
31 +#include "g-gnulib.h"
34 #include "vasnprintf.h"
36 --- glib-82c3e92/glib/gnulib/isnand.c 2019-02-09 09:44:56.075691800 +0000
37 +++ glib-82c3e92/glib/gnulib/isnand.c 2019-02-09 10:09:35.443191100 +0000
40 /* Written by Bruno Haible <bruno@clisp.org>, 2008. */
43 +#include "gnulib_math.h"
44 +#include "isnand-nolibm.h"
46 --- glib-82c3e92/glib/gnulib/isnand-nolibm.h 2019-02-09 09:44:55.973651800 +0000
47 +++ glib-82c3e92/glib/gnulib/isnand-nolibm.h 2019-02-09 10:09:17.089604000 +0000
50 #if HAVE_ISNAND_IN_LIBC
51 /* Get declaration of isnan macro. */
53 +# include <gnulib_math.h>
55 /* GCC 4.0 and newer provides three built-ins for isnan. */
57 --- glib-82c3e92/glib/gnulib/isnanl.c 2019-02-09 09:44:56.285650400 +0000
58 +++ glib-82c3e92/glib/gnulib/isnanl.c 2019-02-09 10:10:00.060305200 +0000
60 /* Written by Bruno Haible <bruno@clisp.org>, 2007. */
62 #define USE_LONG_DOUBLE
64 +#include "gnulib_math.h"
65 +#include "isnanl-nolibm.h"
67 --- glib-82c3e92/glib/gnulib/isnanl-nolibm.h 2019-02-09 09:44:56.181628200 +0000
68 +++ glib-82c3e92/glib/gnulib/isnanl-nolibm.h 2019-02-09 10:09:45.731187400 +0000
71 #if HAVE_ISNANL_IN_LIBC
72 /* Get declaration of isnan macro or (older) isnanl function. */
74 +# include <gnulib_math.h>
76 /* GCC 4.0 and newer provides three built-ins for isnan. */
78 --- glib-82c3e92/glib/gnulib/printf-args.c 2019-02-09 09:44:57.147081400 +0000
79 +++ glib-82c3e92/glib/gnulib/printf-args.c 2019-02-09 10:10:45.869597700 +0000
84 +#include "g-gnulib.h"
87 #ifndef PRINTF_FETCHARGS
88 # include "printf-args.h"
91 ap->a.a_ulongint = va_arg (args, unsigned long int);
93 -#if HAVE_LONG_LONG_INT
95 case TYPE_LONGLONGINT:
96 ap->a.a_longlongint = va_arg (args, long long int);
99 case TYPE_COUNT_LONGINT_POINTER:
100 ap->a.a_count_longint_pointer = va_arg (args, long int *);
102 -#if HAVE_LONG_LONG_INT
104 case TYPE_COUNT_LONGLONGINT_POINTER:
105 ap->a.a_count_longlongint_pointer = va_arg (args, long long int *);
107 --- glib-82c3e92/glib/gnulib/printf-args.h 2019-02-09 09:44:57.245167700 +0000
108 +++ glib-82c3e92/glib/gnulib/printf-args.h 2019-02-09 10:10:55.543592500 +0000
113 -#if HAVE_LONG_LONG_INT
119 TYPE_COUNT_SHORT_POINTER,
120 TYPE_COUNT_INT_POINTER,
121 TYPE_COUNT_LONGINT_POINTER
122 -#if HAVE_LONG_LONG_INT
124 , TYPE_COUNT_LONGLONGINT_POINTER
130 unsigned long int a_ulongint;
131 -#if HAVE_LONG_LONG_INT
133 long long int a_longlongint;
134 unsigned long long int a_ulonglongint;
137 short * a_count_short_pointer;
138 int * a_count_int_pointer;
139 long int * a_count_longint_pointer;
140 -#if HAVE_LONG_LONG_INT
142 long long int * a_count_longlongint_pointer;
145 --- glib-82c3e92/glib/gnulib/printf-frexp.c 2019-02-09 09:44:57.355099800 +0000
146 +++ glib-82c3e92/glib/gnulib/printf-frexp.c 2019-02-09 10:11:15.476905600 +0000
152 +#include <gnulib_math.h>
153 #ifdef USE_LONG_DOUBLE
156 --- glib-82c3e92/glib/gnulib/printf-parse.c 2019-02-09 09:44:57.790835100 +0000
157 +++ glib-82c3e92/glib/gnulib/printf-parse.c 2019-02-09 10:11:32.783744500 +0000
162 +#include "g-gnulib.h"
166 # include "printf-parse.h"
171 -#if HAVE_LONG_LONG_INT
173 /* If 'long long' exists and is larger than 'long': */
174 if (flags >= 16 || (flags & 4))
175 type = TYPE_LONGLONGINT;
179 case 'o': case 'u': case 'x': case 'X':
180 -#if HAVE_LONG_LONG_INT
182 /* If 'long long' exists and is larger than 'long': */
183 if (flags >= 16 || (flags & 4))
184 type = TYPE_ULONGLONGINT;
189 -#if HAVE_LONG_LONG_INT
191 /* If 'long long' exists and is larger than 'long': */
192 if (flags >= 16 || (flags & 4))
193 type = TYPE_COUNT_LONGLONGINT_POINTER;
194 --- glib-82c3e92/glib/gnulib/vasnprintf.c 2019-02-09 09:44:58.585342000 +0000
195 +++ glib-82c3e92/glib/gnulib/vasnprintf.c 2019-02-09 10:22:13.196848200 +0000
197 DCHAR_IS_UINT16_T Set to 1 if DCHAR_T is uint16_t.
198 DCHAR_IS_UINT32_T Set to 1 if DCHAR_T is uint32_t. */
201 /* Tell glibc's <stdio.h> to provide a prototype for snprintf().
202 This must come before <config.h> because <config.h> may include
203 <features.h>, and once <features.h> has been included, it's too late. */
205 # define _GNU_SOURCE 1
213 -# include <alloca.h>
215 +#include "glib/galloca.h"
217 +#include "g-gnulib.h"
224 #if (NEED_PRINTF_DOUBLE || NEED_PRINTF_LONG_DOUBLE) && !defined IN_LIBINTL
226 +# include <gnulib_math.h>
230 #if (NEED_PRINTF_DOUBLE || NEED_PRINTF_INFINITE_DOUBLE) && !defined IN_LIBINTL
232 +# include <gnulib_math.h>
233 # include "isnand-nolibm.h"
236 #if (NEED_PRINTF_LONG_DOUBLE || NEED_PRINTF_INFINITE_LONG_DOUBLE) && !defined IN_LIBINTL
238 +# include <gnulib_math.h>
239 # include "isnanl-nolibm.h"
243 #if (NEED_PRINTF_DIRECTIVE_A || NEED_PRINTF_DOUBLE) && !defined IN_LIBINTL
245 +# include <gnulib_math.h>
246 # include "isnand-nolibm.h"
247 # include "printf-frexp.h"
250 #if (NEED_PRINTF_DIRECTIVE_A || NEED_PRINTF_LONG_DOUBLE) && !defined IN_LIBINTL
252 +# include <gnulib_math.h>
253 # include "isnanl-nolibm.h"
254 # include "printf-frexpl.h"
256 @@ -1553,7 +1555,7 @@
259 case 'd': case 'i': case 'u':
260 -# if HAVE_LONG_LONG_INT
262 if (type == TYPE_LONGLONGINT || type == TYPE_ULONGLONGINT)
264 (unsigned int) (sizeof (unsigned long long) * CHAR_BIT
265 @@ -1583,7 +1585,7 @@
269 -# if HAVE_LONG_LONG_INT
271 if (type == TYPE_LONGLONGINT || type == TYPE_ULONGLONGINT)
273 (unsigned int) (sizeof (unsigned long long) * CHAR_BIT
274 @@ -1611,7 +1613,7 @@
278 -# if HAVE_LONG_LONG_INT
280 if (type == TYPE_LONGLONGINT || type == TYPE_ULONGLONGINT)
282 (unsigned int) (sizeof (unsigned long long) * CHAR_BIT
283 @@ -1939,7 +1941,7 @@
284 case TYPE_COUNT_LONGINT_POINTER:
285 *a.arg[dp->arg_index].a.a_count_longint_pointer = length;
287 -#if HAVE_LONG_LONG_INT
289 case TYPE_COUNT_LONGLONGINT_POINTER:
290 *a.arg[dp->arg_index].a.a_count_longlongint_pointer = length;
292 @@ -4245,7 +4247,7 @@
293 static const wchar_t decimal_format[] =
294 /* Produce the same number of exponent digits
295 as the native printf implementation. */
296 -# if defined _WIN32 && ! defined __CYGWIN__
297 +# if (defined _WIN32 && FALSE) && ! defined __CYGWIN__
298 { '%', '+', '.', '3', 'd', '\0' };
300 { '%', '+', '.', '2', 'd', '\0' };
301 @@ -4259,7 +4261,7 @@
302 static const char decimal_format[] =
303 /* Produce the same number of exponent digits
304 as the native printf implementation. */
305 -# if defined _WIN32 && ! defined __CYGWIN__
306 +# if (defined _WIN32 && FALSE) && ! defined __CYGWIN__
310 @@ -4438,7 +4440,7 @@
311 static const wchar_t decimal_format[] =
312 /* Produce the same number of exponent digits
313 as the native printf implementation. */
314 -# if defined _WIN32 && ! defined __CYGWIN__
315 +# if (defined _WIN32 && FALSE) && ! defined __CYGWIN__
316 { '%', '+', '.', '3', 'd', '\0' };
318 { '%', '+', '.', '2', 'd', '\0' };
319 @@ -4452,7 +4454,7 @@
320 static const char decimal_format[] =
321 /* Produce the same number of exponent digits
322 as the native printf implementation. */
323 -# if defined _WIN32 && ! defined __CYGWIN__
324 +# if (defined _WIN32 && FALSE) && ! defined __CYGWIN__
328 @@ -4510,7 +4512,7 @@
330 /* Produce the same number of exponent digits as
331 the native printf implementation. */
332 -# if defined _WIN32 && ! defined __CYGWIN__
333 +# if (defined _WIN32 && FALSE) && ! defined __CYGWIN__
337 @@ -4835,10 +4837,10 @@
341 -#if HAVE_LONG_LONG_INT
343 case TYPE_LONGLONGINT:
344 case TYPE_ULONGLONGINT:
345 -# if defined _WIN32 && ! defined __CYGWIN__
346 +# if (defined _WIN32 && FALSE) && ! defined __CYGWIN__
350 @@ -5063,7 +5065,7 @@
354 -#if HAVE_LONG_LONG_INT
356 case TYPE_LONGLONGINT:
358 long long int arg = a.arg[dp->arg_index].a.a_longlongint;
359 --- glib-82c3e92/glib/gnulib/xsize.h 2019-02-09 09:44:59.231076600 +0000
360 +++ glib-82c3e92/glib/gnulib/xsize.h 2019-02-09 10:21:28.789553900 +0000
371 +/* Get G_MAXSIZE. */
376 returns a piece of memory that is way too small, and the program then
377 crashes while attempting to fill the memory.
378 To avoid this, the functions and macros in this file check for overflow.
379 - The convention is that SIZE_MAX represents overflow.
380 - malloc (SIZE_MAX) is not guaranteed to fail -- think of a malloc
381 + The convention is that G_MAXSIZE represents overflow.
382 + malloc (G_MAXSIZE) is not guaranteed to fail -- think of a malloc
383 implementation that uses mmap --, it's recommended to use size_overflow_p()
384 or size_in_bounds_p() before invoking malloc().
385 The example thus becomes:
388 /* Convert an arbitrary value >= 0 to type size_t. */
389 #define xcast_size_t(N) \
390 - ((N) <= SIZE_MAX ? (size_t) (N) : SIZE_MAX)
391 + ((N) <= G_MAXSIZE ? (size_t) (N) : G_MAXSIZE)
393 /* Sum of two sizes, with overflow check. */
396 xsum (size_t size1, size_t size2)
398 size_t sum = size1 + size2;
399 - return (sum >= size1 ? sum : SIZE_MAX);
400 + return (sum >= size1 ? sum : G_MAXSIZE);
403 /* Sum of three sizes, with overflow check. */
405 xmax (size_t size1, size_t size2)
407 /* No explicit check is needed here, because for any n:
408 - max (SIZE_MAX, n) == SIZE_MAX and max (n, SIZE_MAX) == SIZE_MAX. */
409 + max (G_MAXSIZE, n) == G_MAXSIZE and max (n, G_MAXSIZE) == G_MAXSIZE. */
410 return (size1 >= size2 ? size1 : size2);
413 /* Multiplication of a count with an element size, with overflow check.
414 The count must be >= 0 and the element size must be > 0.
415 This is a macro, not a function, so that it works correctly even
416 - when N is of a wider type and N > SIZE_MAX. */
417 + when N is of a wider type and N > G_MAXSIZE. */
418 #define xtimes(N, ELSIZE) \
419 - ((N) <= SIZE_MAX / (ELSIZE) ? (size_t) (N) * (ELSIZE) : SIZE_MAX)
420 + ((N) <= G_MAXSIZE / (ELSIZE) ? (size_t) (N) * (ELSIZE) : G_MAXSIZE)
422 /* Check for overflow. */
423 #define size_overflow_p(SIZE) \
424 - ((SIZE) == SIZE_MAX)
425 + ((SIZE) == G_MAXSIZE)
426 /* Check against overflow. */
427 #define size_in_bounds_p(SIZE) \
428 - ((SIZE) != SIZE_MAX)
429 + ((SIZE) != G_MAXSIZE)
431 _GL_INLINE_HEADER_END
433 --- a/glib/gnulib/gnulib_math.h.in
434 +++ b/glib/gnulib/gnulib_math.h.in
436 /* The include_next requires a split double-inclusion guard. */
437 #@INCLUDE_NEXT_AS_FIRST_DIRECTIVE@ @NEXT_AS_FIRST_DIRECTIVE_MATH_H@
439 +/* The __const__ attribute was added in gcc 2.95. */
440 +#if __GNUC__ > 2 || (__GNUC__ == 2 && __GNUC_MINOR__ >= 95)
441 +# define _GL_ATTRIBUTE_CONST __attribute__ ((__const__))
443 +# define _GL_ATTRIBUTE_CONST /* empty */
446 #ifndef _@GUARD_PREFIX@_MATH_H
447 #define _@GUARD_PREFIX@_MATH_H
449 @@ -41,9 +48,9 @@ _GL_INLINE_HEADER_BEGIN
450 # define _GL_MATH_INLINE _GL_INLINE
453 -/* The definitions of _GL_FUNCDECL_RPL etc. are copied here. */
454 +#include "c++defs.h"
456 -/* The definition of _GL_ARG_NONNULL is copied here. */
457 +#include "arg-nonnull.h"
459 /* The definition of _GL_WARN_ON_USE is copied here. */