160-flag-reallocarray.patch 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194
  1. --- a/lib/ialloc.h
  2. +++ b/lib/ialloc.h
  3. @@ -91,6 +91,8 @@ icalloc (idx_t n, idx_t s)
  4. return calloc (n, s);
  5. }
  6. +#if GNULIB_REALLOCARRAY
  7. +
  8. /* ireallocarray (ptr, num, size) is like reallocarray (ptr, num, size).
  9. It returns a non-NULL pointer to num * size bytes of memory.
  10. Upon failure, it returns NULL with errno set. */
  11. @@ -102,6 +104,8 @@ ireallocarray (void *p, idx_t n, idx_t s
  12. : _gl_alloc_nomem ());
  13. }
  14. +#endif /* GNULIB_REALLOCARRAY */
  15. +
  16. #ifdef __cplusplus
  17. }
  18. #endif
  19. --- a/lib/xmalloc.c
  20. +++ b/lib/xmalloc.c
  21. @@ -51,12 +51,16 @@ ximalloc (idx_t s)
  22. return check_nonnull (imalloc (s));
  23. }
  24. +#if GNULIB_REALLOCARRAY
  25. +
  26. char *
  27. xcharalloc (size_t n)
  28. {
  29. return XNMALLOC (n, char);
  30. }
  31. +#endif /* GNULIB_REALLOCARRAY */
  32. +
  33. /* Change the size of an allocated block of memory P to S bytes,
  34. with error checking. */
  35. @@ -75,6 +79,8 @@ xirealloc (void *p, idx_t s)
  36. return check_nonnull (irealloc (p, s));
  37. }
  38. +#if GNULIB_REALLOCARRAY
  39. +
  40. /* Change the size of an allocated block of memory P to an array of N
  41. objects each of S bytes, with error checking. */
  42. @@ -205,6 +211,8 @@ x2nrealloc (void *p, size_t *pn, size_t
  43. return p;
  44. }
  45. +#endif /* GNULIB_REALLOCARRAY */
  46. +
  47. /* Grow PA, which points to an array of *PN items, and return the
  48. location of the reallocated array, updating *PN to reflect its
  49. new size. The new array will contain at least N_INCR_MIN more
  50. --- a/lib/xalloc.h
  51. +++ b/lib/xalloc.h
  52. @@ -81,10 +81,16 @@ void *xrealloc (void *p, size_t s)
  53. _GL_ATTRIBUTE_ALLOC_SIZE ((2));
  54. void *xirealloc (void *p, idx_t s)
  55. _GL_ATTRIBUTE_ALLOC_SIZE ((2)) _GL_ATTRIBUTE_RETURNS_NONNULL;
  56. +
  57. +# if GNULIB_REALLOCARRAY
  58. +
  59. void *xreallocarray (void *p, size_t n, size_t s)
  60. _GL_ATTRIBUTE_ALLOC_SIZE ((2, 3));
  61. void *xireallocarray (void *p, idx_t n, idx_t s)
  62. _GL_ATTRIBUTE_ALLOC_SIZE ((2, 3)) _GL_ATTRIBUTE_RETURNS_NONNULL;
  63. +
  64. +# endif /* GNULIB_REALLOCARRAY */
  65. +
  66. void *x2realloc (void *p, size_t *ps) /* superseded by xpalloc */
  67. _GL_ATTRIBUTE_RETURNS_NONNULL;
  68. void *x2nrealloc (void *p, size_t *pn, size_t s) /* superseded by xpalloc */
  69. @@ -129,6 +135,7 @@ char *xstrdup (char const *str)
  70. # define XCALLOC(n, t) \
  71. ((t *) (sizeof (t) == 1 ? xzalloc (n) : xcalloc (n, sizeof (t))))
  72. +# if GNULIB_REALLOCARRAY
  73. /* Allocate an array of N objects, each with S bytes of memory,
  74. dynamically, with error checking. S must be nonzero. */
  75. @@ -156,6 +163,8 @@ char *xcharalloc (size_t n)
  76. _GL_ATTRIBUTE_MALLOC _GL_ATTRIBUTE_DEALLOC_FREE
  77. _GL_ATTRIBUTE_ALLOC_SIZE ((1)) _GL_ATTRIBUTE_RETURNS_NONNULL;
  78. +# endif /* GNULIB_REALLOCARRAY */
  79. +
  80. #endif /* GNULIB_XALLOC */
  81. --- a/lib/safe-alloc.h
  82. +++ b/lib/safe-alloc.h
  83. @@ -37,7 +37,6 @@ _GL_INLINE_HEADER_BEGIN
  84. extern "C" {
  85. #endif
  86. -
  87. /* Don't call this directly - use the macros below. */
  88. _GL_ATTRIBUTE_NODISCARD SAFE_ALLOC_INLINE int
  89. safe_alloc_check (void *ptr)
  90. @@ -72,6 +71,8 @@ safe_alloc_check (void *ptr)
  91. #define ALLOC_N(ptr, count) \
  92. safe_alloc_check ((ptr) = calloc (count, sizeof *(ptr)))
  93. +#if GNULIB_REALLOCARRAY
  94. +
  95. /**
  96. * ALLOC_N_UNINITIALIZED:
  97. * @ptr: pointer to allocated memory
  98. @@ -100,6 +101,8 @@ safe_alloc_check (void *ptr)
  99. #define REALLOC_N(ptr, count) \
  100. safe_alloc_check ((ptr) = reallocarray (ptr, count, sizeof *(ptr)))
  101. +#endif /* GNULIB_REALLOCARRAY */
  102. +
  103. /**
  104. * FREE:
  105. * @ptr: pointer holding address to be freed
  106. --- a/lib/dfa.c
  107. +++ b/lib/dfa.c
  108. @@ -1620,6 +1620,8 @@ lex (struct dfa *dfa)
  109. }
  110. }
  111. +#if GNULIB_REALLOCARRAY
  112. +
  113. static void
  114. addtok_mb (struct dfa *dfa, token t, char mbprop)
  115. {
  116. @@ -1674,6 +1676,8 @@ addtok_mb (struct dfa *dfa, token t, cha
  117. }
  118. }
  119. +#endif /* GNULIB_REALLOCARRAY */
  120. +
  121. static void addtok_wc (struct dfa *dfa, wint_t wc);
  122. /* Add the given token to the parse tree, maintaining the depth count and
  123. @@ -2934,6 +2938,8 @@ dfaanalyze (struct dfa *d, bool searchfl
  124. free (tmp.elems);
  125. }
  126. +#if GNULIB_REALLOCARRAY
  127. +
  128. /* Make sure D's state arrays are large enough to hold NEW_STATE. */
  129. static void
  130. realloc_trans_if_necessary (struct dfa *d)
  131. @@ -2969,6 +2975,8 @@ realloc_trans_if_necessary (struct dfa *
  132. }
  133. }
  134. +#endif /* GNULIB_REALLOCARRAY */
  135. +
  136. /*
  137. Calculate the transition table for a new state derived from state s
  138. for a compiled dfa d after input character uc, and return the new
  139. @@ -4010,6 +4018,8 @@ freelist (char **cpp)
  140. free (*cpp++);
  141. }
  142. +#if GNULIB_REALLOCARRAY
  143. +
  144. static char **
  145. enlistnew (char **cpp, char *new)
  146. {
  147. @@ -4046,6 +4056,8 @@ enlist (char **cpp, char const *str, idx
  148. return enlistnew (cpp, ximemdup0 (str, len));
  149. }
  150. +#endif /* GNULIB_REALLOCARRAY */
  151. +
  152. /* Given pointers to two strings, return a pointer to an allocated
  153. list of their distinct common substrings. */
  154. static char **
  155. --- a/lib/readtokens.c
  156. +++ b/lib/readtokens.c
  157. @@ -128,6 +128,8 @@ readtoken (FILE *stream,
  158. return i;
  159. }
  160. +#if GNULIB_REALLOCARRAY
  161. +
  162. /* Build a NULL-terminated array of pointers to tokens
  163. read from STREAM. Return the number of tokens read.
  164. All storage is obtained through calls to xmalloc-like functions.
  165. @@ -190,3 +192,5 @@ readtokens (FILE *stream,
  166. free (lengths);
  167. return n_tokens;
  168. }
  169. +
  170. +#endif /* GNULIB_REALLOCARRAY */