This is the mail archive of the libc-alpha@sourceware.org mailing list for the glibc project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: [PATCH 2/2] Use C11 _Alignas on scratch_buffer internal buffer


On 09/18/2017 04:42 PM, Adhemerval Zanella wrote:
Checked on x86_64-linux-gnu.

	* include/scratch_buffer.h (scratch_buffer): Use C11 _Alignas on
	__space field definition if compiler supports it.
---
  ChangeLog                | 3 +++
  include/scratch_buffer.h | 5 +++++
  2 files changed, 8 insertions(+)

diff --git a/include/scratch_buffer.h b/include/scratch_buffer.h
index bb04662..2e0c8b5 100644
--- a/include/scratch_buffer.h
+++ b/include/scratch_buffer.h
@@ -60,13 +60,18 @@
  #include <stdbool.h>
  #include <stddef.h>
  #include <stdlib.h>
+#include <stdalign.h>
/* Scratch buffer. Must be initialized with scratch_buffer_init
     before its use.  */
  struct scratch_buffer {
    void *data;    /* Pointer to the beginning of the scratch area.  */
    size_t length; /* Allocated space at the data pointer, in bytes.  */
+#if __alignas_is_defined
+  _Alignas (max_align_t) char __space[1024];
+#else
    max_align_t __space[(1023 + sizeof (max_align_t)) / sizeof (max_align_t)];
+#endif

Okay, I think.

(Richard has spoken: The code with max_align_t is okay as well as far as GCC is concerned. But I think it's useful to keep the initial buffer size in sync on all architectures to reduce variance, so please push this change.)

Thanks,
Florian.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]