From patchwork Wed Oct 29 03:33:00 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alan Modra X-Patchwork-Id: 3457 Received: (qmail 2865 invoked by alias); 29 Oct 2014 03:33:12 -0000 Mailing-List: contact libc-alpha-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Unsubscribe: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: libc-alpha-owner@sourceware.org Delivered-To: mailing list libc-alpha@sourceware.org Received: (qmail 2794 invoked by uid 89); 29 Oct 2014 03:33:11 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-2.4 required=5.0 tests=AWL, BAYES_00, FREEMAIL_FROM, RCVD_IN_DNSWL_LOW, SPF_PASS autolearn=ham version=3.3.2 X-HELO: mail-pa0-f47.google.com X-Received: by 10.66.160.193 with SMTP id xm1mr7536574pab.115.1414553587901; Tue, 28 Oct 2014 20:33:07 -0700 (PDT) Date: Wed, 29 Oct 2014 14:03:00 +1030 From: Alan Modra To: libc-alpha@sourceware.org, bug-gnulib@gnu.org Subject: [PATCH 5/5] 64-bit obstack support, part 3 Message-ID: <20141029033300.GN4267@bubble.grove.modra.org> MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: User-Agent: Mutt/1.5.23 (2014-03-12) This finally enables full 64-bit obstack support. The glibc shared library specific code is removed from obstack.c too, and the error handling code conditionally compiled under control of another macro, _OBSTACK_NO_ERROR_HANDLER. * lib/obstack.h: Include string.h earlier. (_OBSTACK_INTERFACE_VERSION): Define. (_OBSTACK_SIZE_T, _CHUNK_SIZE_T): Define as size_t for version 2. * lib/obstack.c: Don't include shlib-compat.h. (OBSTACK_INTERFACE_VERSION): Delete. (_OBSTACK_ELIDE_CODE): Rename from ELIDE_CODE. Define when version 1 glibc code is compatible with version 2. Don't include stdio.h for __GNU_LIBRARY. (obstack_exit_failure, print_and_abort, obstack_alloc_failed_handler): Omit when _OBSTACK_NO_ERROR_HANDLER defined. Include stdio.h here. (_obstack_compat, _obstack, _obstack_newchunk, obstack_free): Delete glibc shared library specific source. --- lib/obstack.c | 83 ++++++++++++++++++++++++----------------------------------- lib/obstack.h | 21 +++++++++++---- 2 files changed, 49 insertions(+), 55 deletions(-) diff --git a/lib/obstack.c b/lib/obstack.c index eafb376..183bd0d 100644 --- a/lib/obstack.c +++ b/lib/obstack.c @@ -19,16 +19,14 @@ #ifdef _LIBC # include -# include #else # include # include "obstack.h" #endif -/* NOTE BEFORE MODIFYING THIS FILE: This version number must be - incremented whenever callers compiled using an old obstack.h can no - longer properly call the functions in this obstack.c. */ -#define OBSTACK_INTERFACE_VERSION 1 +/* NOTE BEFORE MODIFYING THIS FILE: _OBSTACK_INTERFACE_VERSION in + obstack.h must be incremented whenever callers compiled using an old + obstack.h can no longer properly call the functions in this file. */ /* Comment out all this code if we are using the GNU C Library, and are not actually compiling the library itself, and the installed library @@ -38,18 +36,18 @@ (especially if it is a shared library). Rather than having every GNU program understand 'configure --with-gnu-libc' and omit the object files, it is simpler to just do this in the source for each such file. */ - -#include /* Random thing to get __GNU_LIBRARY__. */ #if !defined _LIBC && defined __GNU_LIBRARY__ && __GNU_LIBRARY__ > 1 # include -# if _GNU_OBSTACK_INTERFACE_VERSION == OBSTACK_INTERFACE_VERSION -# define ELIDE_CODE +# if (_GNU_OBSTACK_INTERFACE_VERSION == _OBSTACK_INTERFACE_VERSION \ + || (_GNU_OBSTACK_INTERFACE_VERSION == 1 \ + && _OBSTACK_INTERFACE_VERSION == 2 \ + && defined SIZEOF_INT && defined SIZEOF_SIZE_T \ + && SIZEOF_INT == SIZEOF_SIZE_T)) +# define _OBSTACK_ELIDE_CODE # endif #endif -#ifndef ELIDE_CODE - - +#ifndef _OBSTACK_ELIDE_CODE # include # include @@ -75,16 +73,6 @@ enum }; -# ifdef _LIBC -# if SHLIB_COMPAT (libc, GLIBC_2_0, GLIBC_2_3_4) -/* A looong time ago (before 1994, anyway; we're not sure) this global variable - was used by non-GNU-C macros to avoid multiple evaluation. The GNU C - library still exports it because somebody might use it. */ -struct obstack *_obstack_compat = 0; -compat_symbol (libc, _obstack_compat, _obstack, GLIBC_2_0); -# endif -# endif - /* Define a macro that either calls functions with the traditional malloc/free calling interface, or calls functions with the mmalloc/mfree interface (that adds an extra first argument), based on the state of use_extra_arg. @@ -238,9 +226,6 @@ _obstack_newchunk (struct obstack *h, _OBSTACK_SIZE_T length) /* The new chunk certainly contains no empty object yet. */ h->maybe_empty_object = 0; } -# ifdef _LIBC -libc_hidden_def (_obstack_newchunk) -# endif /* Return nonzero if object OBJ has been allocated from obstack H. This is here for debugging. @@ -300,11 +285,6 @@ _obstack_free (struct obstack *h, void *obj) /* obj is not in any of the chunks! */ abort (); } -# ifdef _LIBC -/* Older versions of libc defined both _obstack_free and obstack_free. */ -# undef obstack_free -strong_alias (_obstack_free, obstack_free) -# endif _OBSTACK_SIZE_T _obstack_memory_used (struct obstack *h) @@ -319,28 +299,30 @@ _obstack_memory_used (struct obstack *h) return nbytes; } +# ifndef _OBSTACK_NO_ERROR_HANDLER /* Define the error handler. */ +# include /* Exit value used when 'print_and_abort' is used. */ -# ifdef _LIBC +# ifdef _LIBC int obstack_exit_failure = EXIT_FAILURE; -# else -# include "exitfail.h" -# define obstack_exit_failure exit_failure -# endif +# else +# include "exitfail.h" +# define obstack_exit_failure exit_failure +# endif -# ifdef _LIBC -# include -# else -# include "gettext.h" -# endif -# ifndef _ -# define _(msgid) gettext (msgid) -# endif +# ifdef _LIBC +# include +# else +# include "gettext.h" +# endif +# ifndef _ +# define _(msgid) gettext (msgid) +# endif -# ifdef _LIBC -# include -# endif +# ifdef _LIBC +# include +# endif static _Noreturn void print_and_abort (void) @@ -350,11 +332,11 @@ print_and_abort (void) happen because the "memory exhausted" message appears in other places like this and the translation should be reused instead of creating a very similar string which requires a separate translation. */ -# ifdef _LIBC +# ifdef _LIBC (void) __fxprintf (NULL, "%s\n", _("memory exhausted")); -# else +# else fprintf (stderr, "%s\n", _("memory exhausted")); -# endif +# endif exit (obstack_exit_failure); } @@ -365,4 +347,5 @@ print_and_abort (void) variable by default points to the internal function 'print_and_abort'. */ void (*obstack_alloc_failed_handler) (void) = print_and_abort; -#endif /* !ELIDE_CODE */ +# endif /* !_OBSTACK_NO_ERROR_HANDLER */ +#endif /* !_OBSTACK_ELIDE_CODE */ diff --git a/lib/obstack.h b/lib/obstack.h index b30cc3b..9b9f965 100644 --- a/lib/obstack.h +++ b/lib/obstack.h @@ -104,10 +104,23 @@ #ifndef _OBSTACK_H #define _OBSTACK_H 1 -#include +#ifndef _OBSTACK_INTERFACE_VERSION +# define _OBSTACK_INTERFACE_VERSION 2 +#endif -#define _OBSTACK_SIZE_T unsigned int -#define _CHUNK_SIZE_T unsigned long +#include /* For size_t and ptrdiff_t. */ +#include /* For __GNU_LIBRARY__, and memcpy. */ + +#if _OBSTACK_INTERFACE_VERSION == 1 +/* For binary compatibility with obstack version 1, which used "int" + and "long" for these two types. */ +# define _OBSTACK_SIZE_T unsigned int +# define _CHUNK_SIZE_T unsigned long +#else +/* Version 2 with sane types, especially for 64-bit hosts. */ +# define _OBSTACK_SIZE_T size_t +# define _CHUNK_SIZE_T size_t +#endif /* If B is the base of an object addressed by P, return the result of aligning P to the next multiple of A + 1. B and P must be of type @@ -126,8 +139,6 @@ __BPTR_ALIGN (sizeof (ptrdiff_t) < sizeof (void *) ? (B) : (char *) 0, \ P, A) -#include - #ifndef __attribute_pure__ # define __attribute_pure__ _GL_ATTRIBUTE_PURE #endif