Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(365)

Unified Diff: gdb/gnulib/import/alloca.c

Issue 11969036: Merge GDB 7.5.1 (Closed) Base URL: http://git.chromium.org/native_client/nacl-gdb.git@master
Patch Set: Created 7 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « gdb/gnulib/import/Makefile.in ('k') | gdb/gnulib/import/alloca.in.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: gdb/gnulib/import/alloca.c
diff --git a/libiberty/alloca.c b/gdb/gnulib/import/alloca.c
similarity index 54%
copy from libiberty/alloca.c
copy to gdb/gnulib/import/alloca.c
index 9b2e9cb12b63b494b2de76ba74ec9a04629e8202..ee0f01886826ad9dcba250aad66fe7bc25c06213 100644
--- a/libiberty/alloca.c
+++ b/gdb/gnulib/import/alloca.c
@@ -21,65 +21,56 @@
allocating any. It is a good idea to use alloca(0) in
your main control loop, etc. to force garbage collection. */
-/*
-
-@deftypefn Replacement void* alloca (size_t @var{size})
-
-This function allocates memory which will be automatically reclaimed
-after the procedure exits. The @libib{} implementation does not free
-the memory immediately but will do so eventually during subsequent
-calls to this function. Memory is allocated using @code{xmalloc} under
-normal circumstances.
-
-The header file @file{alloca-conf.h} can be used in conjunction with the
-GNU Autoconf test @code{AC_FUNC_ALLOCA} to test for and properly make
-available this function. The @code{AC_FUNC_ALLOCA} test requires that
-client code use a block of preprocessor code to be safe (see the Autoconf
-manual for more); this header incorporates that logic and more, including
-the possibility of a GCC built-in function.
-
-@end deftypefn
-
-*/
-
-#ifdef HAVE_CONFIG_H
#include <config.h>
-#endif
-#include <libiberty.h>
+#include <alloca.h>
-#ifdef HAVE_STRING_H
#include <string.h>
-#endif
-#ifdef HAVE_STDLIB_H
#include <stdlib.h>
+
+#ifdef emacs
+# include "lisp.h"
+# include "blockinput.h"
+# ifdef EMACS_FREE
+# undef free
+# define free EMACS_FREE
+# endif
+#else
+# define memory_full() abort ()
#endif
-/* These variables are used by the ASTRDUP implementation that relies
- on C_alloca. */
-#ifdef __cplusplus
-extern "C" {
-#endif /* __cplusplus */
-const char *libiberty_optr;
-char *libiberty_nptr;
-unsigned long libiberty_len;
-#ifdef __cplusplus
-}
-#endif /* __cplusplus */
+/* If compiling with GCC 2, this file's not needed. */
+#if !defined (__GNUC__) || __GNUC__ < 2
+
+/* If someone has defined alloca as a macro,
+ there must be some other way alloca is supposed to work. */
+# ifndef alloca
+
+# ifdef emacs
+# ifdef static
+/* actually, only want this if static is defined as ""
+ -- this is for usg, in which emacs must undefine static
+ in order to make unexec workable
+ */
+# ifndef STACK_DIRECTION
+you
+lose
+-- must know STACK_DIRECTION at compile-time
+/* Using #error here is not wise since this file should work for
+ old and obscure compilers. */
+# endif /* STACK_DIRECTION undefined */
+# endif /* static */
+# endif /* emacs */
/* If your stack is a linked list of frames, you have to
provide an "address metric" ADDRESS_FUNCTION macro. */
-#if defined (CRAY) && defined (CRAY_STACKSEG_END)
-static long i00afunc ();
-#define ADDRESS_FUNCTION(arg) (char *) i00afunc (&(arg))
-#else
-#define ADDRESS_FUNCTION(arg) &(arg)
-#endif
-
-#ifndef NULL
-#define NULL 0
-#endif
+# if defined (CRAY) && defined (CRAY_STACKSEG_END)
+long i00afunc ();
+# define ADDRESS_FUNCTION(arg) (char *) i00afunc (&(arg))
+# else
+# define ADDRESS_FUNCTION(arg) &(arg)
+# endif
/* Define STACK_DIRECTION if you know the direction of stack
growth for your system; otherwise it will be automatically
@@ -89,42 +80,31 @@ static long i00afunc ();
STACK_DIRECTION < 0 => grows toward lower addresses
STACK_DIRECTION = 0 => direction of growth unknown */
-#ifndef STACK_DIRECTION
-#define STACK_DIRECTION 0 /* Direction unknown. */
-#endif
+# ifndef STACK_DIRECTION
+# define STACK_DIRECTION 0 /* Direction unknown. */
+# endif
-#if STACK_DIRECTION != 0
+# if STACK_DIRECTION != 0
-#define STACK_DIR STACK_DIRECTION /* Known at compile-time. */
+# define STACK_DIR STACK_DIRECTION /* Known at compile-time. */
-#else /* STACK_DIRECTION == 0; need run-time code. */
+# else /* STACK_DIRECTION == 0; need run-time code. */
-static int stack_dir; /* 1 or -1 once known. */
-#define STACK_DIR stack_dir
+static int stack_dir; /* 1 or -1 once known. */
+# define STACK_DIR stack_dir
-static void
-find_stack_direction (void)
+static int
+find_stack_direction (int *addr, int depth)
{
- static char *addr = NULL; /* Address of first `dummy', once known. */
- auto char dummy; /* To get stack address. */
-
- if (addr == NULL)
- { /* Initial entry. */
- addr = ADDRESS_FUNCTION (dummy);
-
- find_stack_direction (); /* Recurse once. */
- }
- else
- {
- /* Second entry. */
- if (ADDRESS_FUNCTION (dummy) > addr)
- stack_dir = 1; /* Stack grew upward. */
- else
- stack_dir = -1; /* Stack grew downward. */
- }
+ int dir, dummy = 0;
+ if (! addr)
+ addr = &dummy;
+ *addr = addr < &dummy ? 1 : addr == &dummy ? 0 : -1;
+ dir = depth ? find_stack_direction (addr, depth - 1) : 0;
+ return dir + dummy;
}
-#endif /* STACK_DIRECTION == 0 */
+# endif /* STACK_DIRECTION == 0 */
/* An "alloca header" is used to:
(a) chain together all alloca'ed blocks;
@@ -133,21 +113,21 @@ find_stack_direction (void)
It is very important that sizeof(header) agree with malloc
alignment chunk size. The following default should work okay. */
-#ifndef ALIGN_SIZE
-#define ALIGN_SIZE sizeof(double)
-#endif
+# ifndef ALIGN_SIZE
+# define ALIGN_SIZE sizeof(double)
+# endif
typedef union hdr
{
- char align[ALIGN_SIZE]; /* To force sizeof(header). */
+ char align[ALIGN_SIZE]; /* To force sizeof(header). */
struct
{
- union hdr *next; /* For chaining headers. */
- char *deep; /* For stack depth measure. */
+ union hdr *next; /* For chaining headers. */
+ char *deep; /* For stack depth measure. */
} h;
} header;
-static header *last_alloca_header = NULL; /* -> last alloca header. */
+static header *last_alloca_header = NULL; /* -> last alloca header. */
/* Return a pointer to at least SIZE bytes of storage,
which will be automatically reclaimed upon exit from
@@ -156,80 +136,92 @@ static header *last_alloca_header = NULL; /* -> last alloca header. */
caller, but that method cannot be made to work for some
implementations of C, for example under Gould's UTX/32. */
-/* @undocumented C_alloca */
-
-PTR
-C_alloca (size_t size)
+void *
+alloca (size_t size)
{
- auto char probe; /* Probes stack depth: */
+ auto char probe; /* Probes stack depth: */
register char *depth = ADDRESS_FUNCTION (probe);
-#if STACK_DIRECTION == 0
- if (STACK_DIR == 0) /* Unknown growth direction. */
- find_stack_direction ();
-#endif
+# if STACK_DIRECTION == 0
+ if (STACK_DIR == 0) /* Unknown growth direction. */
+ STACK_DIR = find_stack_direction (NULL, (size & 1) + 20);
+# endif
/* Reclaim garbage, defined as all alloca'd storage that
was allocated from deeper in the stack than currently. */
{
- register header *hp; /* Traverses linked list. */
+ register header *hp; /* Traverses linked list. */
+
+# ifdef emacs
+ BLOCK_INPUT;
+# endif
for (hp = last_alloca_header; hp != NULL;)
if ((STACK_DIR > 0 && hp->h.deep > depth)
- || (STACK_DIR < 0 && hp->h.deep < depth))
- {
- register header *np = hp->h.next;
+ || (STACK_DIR < 0 && hp->h.deep < depth))
+ {
+ register header *np = hp->h.next;
- free ((PTR) hp); /* Collect garbage. */
+ free (hp); /* Collect garbage. */
- hp = np; /* -> next header. */
- }
+ hp = np; /* -> next header. */
+ }
else
- break; /* Rest are not deeper. */
+ break; /* Rest are not deeper. */
+
+ last_alloca_header = hp; /* -> last valid storage. */
- last_alloca_header = hp; /* -> last valid storage. */
+# ifdef emacs
+ UNBLOCK_INPUT;
+# endif
}
if (size == 0)
- return NULL; /* No allocation required. */
+ return NULL; /* No allocation required. */
/* Allocate combined header + user data storage. */
{
- register void *new_storage = XNEWVEC (char, sizeof (header) + size);
/* Address of header. */
+ register header *new;
+
+ size_t combined_size = sizeof (header) + size;
+ if (combined_size < sizeof (header))
+ memory_full ();
+
+ new = malloc (combined_size);
- if (new_storage == 0)
- abort();
+ if (! new)
+ memory_full ();
- ((header *) new_storage)->h.next = last_alloca_header;
- ((header *) new_storage)->h.deep = depth;
+ new->h.next = last_alloca_header;
+ new->h.deep = depth;
- last_alloca_header = (header *) new_storage;
+ last_alloca_header = new;
/* User storage begins just after header. */
- return (PTR) ((char *) new_storage + sizeof (header));
+ return (void *) (new + 1);
}
}
-#if defined (CRAY) && defined (CRAY_STACKSEG_END)
+# if defined (CRAY) && defined (CRAY_STACKSEG_END)
-#ifdef DEBUG_I00AFUNC
-#include <stdio.h>
-#endif
+# ifdef DEBUG_I00AFUNC
+# include <stdio.h>
+# endif
-#ifndef CRAY_STACK
-#define CRAY_STACK
-#ifndef CRAY2
+# ifndef CRAY_STACK
+# define CRAY_STACK
+# ifndef CRAY2
/* Stack structures for CRAY-1, CRAY X-MP, and CRAY Y-MP */
struct stack_control_header
{
- long shgrow:32; /* Number of times stack has grown. */
- long shaseg:32; /* Size of increments to stack. */
- long shhwm:32; /* High water mark of stack. */
- long shsize:32; /* Current size of stack (all segments). */
+ long shgrow:32; /* Number of times stack has grown. */
+ long shaseg:32; /* Size of increments to stack. */
+ long shhwm:32; /* High water mark of stack. */
+ long shsize:32; /* Current size of stack (all segments). */
};
/* The stack segment linkage control information occurs at
@@ -241,21 +233,21 @@ struct stack_control_header
struct stack_segment_linkage
{
- long ss[0200]; /* 0200 overflow words. */
- long sssize:32; /* Number of words in this segment. */
- long ssbase:32; /* Offset to stack base. */
+ long ss[0200]; /* 0200 overflow words. */
+ long sssize:32; /* Number of words in this segment. */
+ long ssbase:32; /* Offset to stack base. */
long:32;
- long sspseg:32; /* Offset to linkage control of previous
- segment of stack. */
+ long sspseg:32; /* Offset to linkage control of previous
+ segment of stack. */
long:32;
- long sstcpt:32; /* Pointer to task common address block. */
- long sscsnm; /* Private control structure number for
- microtasking. */
- long ssusr1; /* Reserved for user. */
- long ssusr2; /* Reserved for user. */
- long sstpid; /* Process ID for pid based multi-tasking. */
- long ssgvup; /* Pointer to multitasking thread giveup. */
- long sscray[7]; /* Reserved for Cray Research. */
+ long sstcpt:32; /* Pointer to task common address block. */
+ long sscsnm; /* Private control structure number for
+ microtasking. */
+ long ssusr1; /* Reserved for user. */
+ long ssusr2; /* Reserved for user. */
+ long sstpid; /* Process ID for pid based multi-tasking. */
+ long ssgvup; /* Pointer to multitasking thread giveup. */
+ long sscray[7]; /* Reserved for Cray Research. */
long ssa0;
long ssa1;
long ssa2;
@@ -274,32 +266,32 @@ struct stack_segment_linkage
long sss7;
};
-#else /* CRAY2 */
+# else /* CRAY2 */
/* The following structure defines the vector of words
returned by the STKSTAT library routine. */
struct stk_stat
{
- long now; /* Current total stack size. */
- long maxc; /* Amount of contiguous space which would
- be required to satisfy the maximum
- stack demand to date. */
- long high_water; /* Stack high-water mark. */
- long overflows; /* Number of stack overflow ($STKOFEN) calls. */
- long hits; /* Number of internal buffer hits. */
- long extends; /* Number of block extensions. */
- long stko_mallocs; /* Block allocations by $STKOFEN. */
- long underflows; /* Number of stack underflow calls ($STKRETN). */
- long stko_free; /* Number of deallocations by $STKRETN. */
- long stkm_free; /* Number of deallocations by $STKMRET. */
- long segments; /* Current number of stack segments. */
- long maxs; /* Maximum number of stack segments so far. */
- long pad_size; /* Stack pad size. */
- long current_address; /* Current stack segment address. */
- long current_size; /* Current stack segment size. This
- number is actually corrupted by STKSTAT to
- include the fifteen word trailer area. */
- long initial_address; /* Address of initial segment. */
- long initial_size; /* Size of initial segment. */
+ long now; /* Current total stack size. */
+ long maxc; /* Amount of contiguous space which would
+ be required to satisfy the maximum
+ stack demand to date. */
+ long high_water; /* Stack high-water mark. */
+ long overflows; /* Number of stack overflow ($STKOFEN) calls. */
+ long hits; /* Number of internal buffer hits. */
+ long extends; /* Number of block extensions. */
+ long stko_mallocs; /* Block allocations by $STKOFEN. */
+ long underflows; /* Number of stack underflow calls ($STKRETN). */
+ long stko_free; /* Number of deallocations by $STKRETN. */
+ long stkm_free; /* Number of deallocations by $STKMRET. */
+ long segments; /* Current number of stack segments. */
+ long maxs; /* Maximum number of stack segments so far. */
+ long pad_size; /* Stack pad size. */
+ long current_address; /* Current stack segment address. */
+ long current_size; /* Current stack segment size. This
+ number is actually corrupted by STKSTAT to
+ include the fifteen word trailer area. */
+ long initial_address; /* Address of initial segment. */
+ long initial_size; /* Size of initial segment. */
};
/* The following structure describes the data structure which trails
@@ -308,13 +300,13 @@ struct stk_stat
struct stk_trailer
{
- long this_address; /* Address of this block. */
- long this_size; /* Size of this block (does not include
- this trailer). */
+ long this_address; /* Address of this block. */
+ long this_size; /* Size of this block (does not include
+ this trailer). */
long unknown2;
long unknown3;
- long link; /* Address of trailer block of previous
- segment. */
+ long link; /* Address of trailer block of previous
+ segment. */
long unknown5;
long unknown6;
long unknown7;
@@ -327,10 +319,10 @@ struct stk_trailer
long unknown14;
};
-#endif /* CRAY2 */
-#endif /* not CRAY_STACK */
+# endif /* CRAY2 */
+# endif /* not CRAY_STACK */
-#ifdef CRAY2
+# ifdef CRAY2
/* Determine a "stack measure" for an arbitrary ADDRESS.
I doubt that "lint" will like this much. */
@@ -352,8 +344,8 @@ i00afunc (long *address)
/* Set up the iteration. */
trailer = (struct stk_trailer *) (status.current_address
- + status.current_size
- - 15);
+ + status.current_size
+ - 15);
/* There must be at least one stack segment. Therefore it is
a fatal error if "trailer" is null. */
@@ -368,10 +360,10 @@ i00afunc (long *address)
block = (long *) trailer->this_address;
size = trailer->this_size;
if (block == 0 || size == 0)
- abort ();
+ abort ();
trailer = (struct stk_trailer *) trailer->link;
if ((block <= address) && (address < (block + size)))
- break;
+ break;
}
/* Set the result to the offset in this segment and add the sizes
@@ -387,7 +379,7 @@ i00afunc (long *address)
do
{
if (trailer->this_size <= 0)
- abort ();
+ abort ();
result += trailer->this_size;
trailer = (struct stk_trailer *) trailer->link;
}
@@ -401,7 +393,7 @@ i00afunc (long *address)
return (result);
}
-#else /* not CRAY2 */
+# else /* not CRAY2 */
/* Stack address function for a CRAY-1, CRAY X-MP, or CRAY Y-MP.
Determine the number of the cell within the stack,
given the address of the cell. The purpose of this
@@ -446,11 +438,11 @@ i00afunc (long address)
while (!(this_segment <= address && address <= stkl))
{
-#ifdef DEBUG_I00AFUNC
+# ifdef DEBUG_I00AFUNC
fprintf (stderr, "%011o %011o %011o\n", this_segment, address, stkl);
-#endif
+# endif
if (pseg == 0)
- break;
+ break;
stkl = stkl - pseg;
ssptr = (struct stack_segment_linkage *) stkl;
size = ssptr->sssize;
@@ -467,9 +459,9 @@ i00afunc (long address)
while (pseg != 0)
{
-#ifdef DEBUG_I00AFUNC
+# ifdef DEBUG_I00AFUNC
fprintf (stderr, "%011o %011o\n", pseg, size);
-#endif
+# endif
stkl = stkl - pseg;
ssptr = (struct stack_segment_linkage *) stkl;
size = ssptr->sssize;
@@ -479,5 +471,8 @@ i00afunc (long address)
return (result);
}
-#endif /* not CRAY2 */
-#endif /* CRAY */
+# endif /* not CRAY2 */
+# endif /* CRAY */
+
+# endif /* no alloca */
+#endif /* not GCC 2 */
« no previous file with comments | « gdb/gnulib/import/Makefile.in ('k') | gdb/gnulib/import/alloca.in.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698