[4/9] Sync scratch_buffer with gnulib
Commit Message
This patch syncs the scratch_buffer grom gnulib commit 3866ef6 with
GLIBC code.
Checked on x86_64-linux-gnu and on a build using build-many-glibcs.py
for all major architectures.
* include/scratch_buffer.h (scratch_buffer): Use a C99 align method
instead of GCC extension.
* malloc/scratch_buffer_grow.c [!_LIBC]: Include libc-config.h.
* malloc/scratch_buffer_grow_preserve.c [!_LIBC]: Likewise.
* malloc/scratch_buffer_set_array_size.c [!_LIBC]: Likewise.
---
ChangeLog | 6 ++++++
include/scratch_buffer.h | 3 +--
malloc/scratch_buffer_grow.c | 6 +++++-
malloc/scratch_buffer_grow_preserve.c | 6 +++++-
malloc/scratch_buffer_set_array_size.c | 6 +++++-
5 files changed, 22 insertions(+), 5 deletions(-)
Comments
On 09/05/2017 10:25 PM, Adhemerval Zanella wrote:
> - char __space[1024]
> - __attribute__ ((aligned (__alignof__ (max_align_t))));
> + max_align_t __space[(1023 + sizeof (max_align_t)) / sizeof (max_align_t)];
This change needs a declaration from the GCC folks (probably from
Richard Biener) that it does not break aliasing analysis. The old code
uses a GCC extension (writing to a char array changes its dynamic type);
it is not valid C. I don't know if the GCC extension also applies if
the storage site is declared with a non-char type.
Thanks,
Florian
@@ -66,8 +66,7 @@
struct scratch_buffer {
void *data; /* Pointer to the beginning of the scratch area. */
size_t length; /* Allocated space at the data pointer, in bytes. */
- char __space[1024]
- __attribute__ ((aligned (__alignof__ (max_align_t))));
+ max_align_t __space[(1023 + sizeof (max_align_t)) / sizeof (max_align_t)];
};
/* Initializes *BUFFER so that BUFFER->data points to BUFFER->__space
@@ -16,6 +16,10 @@
License along with the GNU C Library; if not, see
<http://www.gnu.org/licenses/>. */
+#ifndef _LIBC
+# include <libc-config.h>
+#endif
+
#include <scratch_buffer.h>
#include <errno.h>
@@ -49,4 +53,4 @@ __libc_scratch_buffer_grow (struct scratch_buffer *buffer)
buffer->length = new_length;
return true;
}
-libc_hidden_def (__libc_scratch_buffer_grow);
+libc_hidden_def (__libc_scratch_buffer_grow)
@@ -16,6 +16,10 @@
License along with the GNU C Library; if not, see
<http://www.gnu.org/licenses/>. */
+#ifndef _LIBC
+# include <libc-config.h>
+#endif
+
#include <scratch_buffer.h>
#include <errno.h>
#include <string.h>
@@ -60,4 +64,4 @@ __libc_scratch_buffer_grow_preserve (struct scratch_buffer *buffer)
buffer->length = new_length;
return true;
}
-libc_hidden_def (__libc_scratch_buffer_grow_preserve);
+libc_hidden_def (__libc_scratch_buffer_grow_preserve)
@@ -16,6 +16,10 @@
License along with the GNU C Library; if not, see
<http://www.gnu.org/licenses/>. */
+#ifndef _LIBC
+# include <libc-config.h>
+#endif
+
#include <scratch_buffer.h>
#include <errno.h>
#include <limits.h>
@@ -57,4 +61,4 @@ __libc_scratch_buffer_set_array_size (struct scratch_buffer *buffer,
buffer->length = new_length;
return true;
}
-libc_hidden_def (__libc_scratch_buffer_set_array_size);
+libc_hidden_def (__libc_scratch_buffer_set_array_size)