160-flag-reallocarray.patch 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115
  1. --- a/lib/ialloc.h
  2. +++ b/lib/ialloc.h
  3. @@ -106,6 +106,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. @@ -131,6 +133,8 @@ ireallocarray (void *p, idx_t n, idx_t s
  12. return _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 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 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. @@ -129,6 +129,7 @@ char *xstrdup (char const *str)
  53. # define XCALLOC(n, t) \
  54. ((t *) (sizeof (t) == 1 ? xzalloc (n) : xcalloc (n, sizeof (t))))
  55. +# if GNULIB_REALLOCARRAY
  56. /* Allocate an array of N objects, each with S bytes of memory,
  57. dynamically, with error checking. S must be nonzero. */
  58. @@ -156,6 +157,8 @@ char *xcharalloc (size_t n)
  59. _GL_ATTRIBUTE_MALLOC _GL_ATTRIBUTE_DEALLOC_FREE
  60. _GL_ATTRIBUTE_ALLOC_SIZE ((1)) _GL_ATTRIBUTE_RETURNS_NONNULL;
  61. +# endif /* GNULIB_REALLOCARRAY */
  62. +
  63. #endif /* GNULIB_XALLOC */
  64. --- a/lib/safe-alloc.h
  65. +++ b/lib/safe-alloc.h
  66. @@ -36,6 +36,8 @@ _GL_INLINE_HEADER_BEGIN
  67. # define SAFE_ALLOC_INLINE _GL_INLINE
  68. #endif
  69. +#if GNULIB_REALLOCARRAY
  70. +
  71. /* Don't call these directly - use the macros below. */
  72. SAFE_ALLOC_INLINE void *
  73. safe_alloc_realloc_n (void *ptr, size_t count, size_t size)
  74. @@ -51,6 +53,9 @@ safe_alloc_realloc_n (void *ptr, size_t
  75. #endif
  76. return ptr;
  77. }
  78. +
  79. +#endif /* GNULIB_REALLOCARRAY */
  80. +
  81. _GL_ATTRIBUTE_NODISCARD SAFE_ALLOC_INLINE int
  82. safe_alloc_check (void *ptr)
  83. {
  84. @@ -84,6 +89,8 @@ safe_alloc_check (void *ptr)
  85. #define ALLOC_N(ptr, count) \
  86. safe_alloc_check ((ptr) = calloc (count, sizeof *(ptr)))
  87. +#if GNULIB_REALLOCARRAY
  88. +
  89. /**
  90. * ALLOC_N_UNINITIALIZED:
  91. * @ptr: pointer to allocated memory
  92. @@ -112,6 +119,8 @@ safe_alloc_check (void *ptr)
  93. #define REALLOC_N(ptr, count) \
  94. safe_alloc_check ((ptr) = safe_alloc_realloc_n (ptr, count, sizeof *(ptr)))
  95. +#endif /* GNULIB_REALLOCARRAY */
  96. +
  97. /**
  98. * FREE:
  99. * @ptr: pointer holding address to be freed