Skip to content

Commit e9f40d7

Browse files
committed
Modify obstack.[hc] to avoid having to include other gnulib files
Using the standard gnulib obstack source requires importing quite a lot of other files from gnulib, and requires build changes. include/ PR gdb/17133 * obstack.h (__attribute_pure__): Expand _GL_ATTRIBUTE_PURE. libiberty/ PR gdb/17133 * obstack.c (__alignof__): Expand alignof_type from alignof.h. (obstack_exit_failure): Don't use exitfail.h. (_): Include libintl.h when HAVE_LIBINTL_H and nls enabled. Provide default. Don't include gettext.h. (_Noreturn): Define. * obstacks.texi: Adjust node references to external libc info files.
1 parent 314dee8 commit e9f40d7

5 files changed

Lines changed: 55 additions & 14 deletions

File tree

‎include/ChangeLog‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,8 @@
1+
2015-11-09 Alan Modra <amodra@gmail.com>
2+
3+
PR gdb/17133
4+
* obstack.h (__attribute_pure__): Expand _GL_ATTRIBUTE_PURE.
5+
16
2015-11-09 Alan Modra <amodra@gmail.com>
27

38
PR gdb/17133

‎include/obstack.h‎

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -142,7 +142,11 @@
142142
P, A)
143143

144144
#ifndef __attribute_pure__
145-
# define __attribute_pure__ _GL_ATTRIBUTE_PURE
145+
# if defined __GNUC_MINOR__ && __GNUC__ * 1000 + __GNUC_MINOR__ >= 2096
146+
# define __attribute_pure__ __attribute__ ((__pure__))
147+
# else
148+
# define __attribute_pure__
149+
# endif
146150
#endif
147151

148152
#ifdef __cplusplus

‎libiberty/ChangeLog‎

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,13 @@
1+
2015-11-09 Alan Modra <amodra@gmail.com>
2+
3+
PR gdb/17133
4+
* obstack.c (__alignof__): Expand alignof_type from alignof.h.
5+
(obstack_exit_failure): Don't use exitfail.h.
6+
(_): Include libintl.h when HAVE_LIBINTL_H and nls enabled.
7+
Provide default. Don't include gettext.h.
8+
(_Noreturn): Define.
9+
* obstacks.texi: Adjust node references to external libc info files.
10+
111
2015-11-09 Alan Modra <amodra@gmail.com>
212

313
PR gdb/17133

‎libiberty/obstack.c‎

Lines changed: 31 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -51,9 +51,14 @@
5151
/* If GCC, or if an oddball (testing?) host that #defines __alignof__,
5252
use the already-supplied __alignof__. Otherwise, this must be Gnulib
5353
(as glibc assumes GCC); defer to Gnulib's alignof_type. */
54-
# if !defined __GNUC__ && !defined __alignof__
55-
# include <alignof.h>
56-
# define __alignof__(type) alignof_type (type)
54+
# if !defined __GNUC__ && !defined __IBM__ALIGNOF__ && !defined __alignof__
55+
# if defined __cplusplus
56+
template <class type> struct alignof_helper { char __slot1; type __slot2; };
57+
# define __alignof__(type) offsetof (alignof_helper<type>, __slot2)
58+
# else
59+
# define __alignof__(type) \
60+
offsetof (struct { char __slot1; type __slot2; }, __slot2)
61+
# endif
5762
# endif
5863
# include <stdlib.h>
5964
# include <stdint.h>
@@ -309,17 +314,34 @@ _obstack_memory_used (struct obstack *h)
309314
# ifdef _LIBC
310315
int obstack_exit_failure = EXIT_FAILURE;
311316
# else
312-
# include "exitfail.h"
313-
# define obstack_exit_failure exit_failure
317+
# ifndef EXIT_FAILURE
318+
# define EXIT_FAILURE 1
319+
# endif
320+
# define obstack_exit_failure EXIT_FAILURE
314321
# endif
315322

316-
# ifdef _LIBC
323+
# if defined _LIBC || (HAVE_LIBINTL_H && ENABLE_NLS)
317324
# include <libintl.h>
325+
# ifndef _
326+
# define _(msgid) gettext (msgid)
327+
# endif
318328
# else
319-
# include "gettext.h"
329+
# ifndef _
330+
# define _(msgid) (msgid)
331+
# endif
320332
# endif
321-
# ifndef _
322-
# define _(msgid) gettext (msgid)
333+
334+
# if !(defined _Noreturn \
335+
|| (defined __STDC_VERSION__ && __STDC_VERSION__ >= 201112))
336+
# if ((defined __GNUC__ \
337+
&& (__GNUC__ >= 3 || (__GNUC__ == 2 && __GNUC_MINOR__ >= 8))) \
338+
|| (defined __SUNPRO_C && __SUNPRO_C >= 0x5110))
339+
# define _Noreturn __attribute__ ((__noreturn__))
340+
# elif defined _MSC_VER && _MSC_VER >= 1200
341+
# define _Noreturn __declspec (noreturn)
342+
# else
343+
# define _Noreturn
344+
# endif
323345
# endif
324346

325347
# ifdef _LIBC

‎libiberty/obstacks.texi‎

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@ them are freed. These macros should appear before any use of obstacks
9393
in the source file.
9494

9595
Usually these are defined to use @code{malloc} via the intermediary
96-
@code{xmalloc} (@pxref{Unconstrained Allocation}). This is done with
96+
@code{xmalloc} (@pxref{Unconstrained Allocation, , , libc, The GNU C Library Reference Manual}). This is done with
9797
the following pair of macro definitions:
9898

9999
@smallexample
@@ -172,8 +172,8 @@ The value of this variable is a pointer to a function that
172172
@code{obstack} uses when @code{obstack_chunk_alloc} fails to allocate
173173
memory. The default action is to print a message and abort.
174174
You should supply a function that either calls @code{exit}
175-
(@pxref{Program Termination}) or @code{longjmp} (@pxref{Non-Local
176-
Exits}) and doesn't return.
175+
(@pxref{Program Termination, , , libc, The GNU C Library Reference Manual}) or @code{longjmp} (@pxref{Non-Local
176+
Exits, , , libc, The GNU C Library Reference Manual}) and doesn't return.
177177

178178
@smallexample
179179
void my_obstack_alloc_failed (void)
@@ -253,7 +253,7 @@ obstack_savestring (char *addr, size_t size)
253253

254254
@noindent
255255
Contrast this with the previous example of @code{savestring} using
256-
@code{malloc} (@pxref{Basic Allocation}).
256+
@code{malloc} (@pxref{Basic Allocation, , , libc, The GNU C Library Reference Manual}).
257257

258258
@node Freeing Obstack Objects
259259
@subsubsection Freeing Objects in an Obstack

0 commit comments

Comments
 (0)