[05/18] posix: Rewrite to use struct scratch_buffer instead of extend_alloca
Commit Message
Thanks, I merged that patch into Gnulib; see:
http://lists.gnu.org/archive/html/bug-gnulib/2017-09/msg00002.html
This means Gnulib starts sharing scratch_buffer.h etc. with glibc, which
entails some minor and safe changes to those files on the glibc side.
Plus, glibc glob.c can be simplified slightly now. Please see the
attached patch, which I hope can be folded into the next iteration of
this glibc patchset.
From 05cc71685fb0e177233655c4d499ad223ffe9a6f Mon Sep 17 00:00:00 2001
From: Paul Eggert <eggert@cs.ucla.edu>
Date: Fri, 1 Sep 2017 16:37:15 -0700
Subject: [PATCH] Merge glob-related changes from Gnulib
* include/scratch_buffer.h (struct scratch_buffer):
Use portable method to align buffer, instead of relying
on GCC's __attribute__ ((aligned (...))), so that this
can be compiled with non-GCC compilers when used as
part of Gnulib.
* malloc/scratch_buffer_grow.c:
* malloc/scratch_buffer_grow_preserve.c:
* malloc/scratch_buffer_set_array_size.c:
Include <libc-config.h> first thing, if !_LIBC.
Remove stray top-level ";" that non-GCC compilers reject.
* misc/sys/cdefs.h: Do not include <bits/wordsize.h> and
<bits/long-double.h> if __WORDSIZE is already defined, so that
Gnulib-using code does not include these nonexistent files.
* posix/glob.c: Minor simplifications due to Gnulib changes:
do not include <config.h>, and do not define __set_errno.
does that via another method for glob.c.
---
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 +++++-
misc/sys/cdefs.h | 8 ++++++--
posix/glob.c | 8 --------
6 files changed, 22 insertions(+), 15 deletions(-)
@@ -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)
@@ -415,8 +415,12 @@
[!!sizeof (struct { int __error_if_negative: (expr) ? 2 : -1; })]
#endif
-#include <bits/wordsize.h>
-#include <bits/long-double.h>
+/* The #ifndef lets Gnulib avoid including these on non-glibc
+ platforms, where the includes typically do not exist. */
+#ifndef __WORDSIZE
+# include <bits/wordsize.h>
+# include <bits/long-double.h>
+#endif
#if defined __LONG_DOUBLE_MATH_OPTIONAL && defined __NO_LONG_DOUBLE_MATH
# define __LDBL_COMPAT 1
@@ -15,10 +15,6 @@
License along with the GNU C Library; if not, see
<http://www.gnu.org/licenses/>. */
-#ifndef _LIBC
-# include <config.h>
-#endif
-
#include <glob.h>
#include <errno.h>
@@ -39,10 +35,6 @@
#endif
#include <errno.h>
-#ifndef __set_errno
-# define __set_errno(val) errno = (val)
-#endif
-
#include <dirent.h>
#include <stdlib.h>
#include <string.h>
--
2.13.5