[5/5] obstack usability

Message ID 1406354233-7664-6-git-send-email-amodra@gmail.com
State Rejected
Headers

Commit Message

Alan Modra July 26, 2014, 5:57 a.m. UTC
  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(-)
  

Comments

Andreas Schwab July 26, 2014, 7:20 a.m. UTC | #1
Alan Modra <amodra@gmail.com> writes:

> +#   elif defined _MSC_VER && 1200 <= _MSC_VER

Please write that as "_MSC_VER >= 1200".

Andreas.
  
Alan Modra July 26, 2014, 11:21 a.m. UTC | #2
On Sat, Jul 26, 2014 at 09:20:36AM +0200, Andreas Schwab wrote:
> Alan Modra <amodra@gmail.com> writes:
> 
> > +#   elif defined _MSC_VER && 1200 <= _MSC_VER
> 
> Please write that as "_MSC_VER >= 1200".

Thanks for looking over the patch.  This line was taken out of
gnulib/m4/gnulib-common.m4..

I'm happy to fix this oddity and others like it, the tabs in
obstack.[ch] and formatting errors in a few places.
  
Paul Eggert July 26, 2014, 11:48 a.m. UTC | #3
On 07/26/2014 01:57 AM, Alan Modra wrote:
> 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

Sure, but the downside of the proposed change is that it'd break 
programs like 'grep' that require the exitfail.h etc. semantics.

What projects are you thinking about?  That is, what current non-glibc 
projects have copies of obstack.h and obstack.c in their source code, 
but not exitfail.h etc.?
  
Paul Eggert July 26, 2014, 11:49 a.m. UTC | #4
On 07/26/2014 07:21 AM, Alan Modra wrote:
>>> > >+#   elif defined _MSC_VER && 1200 <= _MSC_VER
>> >
>> >Please write that as "_MSC_VER >= 1200".
> Thanks for looking over the patch.  This line was taken out of
> gnulib/m4/gnulib-common.m4..
>
> I'm happy to fix this oddity and others like it,
I'd rather leave this alone.  This is a long-running disagreement about 
a minor style issue, and there's no need to impose the other style here.
  
Andreas Schwab July 26, 2014, 12:17 p.m. UTC | #5
Paul Eggert <eggert@cs.ucla.edu> writes:

> On 07/26/2014 07:21 AM, Alan Modra wrote:
>>>> > >+#   elif defined _MSC_VER && 1200 <= _MSC_VER
>>> >
>>> >Please write that as "_MSC_VER >= 1200".
>> Thanks for looking over the patch.  This line was taken out of
>> gnulib/m4/gnulib-common.m4..
>>
>> I'm happy to fix this oddity and others like it,
> I'd rather leave this alone.  This is a long-running disagreement about a
> minor style issue, and there's no need to impose the other style here.

This style is not suitable for high quality software.

Andreas.
  
Alan Modra July 26, 2014, 12:30 p.m. UTC | #6
On Sat, Jul 26, 2014 at 07:48:21AM -0400, Paul Eggert wrote:
> On 07/26/2014 01:57 AM, Alan Modra wrote:
> >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
> 
> Sure, but the downside of the proposed change is that it'd break
> programs like 'grep' that require the exitfail.h etc. semantics.

Hmm, OK.

> What projects are you thinking about?  That is, what current
> non-glibc projects have copies of obstack.h and obstack.c in their
> source code, but not exitfail.h etc.?

binutils, gdb, and gcc via libiberty.  I guess we can live with a
patched obstack.[ch].
  

Patch

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