diff options
| author | Paul Eggert | 2012-07-28 16:05:32 -0700 |
|---|---|---|
| committer | Paul Eggert | 2012-07-28 16:05:32 -0700 |
| commit | e32a579975bc219bc24d403deeb1fa89187fc51e (patch) | |
| tree | 957a729b7f4eb64980359a57828f02d29e6758e7 /src | |
| parent | 01bd1b0df605d644ae31e8f1f81d926a5d8c7099 (diff) | |
| download | emacs-e32a579975bc219bc24d403deeb1fa89187fc51e.tar.gz emacs-e32a579975bc219bc24d403deeb1fa89187fc51e.zip | |
Use Gnulib stdalign and environ modules (Bug#9772, Bug#9960).
* .bzrignore: Add lib/stdalign.h.
* config.bat: Do not set NO_DECL_ALIGN; no longer needed.
Copy lib/stdalign.in.h to lib/stdalign.in-h as needed.
* configure.ac (HAVE_ATTRIBUTE_ALIGNED): Remove the code that
fiddles with this, as gnulib now does this for us.
* admin/merge-gnulib: Add environ, stdalign.
* m4/environ.m4: New file, from gnulib.
* lib/gnulib.mk, m4/gnulib-comp.m4: Regenerate.
* lib/stdalign.in.h, m4/stdalign.m4: New files, from gnulib.
* sed2v2.inp (HAVE_ATTRIBUTE_ALIGNED): Remove edit.
* sedlibmk.inp (STDALIGN_H, @GL_GENERATE_STDALIGN_H_TRUE@)
(GL_GENERATE_STDALIGN_H_FALSE): New edits.
* nt/config.nt (HAVE_ATTRIBUTE_ALIGNED): Remove.
* src/alloc.c (XMALLOC_BASE_ALIGNMENT, GC_POINTER_ALIGNMENT, pure_alloc):
Simplify by using alignof.
(pure_alloc) [! USE_LSB_TAG]: Don't over-align EMACS_INT values.
* src/lisp.h: Include <stdalign.h>.
(GCALIGNMENT): New macro and constant.
(DECL_ALIGN): Remove. All uses replaced by alignas (GCALIGNMENT).
(USE_LSB_TAG): ifdef on alignas, not on DECL_ALIGN.
(stdalign): New macro, if not already defined.
Diffstat (limited to 'src')
| -rw-r--r-- | src/ChangeLog | 12 | ||||
| -rw-r--r-- | src/alloc.c | 21 | ||||
| -rw-r--r-- | src/buffer.c | 4 | ||||
| -rw-r--r-- | src/lisp.h | 46 |
4 files changed, 36 insertions, 47 deletions
diff --git a/src/ChangeLog b/src/ChangeLog index 6457fc2209b..cc112f4b5da 100644 --- a/src/ChangeLog +++ b/src/ChangeLog | |||
| @@ -1,3 +1,15 @@ | |||
| 1 | 2012-07-28 Paul Eggert <eggert@cs.ucla.edu> | ||
| 2 | |||
| 3 | Use Gnulib stdalign module (Bug#9772, Bug#9960). | ||
| 4 | * alloc.c (XMALLOC_BASE_ALIGNMENT, GC_POINTER_ALIGNMENT, pure_alloc): | ||
| 5 | Simplify by using alignof. | ||
| 6 | (pure_alloc) [! USE_LSB_TAG]: Don't over-align EMACS_INT values. | ||
| 7 | * lisp.h: Include <stdalign.h>. | ||
| 8 | (GCALIGNMENT): New macro and constant. | ||
| 9 | (DECL_ALIGN): Remove. All uses replaced by alignas (GCALIGNMENT). | ||
| 10 | (USE_LSB_TAG): ifdef on alignas, not on DECL_ALIGN. | ||
| 11 | (stdalign): New macro, if not already defined. | ||
| 12 | |||
| 1 | 2012-07-28 Eli Zaretskii <eliz@gnu.org> | 13 | 2012-07-28 Eli Zaretskii <eliz@gnu.org> |
| 2 | 14 | ||
| 3 | Fix non-ASCII input in non-GUI frames on MS-Windows. (Bug#12055) | 15 | Fix non-ASCII input in non-GUI frames on MS-Windows. (Bug#12055) |
diff --git a/src/alloc.c b/src/alloc.c index a551dd821b8..e5f412bb4c3 100644 --- a/src/alloc.c +++ b/src/alloc.c | |||
| @@ -533,12 +533,7 @@ buffer_memory_full (ptrdiff_t nbytes) | |||
| 533 | hold a size_t value and (2) the header size is a multiple of the | 533 | hold a size_t value and (2) the header size is a multiple of the |
| 534 | alignment that Emacs needs for C types and for USE_LSB_TAG. */ | 534 | alignment that Emacs needs for C types and for USE_LSB_TAG. */ |
| 535 | #define XMALLOC_BASE_ALIGNMENT \ | 535 | #define XMALLOC_BASE_ALIGNMENT \ |
| 536 | offsetof ( \ | 536 | alignof (union { long double d; intmax_t i; void *p; }) |
| 537 | struct { \ | ||
| 538 | union { long double d; intmax_t i; void *p; } u; \ | ||
| 539 | char c; \ | ||
| 540 | }, \ | ||
| 541 | c) | ||
| 542 | 537 | ||
| 543 | #if USE_LSB_TAG | 538 | #if USE_LSB_TAG |
| 544 | # define XMALLOC_HEADER_ALIGNMENT \ | 539 | # define XMALLOC_HEADER_ALIGNMENT \ |
| @@ -4652,10 +4647,10 @@ mark_maybe_pointer (void *p) | |||
| 4652 | } | 4647 | } |
| 4653 | 4648 | ||
| 4654 | 4649 | ||
| 4655 | /* Alignment of pointer values. Use offsetof, as it sometimes returns | 4650 | /* Alignment of pointer values. Use alignof, as it sometimes returns |
| 4656 | a smaller alignment than GCC's __alignof__ and mark_memory might | 4651 | a smaller alignment than GCC's __alignof__ and mark_memory might |
| 4657 | miss objects if __alignof__ were used. */ | 4652 | miss objects if __alignof__ were used. */ |
| 4658 | #define GC_POINTER_ALIGNMENT offsetof (struct {char a; void *b;}, b) | 4653 | #define GC_POINTER_ALIGNMENT alignof (void *) |
| 4659 | 4654 | ||
| 4660 | /* Define POINTERS_MIGHT_HIDE_IN_OBJECTS to 1 if marking via C pointers does | 4655 | /* Define POINTERS_MIGHT_HIDE_IN_OBJECTS to 1 if marking via C pointers does |
| 4661 | not suffice, which is the typical case. A host where a Lisp_Object is | 4656 | not suffice, which is the typical case. A host where a Lisp_Object is |
| @@ -5103,17 +5098,11 @@ pure_alloc (size_t size, int type) | |||
| 5103 | #if USE_LSB_TAG | 5098 | #if USE_LSB_TAG |
| 5104 | size_t alignment = (1 << GCTYPEBITS); | 5099 | size_t alignment = (1 << GCTYPEBITS); |
| 5105 | #else | 5100 | #else |
| 5106 | size_t alignment = sizeof (EMACS_INT); | 5101 | size_t alignment = alignof (EMACS_INT); |
| 5107 | 5102 | ||
| 5108 | /* Give Lisp_Floats an extra alignment. */ | 5103 | /* Give Lisp_Floats an extra alignment. */ |
| 5109 | if (type == Lisp_Float) | 5104 | if (type == Lisp_Float) |
| 5110 | { | 5105 | alignment = alignof (struct Lisp_Float); |
| 5111 | #if defined __GNUC__ && __GNUC__ >= 2 | ||
| 5112 | alignment = __alignof (struct Lisp_Float); | ||
| 5113 | #else | ||
| 5114 | alignment = sizeof (struct Lisp_Float); | ||
| 5115 | #endif | ||
| 5116 | } | ||
| 5117 | #endif | 5106 | #endif |
| 5118 | 5107 | ||
| 5119 | again: | 5108 | again: |
diff --git a/src/buffer.c b/src/buffer.c index 5e45882b892..70630de53cb 100644 --- a/src/buffer.c +++ b/src/buffer.c | |||
| @@ -56,7 +56,7 @@ struct buffer *all_buffers; | |||
| 56 | Setting the default value also goes through the alist of buffers | 56 | Setting the default value also goes through the alist of buffers |
| 57 | and stores into each buffer that does not say it has a local value. */ | 57 | and stores into each buffer that does not say it has a local value. */ |
| 58 | 58 | ||
| 59 | DECL_ALIGN (struct buffer, buffer_defaults); | 59 | struct buffer alignas (GCALIGNMENT) buffer_defaults; |
| 60 | 60 | ||
| 61 | /* A Lisp_Object pointer to the above, used for staticpro */ | 61 | /* A Lisp_Object pointer to the above, used for staticpro */ |
| 62 | 62 | ||
| @@ -83,7 +83,7 @@ struct buffer buffer_local_flags; | |||
| 83 | /* This structure holds the names of symbols whose values may be | 83 | /* This structure holds the names of symbols whose values may be |
| 84 | buffer-local. It is indexed and accessed in the same way as the above. */ | 84 | buffer-local. It is indexed and accessed in the same way as the above. */ |
| 85 | 85 | ||
| 86 | DECL_ALIGN (struct buffer, buffer_local_symbols); | 86 | struct buffer alignas (GCALIGNMENT) buffer_local_symbols; |
| 87 | 87 | ||
| 88 | /* A Lisp_Object pointer to the above, used for staticpro */ | 88 | /* A Lisp_Object pointer to the above, used for staticpro */ |
| 89 | static Lisp_Object Vbuffer_local_symbols; | 89 | static Lisp_Object Vbuffer_local_symbols; |
diff --git a/src/lisp.h b/src/lisp.h index 80a9ab343c3..a45e9c2c892 100644 --- a/src/lisp.h +++ b/src/lisp.h | |||
| @@ -20,6 +20,7 @@ along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>. */ | |||
| 20 | #ifndef EMACS_LISP_H | 20 | #ifndef EMACS_LISP_H |
| 21 | #define EMACS_LISP_H | 21 | #define EMACS_LISP_H |
| 22 | 22 | ||
| 23 | #include <stdalign.h> | ||
| 23 | #include <stdarg.h> | 24 | #include <stdarg.h> |
| 24 | #include <stddef.h> | 25 | #include <stddef.h> |
| 25 | #include <inttypes.h> | 26 | #include <inttypes.h> |
| @@ -151,10 +152,6 @@ extern int suppress_checking EXTERNALLY_VISIBLE; | |||
| 151 | on the few static Lisp_Objects used: all the defsubr as well | 152 | on the few static Lisp_Objects used: all the defsubr as well |
| 152 | as the two special buffers buffer_defaults and buffer_local_symbols. */ | 153 | as the two special buffers buffer_defaults and buffer_local_symbols. */ |
| 153 | 154 | ||
| 154 | /* First, try and define DECL_ALIGN(type,var) which declares a static | ||
| 155 | variable VAR of type TYPE with the added requirement that it be | ||
| 156 | TYPEBITS-aligned. */ | ||
| 157 | |||
| 158 | enum Lisp_Bits | 155 | enum Lisp_Bits |
| 159 | { | 156 | { |
| 160 | /* Number of bits in a Lisp_Object tag. This can be used in #if, | 157 | /* Number of bits in a Lisp_Object tag. This can be used in #if, |
| @@ -163,6 +160,12 @@ enum Lisp_Bits | |||
| 163 | #define GCTYPEBITS 3 | 160 | #define GCTYPEBITS 3 |
| 164 | GCTYPEBITS, | 161 | GCTYPEBITS, |
| 165 | 162 | ||
| 163 | /* 2**GCTYPEBITS. This must also be a macro that expands to a | ||
| 164 | literal integer constant, for MSVC. */ | ||
| 165 | GCALIGNMENT = | ||
| 166 | #define GCALIGNMENT 8 | ||
| 167 | GCALIGNMENT, | ||
| 168 | |||
| 166 | /* Number of bits in a Lisp_Object value, not counting the tag. */ | 169 | /* Number of bits in a Lisp_Object value, not counting the tag. */ |
| 167 | VALBITS = BITS_PER_EMACS_INT - GCTYPEBITS, | 170 | VALBITS = BITS_PER_EMACS_INT - GCTYPEBITS, |
| 168 | 171 | ||
| @@ -173,36 +176,22 @@ enum Lisp_Bits | |||
| 173 | FIXNUM_BITS = VALBITS + 1 | 176 | FIXNUM_BITS = VALBITS + 1 |
| 174 | }; | 177 | }; |
| 175 | 178 | ||
| 179 | #if GCALIGNMENT != 1 << GCTYPEBITS | ||
| 180 | # error "GCALIGNMENT and GCTYPEBITS are inconsistent" | ||
| 181 | #endif | ||
| 182 | |||
| 176 | /* The maximum value that can be stored in a EMACS_INT, assuming all | 183 | /* The maximum value that can be stored in a EMACS_INT, assuming all |
| 177 | bits other than the type bits contribute to a nonnegative signed value. | 184 | bits other than the type bits contribute to a nonnegative signed value. |
| 178 | This can be used in #if, e.g., '#if VAL_MAX < UINTPTR_MAX' below. */ | 185 | This can be used in #if, e.g., '#if VAL_MAX < UINTPTR_MAX' below. */ |
| 179 | #define VAL_MAX (EMACS_INT_MAX >> (GCTYPEBITS - 1)) | 186 | #define VAL_MAX (EMACS_INT_MAX >> (GCTYPEBITS - 1)) |
| 180 | 187 | ||
| 181 | #ifndef NO_DECL_ALIGN | ||
| 182 | # ifndef DECL_ALIGN | ||
| 183 | # if HAVE_ATTRIBUTE_ALIGNED | ||
| 184 | # define DECL_ALIGN(type, var) \ | ||
| 185 | type __attribute__ ((__aligned__ (1 << GCTYPEBITS))) var | ||
| 186 | # elif defined(_MSC_VER) | ||
| 187 | # define ALIGN_GCTYPEBITS 8 | ||
| 188 | # if (1 << GCTYPEBITS) != ALIGN_GCTYPEBITS | ||
| 189 | # error ALIGN_GCTYPEBITS is wrong! | ||
| 190 | # endif | ||
| 191 | # define DECL_ALIGN(type, var) \ | ||
| 192 | type __declspec(align(ALIGN_GCTYPEBITS)) var | ||
| 193 | # else | ||
| 194 | /* What directives do other compilers use? */ | ||
| 195 | # endif | ||
| 196 | # endif | ||
| 197 | #endif | ||
| 198 | |||
| 199 | /* Unless otherwise specified, use USE_LSB_TAG on systems where: */ | 188 | /* Unless otherwise specified, use USE_LSB_TAG on systems where: */ |
| 200 | #ifndef USE_LSB_TAG | 189 | #ifndef USE_LSB_TAG |
| 201 | /* 1. We know malloc returns a multiple of 8. */ | 190 | /* 1. We know malloc returns a multiple of 8. */ |
| 202 | # if (defined GNU_MALLOC || defined DOUG_LEA_MALLOC || defined __GLIBC__ \ | 191 | # if (defined GNU_MALLOC || defined DOUG_LEA_MALLOC || defined __GLIBC__ \ |
| 203 | || defined DARWIN_OS || defined __sun) | 192 | || defined DARWIN_OS || defined __sun) |
| 204 | /* 2. We can specify multiple-of-8 alignment on static variables. */ | 193 | /* 2. We can specify multiple-of-8 alignment on static variables. */ |
| 205 | # ifdef DECL_ALIGN | 194 | # ifdef alignas |
| 206 | /* 3. Pointers-as-ints exceed VAL_MAX. | 195 | /* 3. Pointers-as-ints exceed VAL_MAX. |
| 207 | On hosts where pointers-as-ints do not exceed VAL_MAX, USE_LSB_TAG is: | 196 | On hosts where pointers-as-ints do not exceed VAL_MAX, USE_LSB_TAG is: |
| 208 | a. unnecessary, because the top bits of an EMACS_INT are unused, and | 197 | a. unnecessary, because the top bits of an EMACS_INT are unused, and |
| @@ -223,12 +212,11 @@ enum enum_USE_LSB_TAG { USE_LSB_TAG = 0 }; | |||
| 223 | # define USE_LSB_TAG 0 | 212 | # define USE_LSB_TAG 0 |
| 224 | #endif | 213 | #endif |
| 225 | 214 | ||
| 226 | /* If we cannot use 8-byte alignment, make DECL_ALIGN a no-op. */ | 215 | #ifndef alignas |
| 227 | #ifndef DECL_ALIGN | 216 | # define alignas(alignment) /* empty */ |
| 228 | # if USE_LSB_TAG | 217 | # if USE_LSB_TAG |
| 229 | # error "USE_LSB_TAG used without defining DECL_ALIGN" | 218 | # error "USE_LSB_TAG requires alignas" |
| 230 | # endif | 219 | # endif |
| 231 | # define DECL_ALIGN(type, var) type var | ||
| 232 | #endif | 220 | #endif |
| 233 | 221 | ||
| 234 | 222 | ||
| @@ -1882,7 +1870,7 @@ typedef struct { | |||
| 1882 | #ifdef _MSC_VER | 1870 | #ifdef _MSC_VER |
| 1883 | #define DEFUN(lname, fnname, sname, minargs, maxargs, intspec, doc) \ | 1871 | #define DEFUN(lname, fnname, sname, minargs, maxargs, intspec, doc) \ |
| 1884 | Lisp_Object fnname DEFUN_ARGS_ ## maxargs ; \ | 1872 | Lisp_Object fnname DEFUN_ARGS_ ## maxargs ; \ |
| 1885 | static DECL_ALIGN (struct Lisp_Subr, sname) = \ | 1873 | static struct Lisp_Subr alignas (GCALIGNMENT) sname = \ |
| 1886 | { (PVEC_SUBR << PSEUDOVECTOR_SIZE_BITS) \ | 1874 | { (PVEC_SUBR << PSEUDOVECTOR_SIZE_BITS) \ |
| 1887 | | (sizeof (struct Lisp_Subr) / sizeof (EMACS_INT)), \ | 1875 | | (sizeof (struct Lisp_Subr) / sizeof (EMACS_INT)), \ |
| 1888 | { (Lisp_Object (__cdecl *)(void))fnname }, \ | 1876 | { (Lisp_Object (__cdecl *)(void))fnname }, \ |
| @@ -1891,7 +1879,7 @@ typedef struct { | |||
| 1891 | #else /* not _MSC_VER */ | 1879 | #else /* not _MSC_VER */ |
| 1892 | #define DEFUN(lname, fnname, sname, minargs, maxargs, intspec, doc) \ | 1880 | #define DEFUN(lname, fnname, sname, minargs, maxargs, intspec, doc) \ |
| 1893 | Lisp_Object fnname DEFUN_ARGS_ ## maxargs ; \ | 1881 | Lisp_Object fnname DEFUN_ARGS_ ## maxargs ; \ |
| 1894 | static DECL_ALIGN (struct Lisp_Subr, sname) = \ | 1882 | static struct Lisp_Subr alignas (GCALIGNMENT) sname = \ |
| 1895 | { PVEC_SUBR << PSEUDOVECTOR_SIZE_BITS, \ | 1883 | { PVEC_SUBR << PSEUDOVECTOR_SIZE_BITS, \ |
| 1896 | { .a ## maxargs = fnname }, \ | 1884 | { .a ## maxargs = fnname }, \ |
| 1897 | minargs, maxargs, lname, intspec, 0}; \ | 1885 | minargs, maxargs, lname, intspec, 0}; \ |