| File: | src/gnu/lib/libiberty/src/obstack.c |
| Warning: | line 223, column 5 Access to field 'limit' results in a dereference of a null pointer (loaded from variable 'chunk') |
Press '?' to see keyboard shortcuts
Keyboard shortcuts:
| 1 | /* obstack.c - subroutines used implicitly by object stack macros | |||
| 2 | Copyright (C) 1988,89,90,91,92,93,94,96,97 Free Software Foundation, Inc. | |||
| 3 | ||||
| 4 | ||||
| 5 | NOTE: This source is derived from an old version taken from the GNU C | |||
| 6 | Library (glibc). | |||
| 7 | ||||
| 8 | This program is free software; you can redistribute it and/or modify it | |||
| 9 | under the terms of the GNU General Public License as published by the | |||
| 10 | Free Software Foundation; either version 2, or (at your option) any | |||
| 11 | later version. | |||
| 12 | ||||
| 13 | This program is distributed in the hope that it will be useful, | |||
| 14 | but WITHOUT ANY WARRANTY; without even the implied warranty of | |||
| 15 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |||
| 16 | GNU General Public License for more details. | |||
| 17 | ||||
| 18 | You should have received a copy of the GNU General Public License | |||
| 19 | along with this program; if not, write to the Free Software | |||
| 20 | Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston, MA 02110-1301, | |||
| 21 | USA. */ | |||
| 22 | ||||
| 23 | #ifdef HAVE_CONFIG_H1 | |||
| 24 | #include <config.h> | |||
| 25 | #endif | |||
| 26 | ||||
| 27 | #include "obstack.h" | |||
| 28 | ||||
| 29 | /* NOTE BEFORE MODIFYING THIS FILE: This version number must be | |||
| 30 | incremented whenever callers compiled using an old obstack.h can no | |||
| 31 | longer properly call the functions in this obstack.c. */ | |||
| 32 | #define OBSTACK_INTERFACE_VERSION1 1 | |||
| 33 | ||||
| 34 | /* Comment out all this code if we are using the GNU C Library, and are not | |||
| 35 | actually compiling the library itself, and the installed library | |||
| 36 | supports the same library interface we do. This code is part of the GNU | |||
| 37 | C Library, but also included in many other GNU distributions. Compiling | |||
| 38 | and linking in this code is a waste when using the GNU C library | |||
| 39 | (especially if it is a shared library). Rather than having every GNU | |||
| 40 | program understand `configure --with-gnu-libc' and omit the object | |||
| 41 | files, it is simpler to just do this in the source for each such file. */ | |||
| 42 | ||||
| 43 | #include <stdio.h> /* Random thing to get __GNU_LIBRARY__. */ | |||
| 44 | #if !defined (_LIBC) && defined (__GNU_LIBRARY__) && __GNU_LIBRARY__ > 1 | |||
| 45 | #include <gnu-versions.h> | |||
| 46 | #if _GNU_OBSTACK_INTERFACE_VERSION == OBSTACK_INTERFACE_VERSION1 | |||
| 47 | #define ELIDE_CODE | |||
| 48 | #endif | |||
| 49 | #endif | |||
| 50 | ||||
| 51 | ||||
| 52 | #ifndef ELIDE_CODE | |||
| 53 | ||||
| 54 | ||||
| 55 | #define POINTERvoid * void * | |||
| 56 | ||||
| 57 | /* Determine default alignment. */ | |||
| 58 | struct fooalign {char x; double d;}; | |||
| 59 | #define DEFAULT_ALIGNMENT((long int) ((char *) &((struct fooalign *) 0)->d - (char *) 0)) \ | |||
| 60 | ((PTR_INT_TYPElong int) ((char *) &((struct fooalign *) 0)->d - (char *) 0)) | |||
| 61 | /* If malloc were really smart, it would round addresses to DEFAULT_ALIGNMENT. | |||
| 62 | But in fact it might be less smart and round addresses to as much as | |||
| 63 | DEFAULT_ROUNDING. So we prepare for it to do that. */ | |||
| 64 | union fooround {long x; double d;}; | |||
| 65 | #define DEFAULT_ROUNDING(sizeof (union fooround)) (sizeof (union fooround)) | |||
| 66 | ||||
| 67 | /* When we copy a long block of data, this is the unit to do it with. | |||
| 68 | On some machines, copying successive ints does not work; | |||
| 69 | in such a case, redefine COPYING_UNIT to `long' (if that works) | |||
| 70 | or `char' as a last resort. */ | |||
| 71 | #ifndef COPYING_UNITint | |||
| 72 | #define COPYING_UNITint int | |||
| 73 | #endif | |||
| 74 | ||||
| 75 | ||||
| 76 | /* The functions allocating more room by calling `obstack_chunk_alloc' | |||
| 77 | jump to the handler pointed to by `obstack_alloc_failed_handler'. | |||
| 78 | This variable by default points to the internal function | |||
| 79 | `print_and_abort'. */ | |||
| 80 | static void print_and_abort (void); | |||
| 81 | void (*obstack_alloc_failed_handler) (void) = print_and_abort; | |||
| 82 | ||||
| 83 | /* Exit value used when `print_and_abort' is used. */ | |||
| 84 | #if defined __GNU_LIBRARY__ || defined HAVE_STDLIB_H1 | |||
| 85 | #include <stdlib.h> | |||
| 86 | #endif | |||
| 87 | #ifndef EXIT_FAILURE1 | |||
| 88 | #define EXIT_FAILURE1 1 | |||
| 89 | #endif | |||
| 90 | int obstack_exit_failure = EXIT_FAILURE1; | |||
| 91 | ||||
| 92 | /* The non-GNU-C macros copy the obstack into this global variable | |||
| 93 | to avoid multiple evaluation. */ | |||
| 94 | ||||
| 95 | struct obstack *_obstack; | |||
| 96 | ||||
| 97 | /* Define a macro that either calls functions with the traditional malloc/free | |||
| 98 | calling interface, or calls functions with the mmalloc/mfree interface | |||
| 99 | (that adds an extra first argument), based on the state of use_extra_arg. | |||
| 100 | For free, do not use ?:, since some compilers, like the MIPS compilers, | |||
| 101 | do not allow (expr) ? void : void. */ | |||
| 102 | ||||
| 103 | #if defined (__STDC__1) && __STDC__1 | |||
| 104 | #define CALL_CHUNKFUN(h, size)(((h) -> use_extra_arg) ? (*(h)->chunkfun) ((h)->extra_arg , (size)) : (*(struct _obstack_chunk *(*) (long)) (h)->chunkfun ) ((size))) \ | |||
| 105 | (((h) -> use_extra_arg) \ | |||
| 106 | ? (*(h)->chunkfun) ((h)->extra_arg, (size)) \ | |||
| 107 | : (*(struct _obstack_chunk *(*) (long)) (h)->chunkfun) ((size))) | |||
| 108 | ||||
| 109 | #define CALL_FREEFUN(h, old_chunk)do { if ((h) -> use_extra_arg) (*(h)->freefun) ((h)-> extra_arg, (old_chunk)); else (*(void (*) (void *)) (h)->freefun ) ((old_chunk)); } while (0) \ | |||
| 110 | do { \ | |||
| 111 | if ((h) -> use_extra_arg) \ | |||
| 112 | (*(h)->freefun) ((h)->extra_arg, (old_chunk)); \ | |||
| 113 | else \ | |||
| 114 | (*(void (*) (void *)) (h)->freefun) ((old_chunk)); \ | |||
| 115 | } while (0) | |||
| 116 | #else | |||
| 117 | #define CALL_CHUNKFUN(h, size)(((h) -> use_extra_arg) ? (*(h)->chunkfun) ((h)->extra_arg , (size)) : (*(struct _obstack_chunk *(*) (long)) (h)->chunkfun ) ((size))) \ | |||
| 118 | (((h) -> use_extra_arg) \ | |||
| 119 | ? (*(h)->chunkfun) ((h)->extra_arg, (size)) \ | |||
| 120 | : (*(struct _obstack_chunk *(*) ()) (h)->chunkfun) ((size))) | |||
| 121 | ||||
| 122 | #define CALL_FREEFUN(h, old_chunk)do { if ((h) -> use_extra_arg) (*(h)->freefun) ((h)-> extra_arg, (old_chunk)); else (*(void (*) (void *)) (h)->freefun ) ((old_chunk)); } while (0) \ | |||
| 123 | do { \ | |||
| 124 | if ((h) -> use_extra_arg) \ | |||
| 125 | (*(h)->freefun) ((h)->extra_arg, (old_chunk)); \ | |||
| 126 | else \ | |||
| 127 | (*(void (*) ()) (h)->freefun) ((old_chunk)); \ | |||
| 128 | } while (0) | |||
| 129 | #endif | |||
| 130 | ||||
| 131 | ||||
| 132 | /* Initialize an obstack H for use. Specify chunk size SIZE (0 means default). | |||
| 133 | Objects start on multiples of ALIGNMENT (0 means use default). | |||
| 134 | CHUNKFUN is the function to use to allocate chunks, | |||
| 135 | and FREEFUN the function to free them. | |||
| 136 | ||||
| 137 | Return nonzero if successful, zero if out of memory. | |||
| 138 | To recover from an out of memory error, | |||
| 139 | free up some memory, then call this again. */ | |||
| 140 | ||||
| 141 | int | |||
| 142 | _obstack_begin (struct obstack *h, int size, int alignment, | |||
| 143 | POINTERvoid * (*chunkfun) (long), void (*freefun) (void *)) | |||
| 144 | { | |||
| 145 | register struct _obstack_chunk *chunk; /* points to new chunk */ | |||
| 146 | ||||
| 147 | if (alignment == 0) | |||
| 148 | alignment = (int) DEFAULT_ALIGNMENT((long int) ((char *) &((struct fooalign *) 0)->d - (char *) 0)); | |||
| 149 | if (size == 0) | |||
| 150 | /* Default size is what GNU malloc can fit in a 4096-byte block. */ | |||
| 151 | { | |||
| 152 | /* 12 is sizeof (mhead) and 4 is EXTRA from GNU malloc. | |||
| 153 | Use the values for range checking, because if range checking is off, | |||
| 154 | the extra bytes won't be missed terribly, but if range checking is on | |||
| 155 | and we used a larger request, a whole extra 4096 bytes would be | |||
| 156 | allocated. | |||
| 157 | ||||
| 158 | These number are irrelevant to the new GNU malloc. I suspect it is | |||
| 159 | less sensitive to the size of the request. */ | |||
| 160 | int extra = ((((12 + DEFAULT_ROUNDING(sizeof (union fooround)) - 1) & ~(DEFAULT_ROUNDING(sizeof (union fooround)) - 1)) | |||
| 161 | + 4 + DEFAULT_ROUNDING(sizeof (union fooround)) - 1) | |||
| 162 | & ~(DEFAULT_ROUNDING(sizeof (union fooround)) - 1)); | |||
| 163 | size = 4096 - extra; | |||
| 164 | } | |||
| 165 | ||||
| 166 | h->chunkfun = (struct _obstack_chunk * (*)(void *, long)) chunkfun; | |||
| 167 | h->freefun = (void (*) (void *, struct _obstack_chunk *)) freefun; | |||
| 168 | h->chunk_size = size; | |||
| 169 | h->alignment_mask = alignment - 1; | |||
| 170 | h->use_extra_arg = 0; | |||
| 171 | ||||
| 172 | chunk = h->chunk = CALL_CHUNKFUN (h, h -> chunk_size)(((h) -> use_extra_arg) ? (*(h)->chunkfun) ((h)->extra_arg , (h -> chunk_size)) : (*(struct _obstack_chunk *(*) (long )) (h)->chunkfun) ((h -> chunk_size))); | |||
| 173 | if (!chunk) | |||
| 174 | (*obstack_alloc_failed_handler) (); | |||
| 175 | h->next_free = h->object_base = chunk->contents; | |||
| 176 | h->chunk_limit = chunk->limit | |||
| 177 | = (char *) chunk + h->chunk_size; | |||
| 178 | chunk->prev = 0; | |||
| 179 | /* The initial chunk now contains no empty object. */ | |||
| 180 | h->maybe_empty_object = 0; | |||
| 181 | h->alloc_failed = 0; | |||
| 182 | return 1; | |||
| 183 | } | |||
| 184 | ||||
| 185 | int | |||
| 186 | _obstack_begin_1 (struct obstack *h, int size, int alignment, | |||
| 187 | POINTERvoid * (*chunkfun) (POINTERvoid *, long), | |||
| 188 | void (*freefun) (POINTERvoid *, POINTERvoid *), POINTERvoid * arg) | |||
| 189 | { | |||
| 190 | register struct _obstack_chunk *chunk; /* points to new chunk */ | |||
| 191 | ||||
| 192 | if (alignment == 0) | |||
| ||||
| 193 | alignment = (int) DEFAULT_ALIGNMENT((long int) ((char *) &((struct fooalign *) 0)->d - (char *) 0)); | |||
| 194 | if (size == 0) | |||
| 195 | /* Default size is what GNU malloc can fit in a 4096-byte block. */ | |||
| 196 | { | |||
| 197 | /* 12 is sizeof (mhead) and 4 is EXTRA from GNU malloc. | |||
| 198 | Use the values for range checking, because if range checking is off, | |||
| 199 | the extra bytes won't be missed terribly, but if range checking is on | |||
| 200 | and we used a larger request, a whole extra 4096 bytes would be | |||
| 201 | allocated. | |||
| 202 | ||||
| 203 | These number are irrelevant to the new GNU malloc. I suspect it is | |||
| 204 | less sensitive to the size of the request. */ | |||
| 205 | int extra = ((((12 + DEFAULT_ROUNDING(sizeof (union fooround)) - 1) & ~(DEFAULT_ROUNDING(sizeof (union fooround)) - 1)) | |||
| 206 | + 4 + DEFAULT_ROUNDING(sizeof (union fooround)) - 1) | |||
| 207 | & ~(DEFAULT_ROUNDING(sizeof (union fooround)) - 1)); | |||
| 208 | size = 4096 - extra; | |||
| 209 | } | |||
| 210 | ||||
| 211 | h->chunkfun = (struct _obstack_chunk * (*)(void *,long)) chunkfun; | |||
| 212 | h->freefun = (void (*) (void *, struct _obstack_chunk *)) freefun; | |||
| 213 | h->chunk_size = size; | |||
| 214 | h->alignment_mask = alignment - 1; | |||
| 215 | h->extra_arg = arg; | |||
| 216 | h->use_extra_arg = 1; | |||
| 217 | ||||
| 218 | chunk = h->chunk = CALL_CHUNKFUN (h, h -> chunk_size)(((h) -> use_extra_arg) ? (*(h)->chunkfun) ((h)->extra_arg , (h -> chunk_size)) : (*(struct _obstack_chunk *(*) (long )) (h)->chunkfun) ((h -> chunk_size))); | |||
| 219 | if (!chunk) | |||
| 220 | (*obstack_alloc_failed_handler) (); | |||
| 221 | h->next_free = h->object_base = chunk->contents; | |||
| 222 | h->chunk_limit = chunk->limit | |||
| 223 | = (char *) chunk + h->chunk_size; | |||
| ||||
| 224 | chunk->prev = 0; | |||
| 225 | /* The initial chunk now contains no empty object. */ | |||
| 226 | h->maybe_empty_object = 0; | |||
| 227 | h->alloc_failed = 0; | |||
| 228 | return 1; | |||
| 229 | } | |||
| 230 | ||||
| 231 | /* Allocate a new current chunk for the obstack *H | |||
| 232 | on the assumption that LENGTH bytes need to be added | |||
| 233 | to the current object, or a new object of length LENGTH allocated. | |||
| 234 | Copies any partial object from the end of the old chunk | |||
| 235 | to the beginning of the new one. */ | |||
| 236 | ||||
| 237 | void | |||
| 238 | _obstack_newchunk (struct obstack *h, int length) | |||
| 239 | { | |||
| 240 | register struct _obstack_chunk *old_chunk = h->chunk; | |||
| 241 | register struct _obstack_chunk *new_chunk; | |||
| 242 | register long new_size; | |||
| 243 | register long obj_size = h->next_free - h->object_base; | |||
| 244 | register long i; | |||
| 245 | long already; | |||
| 246 | ||||
| 247 | /* Compute size for new chunk. */ | |||
| 248 | new_size = (obj_size + length) + (obj_size >> 3) + 100; | |||
| 249 | if (new_size < h->chunk_size) | |||
| 250 | new_size = h->chunk_size; | |||
| 251 | ||||
| 252 | /* Allocate and initialize the new chunk. */ | |||
| 253 | new_chunk = CALL_CHUNKFUN (h, new_size)(((h) -> use_extra_arg) ? (*(h)->chunkfun) ((h)->extra_arg , (new_size)) : (*(struct _obstack_chunk *(*) (long)) (h)-> chunkfun) ((new_size))); | |||
| 254 | if (!new_chunk) | |||
| 255 | (*obstack_alloc_failed_handler) (); | |||
| 256 | h->chunk = new_chunk; | |||
| 257 | new_chunk->prev = old_chunk; | |||
| 258 | new_chunk->limit = h->chunk_limit = (char *) new_chunk + new_size; | |||
| 259 | ||||
| 260 | /* Move the existing object to the new chunk. | |||
| 261 | Word at a time is fast and is safe if the object | |||
| 262 | is sufficiently aligned. */ | |||
| 263 | if (h->alignment_mask + 1 >= DEFAULT_ALIGNMENT((long int) ((char *) &((struct fooalign *) 0)->d - (char *) 0))) | |||
| 264 | { | |||
| 265 | for (i = obj_size / sizeof (COPYING_UNITint) - 1; | |||
| 266 | i >= 0; i--) | |||
| 267 | ((COPYING_UNITint *)new_chunk->contents)[i] | |||
| 268 | = ((COPYING_UNITint *)h->object_base)[i]; | |||
| 269 | /* We used to copy the odd few remaining bytes as one extra COPYING_UNIT, | |||
| 270 | but that can cross a page boundary on a machine | |||
| 271 | which does not do strict alignment for COPYING_UNITS. */ | |||
| 272 | already = obj_size / sizeof (COPYING_UNITint) * sizeof (COPYING_UNITint); | |||
| 273 | } | |||
| 274 | else | |||
| 275 | already = 0; | |||
| 276 | /* Copy remaining bytes one by one. */ | |||
| 277 | for (i = already; i < obj_size; i++) | |||
| 278 | new_chunk->contents[i] = h->object_base[i]; | |||
| 279 | ||||
| 280 | /* If the object just copied was the only data in OLD_CHUNK, | |||
| 281 | free that chunk and remove it from the chain. | |||
| 282 | But not if that chunk might contain an empty object. */ | |||
| 283 | if (h->object_base == old_chunk->contents && ! h->maybe_empty_object) | |||
| 284 | { | |||
| 285 | new_chunk->prev = old_chunk->prev; | |||
| 286 | CALL_FREEFUN (h, old_chunk)do { if ((h) -> use_extra_arg) (*(h)->freefun) ((h)-> extra_arg, (old_chunk)); else (*(void (*) (void *)) (h)->freefun ) ((old_chunk)); } while (0); | |||
| 287 | } | |||
| 288 | ||||
| 289 | h->object_base = new_chunk->contents; | |||
| 290 | h->next_free = h->object_base + obj_size; | |||
| 291 | /* The new chunk certainly contains no empty object yet. */ | |||
| 292 | h->maybe_empty_object = 0; | |||
| 293 | } | |||
| 294 | ||||
| 295 | /* Return nonzero if object OBJ has been allocated from obstack H. | |||
| 296 | This is here for debugging. | |||
| 297 | If you use it in a program, you are probably losing. */ | |||
| 298 | ||||
| 299 | /* Suppress -Wmissing-prototypes warning. We don't want to declare this in | |||
| 300 | obstack.h because it is just for debugging. */ | |||
| 301 | int _obstack_allocated_p (struct obstack *h, POINTERvoid * obj); | |||
| 302 | ||||
| 303 | int | |||
| 304 | _obstack_allocated_p (struct obstack *h, POINTERvoid * obj) | |||
| 305 | { | |||
| 306 | register struct _obstack_chunk *lp; /* below addr of any objects in this chunk */ | |||
| 307 | register struct _obstack_chunk *plp; /* point to previous chunk if any */ | |||
| 308 | ||||
| 309 | lp = (h)->chunk; | |||
| 310 | /* We use >= rather than > since the object cannot be exactly at | |||
| 311 | the beginning of the chunk but might be an empty object exactly | |||
| 312 | at the end of an adjacent chunk. */ | |||
| 313 | while (lp != 0 && ((POINTERvoid *) lp >= obj || (POINTERvoid *) (lp)->limit < obj)) | |||
| 314 | { | |||
| 315 | plp = lp->prev; | |||
| 316 | lp = plp; | |||
| 317 | } | |||
| 318 | return lp != 0; | |||
| 319 | } | |||
| 320 | ||||
| 321 | /* Free objects in obstack H, including OBJ and everything allocate | |||
| 322 | more recently than OBJ. If OBJ is zero, free everything in H. */ | |||
| 323 | ||||
| 324 | #undef obstack_free | |||
| 325 | ||||
| 326 | /* This function has two names with identical definitions. | |||
| 327 | This is the first one, called from non-ANSI code. */ | |||
| 328 | ||||
| 329 | void | |||
| 330 | _obstack_free (struct obstack *h, POINTERvoid * obj) | |||
| 331 | { | |||
| 332 | register struct _obstack_chunk *lp; /* below addr of any objects in this chunk */ | |||
| 333 | register struct _obstack_chunk *plp; /* point to previous chunk if any */ | |||
| 334 | ||||
| 335 | lp = h->chunk; | |||
| 336 | /* We use >= because there cannot be an object at the beginning of a chunk. | |||
| 337 | But there can be an empty object at that address | |||
| 338 | at the end of another chunk. */ | |||
| 339 | while (lp != 0 && ((POINTERvoid *) lp >= obj || (POINTERvoid *) (lp)->limit < obj)) | |||
| 340 | { | |||
| 341 | plp = lp->prev; | |||
| 342 | CALL_FREEFUN (h, lp)do { if ((h) -> use_extra_arg) (*(h)->freefun) ((h)-> extra_arg, (lp)); else (*(void (*) (void *)) (h)->freefun) ((lp)); } while (0); | |||
| 343 | lp = plp; | |||
| 344 | /* If we switch chunks, we can't tell whether the new current | |||
| 345 | chunk contains an empty object, so assume that it may. */ | |||
| 346 | h->maybe_empty_object = 1; | |||
| 347 | } | |||
| 348 | if (lp) | |||
| 349 | { | |||
| 350 | h->object_base = h->next_free = (char *) (obj); | |||
| 351 | h->chunk_limit = lp->limit; | |||
| 352 | h->chunk = lp; | |||
| 353 | } | |||
| 354 | else if (obj != 0) | |||
| 355 | /* obj is not in any of the chunks! */ | |||
| 356 | abort (); | |||
| 357 | } | |||
| 358 | ||||
| 359 | /* This function is used from ANSI code. */ | |||
| 360 | ||||
| 361 | void | |||
| 362 | obstack_free (struct obstack *h, POINTERvoid * obj) | |||
| 363 | { | |||
| 364 | register struct _obstack_chunk *lp; /* below addr of any objects in this chunk */ | |||
| 365 | register struct _obstack_chunk *plp; /* point to previous chunk if any */ | |||
| 366 | ||||
| 367 | lp = h->chunk; | |||
| 368 | /* We use >= because there cannot be an object at the beginning of a chunk. | |||
| 369 | But there can be an empty object at that address | |||
| 370 | at the end of another chunk. */ | |||
| 371 | while (lp != 0 && ((POINTERvoid *) lp >= obj || (POINTERvoid *) (lp)->limit < obj)) | |||
| 372 | { | |||
| 373 | plp = lp->prev; | |||
| 374 | CALL_FREEFUN (h, lp)do { if ((h) -> use_extra_arg) (*(h)->freefun) ((h)-> extra_arg, (lp)); else (*(void (*) (void *)) (h)->freefun) ((lp)); } while (0); | |||
| 375 | lp = plp; | |||
| 376 | /* If we switch chunks, we can't tell whether the new current | |||
| 377 | chunk contains an empty object, so assume that it may. */ | |||
| 378 | h->maybe_empty_object = 1; | |||
| 379 | } | |||
| 380 | if (lp) | |||
| 381 | { | |||
| 382 | h->object_base = h->next_free = (char *) (obj); | |||
| 383 | h->chunk_limit = lp->limit; | |||
| 384 | h->chunk = lp; | |||
| 385 | } | |||
| 386 | else if (obj != 0) | |||
| 387 | /* obj is not in any of the chunks! */ | |||
| 388 | abort (); | |||
| 389 | } | |||
| 390 | ||||
| 391 | int | |||
| 392 | _obstack_memory_used (struct obstack *h) | |||
| 393 | { | |||
| 394 | register struct _obstack_chunk* lp; | |||
| 395 | register int nbytes = 0; | |||
| 396 | ||||
| 397 | for (lp = h->chunk; lp != 0; lp = lp->prev) | |||
| 398 | { | |||
| 399 | nbytes += lp->limit - (char *) lp; | |||
| 400 | } | |||
| 401 | return nbytes; | |||
| 402 | } | |||
| 403 | ||||
| 404 | /* Define the error handler. */ | |||
| 405 | #ifndef _ | |||
| 406 | # if (HAVE_LIBINTL_H && ENABLE_NLS) || defined _LIBC | |||
| 407 | # include <libintl.h> | |||
| 408 | # ifndef _ | |||
| 409 | # define _(Str)(Str) gettext (Str) | |||
| 410 | # endif | |||
| 411 | # else | |||
| 412 | # define _(Str)(Str) (Str) | |||
| 413 | # endif | |||
| 414 | #endif | |||
| 415 | ||||
| 416 | static void | |||
| 417 | print_and_abort (void) | |||
| 418 | { | |||
| 419 | fputs (_("memory exhausted\n")("memory exhausted\n"), stderr(&__sF[2])); | |||
| 420 | exit (obstack_exit_failure); | |||
| 421 | } | |||
| 422 | ||||
| 423 | #if 0 | |||
| 424 | /* These are now turned off because the applications do not use it | |||
| 425 | and it uses bcopy via obstack_grow, which causes trouble on sysV. */ | |||
| 426 | ||||
| 427 | /* Now define the functional versions of the obstack macros. | |||
| 428 | Define them to simply use the corresponding macros to do the job. */ | |||
| 429 | ||||
| 430 | /* The function names appear in parentheses in order to prevent | |||
| 431 | the macro-definitions of the names from being expanded there. */ | |||
| 432 | ||||
| 433 | POINTERvoid * (obstack_base) (struct obstack *obstack) | |||
| 434 | { | |||
| 435 | return obstack_base (obstack)((obstack)->object_base); | |||
| 436 | } | |||
| 437 | ||||
| 438 | POINTERvoid * (obstack_next_free) (struct obstack *obstack) | |||
| 439 | { | |||
| 440 | return obstack_next_free (obstack)((obstack)->next_free); | |||
| 441 | } | |||
| 442 | ||||
| 443 | int (obstack_object_size) (struct obstack *obstack) | |||
| 444 | { | |||
| 445 | return obstack_object_size (obstack)__extension__ ({ struct obstack *__o = (obstack); (unsigned) ( __o->next_free - __o->object_base); }); | |||
| 446 | } | |||
| 447 | ||||
| 448 | int (obstack_room) (struct obstack *obstack) | |||
| 449 | { | |||
| 450 | return obstack_room (obstack)__extension__ ({ struct obstack *__o = (obstack); (unsigned) ( __o->chunk_limit - __o->next_free); }); | |||
| 451 | } | |||
| 452 | ||||
| 453 | int (obstack_make_room) (struct obstack *obstack, int length) | |||
| 454 | { | |||
| 455 | return obstack_make_room (obstack, length)__extension__ ({ struct obstack *__o = (obstack); int __len = (length); if (__o->chunk_limit - __o->next_free < __len ) _obstack_newchunk (__o, __len); (void) 0; }); | |||
| 456 | } | |||
| 457 | ||||
| 458 | void (obstack_grow) (struct obstack *obstack, POINTERvoid * pointer, int length) | |||
| 459 | { | |||
| 460 | obstack_grow (obstack, pointer, length)__extension__ ({ struct obstack *__o = (obstack); int __len = (length); if (__o->next_free + __len > __o->chunk_limit ) _obstack_newchunk (__o, __len); memcpy ((__o->next_free) , ((pointer)), (__len)); __o->next_free += __len; (void) 0 ; }); | |||
| 461 | } | |||
| 462 | ||||
| 463 | void (obstack_grow0) (struct obstack *obstack, POINTERvoid * pointer, int length) | |||
| 464 | { | |||
| 465 | obstack_grow0 (obstack, pointer, length)__extension__ ({ struct obstack *__o = (obstack); int __len = (length); if (__o->next_free + __len + 1 > __o->chunk_limit ) _obstack_newchunk (__o, __len + 1); memcpy ((__o->next_free ), ((pointer)), (__len)); __o->next_free += __len; *(__o-> next_free)++ = 0; (void) 0; }); | |||
| 466 | } | |||
| 467 | ||||
| 468 | void (obstack_1grow) (struct obstack *obstack, int character) | |||
| 469 | { | |||
| 470 | obstack_1grow (obstack, character)__extension__ ({ struct obstack *__o = (obstack); if (__o-> next_free + 1 > __o->chunk_limit) _obstack_newchunk (__o , 1); (*((__o)->next_free)++ = (character)); (void) 0; }); | |||
| 471 | } | |||
| 472 | ||||
| 473 | void (obstack_blank) (struct obstack *obstack, int length) | |||
| 474 | { | |||
| 475 | obstack_blank (obstack, length)__extension__ ({ struct obstack *__o = (obstack); int __len = (length); if (__o->chunk_limit - __o->next_free < __len ) _obstack_newchunk (__o, __len); ((__o)->next_free += (__len )); (void) 0; }); | |||
| 476 | } | |||
| 477 | ||||
| 478 | void (obstack_1grow_fast) (struct obstack *obstack, int character) | |||
| 479 | { | |||
| 480 | obstack_1grow_fast (obstack, character)(*((obstack)->next_free)++ = (character)); | |||
| 481 | } | |||
| 482 | ||||
| 483 | void (obstack_blank_fast) (struct obstack *obstack, int length) | |||
| 484 | { | |||
| 485 | obstack_blank_fast (obstack, length)((obstack)->next_free += (length)); | |||
| 486 | } | |||
| 487 | ||||
| 488 | POINTERvoid * (obstack_finish) (struct obstack *obstack) | |||
| 489 | { | |||
| 490 | return obstack_finish (obstack)__extension__ ({ struct obstack *__o1 = (obstack); void *value ; value = (void *) __o1->object_base; if (__o1->next_free == value) __o1->maybe_empty_object = 1; __o1->next_free = (((((__o1->next_free) - (char *) 0)+__o1->alignment_mask ) & ~ (__o1->alignment_mask)) + (char *) 0); if (__o1-> next_free - (char *)__o1->chunk > __o1->chunk_limit - (char *)__o1->chunk) __o1->next_free = __o1->chunk_limit ; __o1->object_base = __o1->next_free; value; }); | |||
| 491 | } | |||
| 492 | ||||
| 493 | POINTERvoid * (obstack_alloc) (struct obstack *obstack, int length) | |||
| 494 | { | |||
| 495 | return obstack_alloc (obstack, length)__extension__ ({ struct obstack *__h = (obstack); __extension__ ({ struct obstack *__o = (__h); int __len = ((length)); if ( __o->chunk_limit - __o->next_free < __len) _obstack_newchunk (__o, __len); ((__o)->next_free += (__len)); (void) 0; }) ; __extension__ ({ struct obstack *__o1 = (__h); void *value; value = (void *) __o1->object_base; if (__o1->next_free == value) __o1->maybe_empty_object = 1; __o1->next_free = (((((__o1->next_free) - (char *) 0)+__o1->alignment_mask ) & ~ (__o1->alignment_mask)) + (char *) 0); if (__o1-> next_free - (char *)__o1->chunk > __o1->chunk_limit - (char *)__o1->chunk) __o1->next_free = __o1->chunk_limit ; __o1->object_base = __o1->next_free; value; }); }); | |||
| 496 | } | |||
| 497 | ||||
| 498 | POINTERvoid * (obstack_copy) (struct obstack *obstack, POINTERvoid * pointer, int length) | |||
| 499 | { | |||
| 500 | return obstack_copy (obstack, pointer, length)__extension__ ({ struct obstack *__h = (obstack); __extension__ ({ struct obstack *__o = (__h); int __len = ((length)); if ( __o->next_free + __len > __o->chunk_limit) _obstack_newchunk (__o, __len); memcpy ((__o->next_free), (((pointer))), (__len )); __o->next_free += __len; (void) 0; }); __extension__ ( { struct obstack *__o1 = (__h); void *value; value = (void *) __o1->object_base; if (__o1->next_free == value) __o1-> maybe_empty_object = 1; __o1->next_free = (((((__o1->next_free ) - (char *) 0)+__o1->alignment_mask) & ~ (__o1->alignment_mask )) + (char *) 0); if (__o1->next_free - (char *)__o1->chunk > __o1->chunk_limit - (char *)__o1->chunk) __o1-> next_free = __o1->chunk_limit; __o1->object_base = __o1 ->next_free; value; }); }); | |||
| 501 | } | |||
| 502 | ||||
| 503 | POINTERvoid * (obstack_copy0) (struct obstack *obstack, POINTERvoid * pointer, int length) | |||
| 504 | { | |||
| 505 | return obstack_copy0 (obstack, pointer, length)__extension__ ({ struct obstack *__h = (obstack); __extension__ ({ struct obstack *__o = (__h); int __len = ((length)); if ( __o->next_free + __len + 1 > __o->chunk_limit) _obstack_newchunk (__o, __len + 1); memcpy ((__o->next_free), (((pointer))) , (__len)); __o->next_free += __len; *(__o->next_free)++ = 0; (void) 0; }); __extension__ ({ struct obstack *__o1 = ( __h); void *value; value = (void *) __o1->object_base; if ( __o1->next_free == value) __o1->maybe_empty_object = 1; __o1->next_free = (((((__o1->next_free) - (char *) 0)+ __o1->alignment_mask) & ~ (__o1->alignment_mask)) + (char *) 0); if (__o1->next_free - (char *)__o1->chunk > __o1->chunk_limit - (char *)__o1->chunk) __o1-> next_free = __o1->chunk_limit; __o1->object_base = __o1 ->next_free; value; }); }); | |||
| 506 | } | |||
| 507 | ||||
| 508 | #endif /* 0 */ | |||
| 509 | ||||
| 510 | #endif /* !ELIDE_CODE */ |