aboutsummaryrefslogtreecommitdiff
path: root/gdb/obstack.c
diff options
context:
space:
mode:
authorgdb-2.8 <gdb@fsf.org>1988-09-03 08:00:00 +0100
committerPedro Alves <palves@redhat.com>2012-06-03 15:36:31 +0100
commit3bf57d210832b28e9361990830eb722a619f031b (patch)
treeba506d293bde0f6500d0cee3e643ebf8890d9cf7 /gdb/obstack.c
parent7c75bab3d3ef344a6a0b13b9ab59ecd5855aceb5 (diff)
downloadgdb-3bf57d210832b28e9361990830eb722a619f031b.zip
gdb-3bf57d210832b28e9361990830eb722a619f031b.tar.gz
gdb-3bf57d210832b28e9361990830eb722a619f031b.tar.bz2
gdb-2.8
Diffstat (limited to 'gdb/obstack.c')
-rw-r--r--gdb/obstack.c55
1 files changed, 47 insertions, 8 deletions
diff --git a/gdb/obstack.c b/gdb/obstack.c
index 320e1b7..3b5bdef 100644
--- a/gdb/obstack.c
+++ b/gdb/obstack.c
@@ -57,9 +57,9 @@ Mere aggregation of another unrelated program with this program (or its
derivative) on a volume of a storage or distribution medium does not bring
the other program under the scope of these terms.
- 3. You may copy and distribute this program (or a portion or derivative
-of it, under Paragraph 2) in object code or executable form under the terms
-of Paragraphs 1 and 2 above provided that you also do one of the following:
+ 3. You may copy and distribute this program or any portion of it in
+compiled, executable or object code form under the terms of Paragraphs
+1 and 2 above provided that you do the following:
a) accompany it with the complete corresponding machine-readable
source code, which must be distributed under the terms of
@@ -111,13 +111,30 @@ what you give them. Help stamp out software-hoarding! */
#define POINTER char *
#endif
+/* Determine default alignment. */
+struct fooalign {char x; double d;};
+#define DEFAULT_ALIGNMENT ((char *)&((struct fooalign *) 0)->d - (char *)0)
+/* If malloc were really smart, it would round addresses to DEFAULT_ALIGNMENT.
+ But in fact it might be less smart and round addresses to as much as
+ DEFAULT_ROUNDING. So we prepare for it to do that. */
+union fooround {long x; double d;};
+#define DEFAULT_ROUNDING (sizeof (union fooround))
+
+/* When we copy a long block of data, this is the unit to do it with.
+ On some machines, copying successive ints does not work;
+ in such a case, redefine COPYING_UNIT to `long' (if that works)
+ or `char' as a last resort. */
+#ifndef COPYING_UNIT
+#define COPYING_UNIT int
+#endif
+
/* The non-GNU-C macros copy the obstack into this global variable
to avoid multiple evaluation. */
struct obstack *_obstack;
-/* Initialize an obstack H for use. Specify chunk size SIZE.
- Objects start on multiples of ALIGNMENT.
+/* Initialize an obstack H for use. Specify chunk size SIZE (0 means default).
+ Objects start on multiples of ALIGNMENT (0 means use default).
CHUNKFUN is the function to use to allocate chunks,
and FREEFUN the function to free them. */
@@ -129,7 +146,21 @@ _obstack_begin (h, size, alignment, chunkfun, freefun)
POINTER (*chunkfun) ();
void (*freefun) ();
{
- register struct _obstack_chunk* chunk; /* points to new chunk */
+ register struct _obstack_chunk* chunk; /* points to new chunk */
+
+ if (alignment == 0)
+ alignment = DEFAULT_ALIGNMENT;
+ if (size == 0)
+ /* Default size is what GNU malloc can fit in a 4096-byte block.
+ Pick a number small enough that when rounded up to DEFAULT_ROUNDING
+ it is still smaller than 4096 - 4. */
+ {
+ int extra = 4;
+ if (extra < DEFAULT_ROUNDING)
+ extra = DEFAULT_ROUNDING;
+ size = 4096 - extra;
+ }
+
h->chunkfun = (struct _obstack_chunk * (*)()) chunkfun;
h->freefun = freefun;
h->chunk_size = size;
@@ -172,8 +203,10 @@ _obstack_newchunk (h, length)
/* Move the existing object to the new chunk.
Word at a time is fast and is safe because these
structures are aligned at least that much. */
- for (i = (obj_size + sizeof (int) - 1) / sizeof (int); i >= 0; i--)
- ((int *)new_chunk->contents)[i] = ((int *)h->object_base)[i];
+ for (i = (obj_size + sizeof (COPYING_UNIT) - 1) / sizeof (COPYING_UNIT) - 1;
+ i >= 0; i--)
+ ((COPYING_UNIT *)new_chunk->contents)[i]
+ = ((COPYING_UNIT *)h->object_base)[i];
h->object_base = new_chunk->contents;
h->next_free = h->object_base + obj_size;
@@ -214,6 +247,10 @@ _obstack_free (h, obj)
abort ();
}
+#if 0
+/* These are now turned off because the applications do not use it
+ and it uses bcopy via obstack_grow, which causes trouble on sysV. */
+
/* Now define the functional versions of the obstack macros.
Define them to simply use the corresponding macros to do the job. */
@@ -322,3 +359,5 @@ POINTER (obstack_copy0) (obstack, pointer, length)
}
#endif /* __STDC__ */
+
+#endif /* 0 */