bug-gnulib
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[PATCH 5/5] obstack usability


From: Alan Modra
Subject: [PATCH 5/5] obstack usability
Date: Sat, 26 Jul 2014 15:27:12 +0930

When using obstack.h/c in other projects it isn't very nice that gnulib
headers like exitfail.h and gettext.h need to be present.  Far worse
is a dependency on gnulib's version of stdlib.h for __attribute_pure__
and _Noreturn.  This only works if a project is willing to import
rather a lot of gnulib configury magic, because gnulib's stdlib.h must
be modified at configure time.

        * lib/obstack.h (__attribute_pure__): Don't use _GL_ATTRIBUTE_PURE.
        * lib/obstack.c (obstack_exit_failure): Don't include exitfail.h.
        (_): Include libintl.h when HAVE_LIBINTL_H and ENABLE_NLS.  Don't
        include gettext.h.
        (_Noreturn): Define.
---
 lib/obstack.c |   29 +++++++++++++++++++++++------
 lib/obstack.h |    6 +++++-
 2 files changed, 28 insertions(+), 7 deletions(-)

diff --git a/lib/obstack.c b/lib/obstack.c
index 1ac0e5d..4101581 100644
--- a/lib/obstack.c
+++ b/lib/obstack.c
@@ -312,17 +312,34 @@ libc_hidden_def (_obstack2_newchunk)
 #  ifdef _LIBC
 int obstack_exit_failure = EXIT_FAILURE;
 #  else
-#   include "exitfail.h"
-#   define obstack_exit_failure exit_failure
+#   ifndef EXIT_FAILURE
+#    define EXIT_FAILURE 1
+#   endif
+#   define obstack_exit_failure EXIT_FAILURE
 #  endif
 
-#  ifdef _LIBC
+#  if defined _LIBC || (HAVE_LIBINTL_H && ENABLE_NLS)
 #   include <libintl.h>
+#   ifndef _
+#    define _(msgid) gettext (msgid)
+#   endif
 #  else
-#   include "gettext.h"
+#   ifndef _
+#    define _(msgid) (msgid)
+#   endif
 #  endif
-#  ifndef _
-#   define _(msgid) gettext (msgid)
+
+#  if !(defined _Noreturn                                                    \
+        || (defined __STDC_VERSION__ && 201112 <= __STDC_VERSION__))
+#   if ((defined __GNUC__                                                    \
+        && (3 <= __GNUC__ || (__GNUC__ == 2 && 8 <= __GNUC_MINOR__)))        \
+       || (defined __SUNPRO_C && 0x5110 <= __SUNPRO_C))
+#    define _Noreturn __attribute__ ((__noreturn__))
+#   elif defined _MSC_VER && 1200 <= _MSC_VER
+#    define _Noreturn __declspec (noreturn)
+#   else
+#    define _Noreturn
+#   endif
 #  endif
 
 #  ifdef _LIBC
diff --git a/lib/obstack.h b/lib/obstack.h
index 19a8eb2..b79d4cb 100644
--- a/lib/obstack.h
+++ b/lib/obstack.h
@@ -188,7 +188,11 @@
 #include <string.h>
 
 #ifndef __attribute_pure__
-# define __attribute_pure__ _GL_ATTRIBUTE_PURE
+# if defined __GNUC_MINOR__ && __GNUC__ * 1000 + __GNUC_MINOR__ >= 2096
+#  define __attribute_pure__ __attribute__ ((__pure__))
+# else
+#  define __attribute_pure__
+# endif
 #endif
 
 #ifdef __cplusplus



reply via email to

[Prev in Thread] Current Thread [Next in Thread]