Changeset 2155 for trunk/src/emx/include/obstack.h
- Timestamp:
- Jul 2, 2005, 11:38:03 PM (20 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/emx/include/obstack.h
-
Property cvs2svn:cvs-rev
changed from
1.2
to1.3
r2154 r2155 1 /* obstack.h,v 1.2 2004/09/14 22:27:34 bird Exp */ 1 /* obstack.h - object stack macros 2 Copyright (C) 1988-1994,1996-1999,2003,2004 Free Software Foundation, Inc. 3 This file is part of the GNU C Library. Its master source is NOT part of 4 the C library, however. The master source lives in /gd/gnu/lib. 5 6 The GNU C Library is free software; you can redistribute it and/or 7 modify it under the terms of the GNU Lesser General Public 8 License as published by the Free Software Foundation; either 9 version 2.1 of the License, or (at your option) any later version. 10 11 The GNU C Library is distributed in the hope that it will be useful, 12 but WITHOUT ANY WARRANTY; without even the implied warranty of 13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 14 Lesser General Public License for more details. 15 16 You should have received a copy of the GNU Lesser General Public 17 License along with the GNU C Library; if not, write to the Free 18 Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 19 02111-1307 USA. */ 2 20 /** @file 3 * G NU, -liberty.21 * GLIBC 2.3.x CVS 4 22 */ 5 6 /* obstack.h - object stack macros7 Copyright 1988, 1989, 1990, 1991, 1992, 1993, 1994, 1996, 1997, 1998,8 1999, 20009 Free Software Foundation, Inc.10 11 12 NOTE: The canonical source of this file is maintained with the GNU C Library.13 Bugs can be reported to bug-glibc@gnu.org.14 15 This program is free software; you can redistribute it and/or modify it16 under the terms of the GNU General Public License as published by the17 Free Software Foundation; either version 2, or (at your option) any18 later version.19 20 This program is distributed in the hope that it will be useful,21 but WITHOUT ANY WARRANTY; without even the implied warranty of22 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the23 GNU General Public License for more details.24 25 You should have received a copy of the GNU General Public License26 along with this program; if not, write to the Free Software27 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,28 USA. */29 23 30 24 /* Summary: … … 135 129 /* We need the type of the resulting object. If __PTRDIFF_TYPE__ is 136 130 defined, as with GNU C, use that; that way we don't pollute the 137 namespace with <stddef.h>'s symbols. Otherwise, if <stddef.h> is 138 available, include it and use ptrdiff_t. In traditional C, long is 139 the best that we can do. */ 131 namespace with <stddef.h>'s symbols. Otherwise, include <stddef.h> 132 and use ptrdiff_t. */ 140 133 141 134 #ifdef __PTRDIFF_TYPE__ 142 135 # define PTR_INT_TYPE __PTRDIFF_TYPE__ 143 136 #else 144 # ifdef HAVE_STDDEF_H 145 # include <stddef.h> 146 # define PTR_INT_TYPE ptrdiff_t 147 # else 148 # define PTR_INT_TYPE long 149 # endif 137 # include <stddef.h> 138 # define PTR_INT_TYPE ptrdiff_t 150 139 #endif 151 140 152 #if defined _LIBC || defined HAVE_STRING_H 153 # include <string.h> 154 # if defined __STDC__ && __STDC__ 155 # define _obstack_memcpy(To, From, N) memcpy ((To), (From), (N)) 156 # else 157 # define _obstack_memcpy(To, From, N) memcpy ((To), (char *)(From), (N)) 158 # endif 159 #else 160 # ifdef memcpy 161 # define _obstack_memcpy(To, From, N) memcpy ((To), (char *)(From), (N)) 162 # else 163 # define _obstack_memcpy(To, From, N) bcopy ((char *)(From), (To), (N)) 164 # endif 165 #endif 141 #include <string.h> 166 142 167 143 struct _obstack_chunk /* Lives at front of each chunk. */ … … 181 157 PTR_INT_TYPE temp; /* Temporary for some macros. */ 182 158 int alignment_mask; /* Mask of alignment for each object. */ 183 #if defined __STDC__ && __STDC__184 159 /* These prototypes vary based on `use_extra_arg', and we use 185 160 casts to the prototypeless function type in all assignments, … … 188 163 void (*freefun) (void *, struct _obstack_chunk *); 189 164 void *extra_arg; /* first arg for chunk alloc/dealloc funcs */ 190 #else191 struct _obstack_chunk *(*chunkfun) (); /* User's fcn to allocate a chunk. */192 void (*freefun) (); /* User's function to free a chunk. */193 char *extra_arg; /* first arg for chunk alloc/dealloc funcs */194 #endif195 165 unsigned use_extra_arg:1; /* chunk alloc/dealloc funcs take extra arg */ 196 166 unsigned maybe_empty_object:1;/* There is a possibility that the current … … 205 175 /* Declare the external functions we use; they are in obstack.c. */ 206 176 207 #if defined __STDC__ && __STDC__208 177 extern void _obstack_newchunk (struct obstack *, int); 209 extern void _obstack_free (struct obstack *, void *);210 178 extern int _obstack_begin (struct obstack *, int, int, 211 179 void *(*) (long), void (*) (void *)); … … 214 182 void (*) (void *, void *), void *); 215 183 extern int _obstack_memory_used (struct obstack *); 216 #else217 extern void _obstack_newchunk ();218 extern void _obstack_free ();219 extern int _obstack_begin ();220 extern int _obstack_begin_1 ();221 extern int _obstack_memory_used ();222 #endif223 224 225 #if defined __STDC__ && __STDC__226 227 /* Do the function-declarations after the structs228 but before defining the macros. */229 230 void obstack_init (struct obstack *obstack);231 232 void * obstack_alloc (struct obstack *obstack, int size);233 234 void * obstack_copy (struct obstack *obstack, void *address, int size);235 void * obstack_copy0 (struct obstack *obstack, void *address, int size);236 184 237 185 void obstack_free (struct obstack *obstack, void *block); 238 186 239 void obstack_blank (struct obstack *obstack, int size); 240 241 void obstack_grow (struct obstack *obstack, void *data, int size); 242 void obstack_grow0 (struct obstack *obstack, void *data, int size); 243 244 void obstack_1grow (struct obstack *obstack, int data_char); 245 void obstack_ptr_grow (struct obstack *obstack, void *data); 246 void obstack_int_grow (struct obstack *obstack, int data); 247 248 void * obstack_finish (struct obstack *obstack); 249 250 int obstack_object_size (struct obstack *obstack); 251 252 int obstack_room (struct obstack *obstack); 253 void obstack_make_room (struct obstack *obstack, int size); 254 void obstack_1grow_fast (struct obstack *obstack, int data_char); 255 void obstack_ptr_grow_fast (struct obstack *obstack, void *data); 256 void obstack_int_grow_fast (struct obstack *obstack, int data); 257 void obstack_blank_fast (struct obstack *obstack, int size); 258 259 void * obstack_base (struct obstack *obstack); 260 void * obstack_next_free (struct obstack *obstack); 261 int obstack_alignment_mask (struct obstack *obstack); 262 int obstack_chunk_size (struct obstack *obstack); 263 int obstack_memory_used (struct obstack *obstack); 264 265 #endif /* __STDC__ */ 266 267 /* Non-ANSI C cannot really support alternative functions for these macros, 268 so we do not declare them. */ 187 269 188 270 189 /* Error handler called when `obstack_chunk_alloc' failed to allocate 271 more memory. This can be set to a user defined function . The272 default action is to print a message and abort. */273 #if defined __STDC__ && __STDC__ 190 more memory. This can be set to a user defined function which 191 should either abort gracefully or use longjump - but shouldn't 192 return. The default action is to print a message and abort. */ 274 193 extern void (*obstack_alloc_failed_handler) (void); 275 #else276 extern void (*obstack_alloc_failed_handler) ();277 #endif278 194 279 195 /* Exit value used when `print_and_abort' is used. */ … … 285 201 because a new chunk might be needed to hold the final size. */ 286 202 287 #define obstack_base(h) (( h)->object_base)203 #define obstack_base(h) ((void *) (h)->object_base) 288 204 289 205 /* Size for allocating ordinary chunks. */ … … 299 215 #define obstack_alignment_mask(h) ((h)->alignment_mask) 300 216 301 /* To prevent prototype warnings provide complete argument list in302 standard C version. */ 303 #if defined __STDC__ && __STDC__ 304 305 # define obstack_init(h) \ 306 _obstack_begin ((h), 0, 0, \ 307 (void *(*) (long)) obstack_chunk_alloc, (void (*) (void *)) obstack_chunk_free) 308 309 # define obstack_begin(h, size)\310 _obstack_begin ((h), (size), 0, \ 311 (void *(*) (long)) obstack_chunk_alloc, (void (*) (void *)) obstack_chunk_free) 312 313 # define obstack_specify_allocation(h, size, alignment, chunkfun, freefun)\314 _obstack_begin ((h), (size), (alignment),\315 (void *(*) (long)) (chunkfun),(void (*) (void *)) (freefun))316 317 # 318 _obstack_begin_1 ((h), (size), (alignment), 319 (void *(*) (void *, long)) (chunkfun), 217 /* To prevent prototype warnings provide complete argument list. */ 218 #define obstack_init(h) \ 219 _obstack_begin ((h), 0, 0, \ 220 (void *(*) (long)) obstack_chunk_alloc, \ 221 (void (*) (void *)) obstack_chunk_free) 222 223 #define obstack_begin(h, size) \ 224 _obstack_begin ((h), (size), 0, \ 225 (void *(*) (long)) obstack_chunk_alloc, \ 226 (void (*) (void *)) obstack_chunk_free) 227 228 #define obstack_specify_allocation(h, size, alignment, chunkfun, freefun) \ 229 _obstack_begin ((h), (size), (alignment), \ 230 (void *(*) (long)) (chunkfun), \ 231 (void (*) (void *)) (freefun)) 232 233 #define obstack_specify_allocation_with_arg(h, size, alignment, chunkfun, freefun, arg) \ 234 _obstack_begin_1 ((h), (size), (alignment), \ 235 (void *(*) (void *, long)) (chunkfun), \ 320 236 (void (*) (void *, void *)) (freefun), (arg)) 321 237 322 # 238 #define obstack_chunkfun(h, newchunkfun) \ 323 239 ((h) -> chunkfun = (struct _obstack_chunk *(*)(void *, long)) (newchunkfun)) 324 240 325 # 241 #define obstack_freefun(h, newfreefun) \ 326 242 ((h) -> freefun = (void (*)(void *, struct _obstack_chunk *)) (newfreefun)) 327 243 328 #else 329 330 # define obstack_init(h) \ 331 _obstack_begin ((h), 0, 0, \ 332 (void *(*) ()) obstack_chunk_alloc, (void (*) ()) obstack_chunk_free) 333 334 # define obstack_begin(h, size) \ 335 _obstack_begin ((h), (size), 0, \ 336 (void *(*) ()) obstack_chunk_alloc, (void (*) ()) obstack_chunk_free) 337 338 # define obstack_specify_allocation(h, size, alignment, chunkfun, freefun) \ 339 _obstack_begin ((h), (size), (alignment), \ 340 (void *(*) ()) (chunkfun), (void (*) ()) (freefun)) 341 342 # define obstack_specify_allocation_with_arg(h, size, alignment, chunkfun, freefun, arg) \ 343 _obstack_begin_1 ((h), (size), (alignment), \ 344 (void *(*) ()) (chunkfun), (void (*) ()) (freefun), (arg)) 345 346 # define obstack_chunkfun(h, newchunkfun) \ 347 ((h) -> chunkfun = (struct _obstack_chunk *(*)()) (newchunkfun)) 348 349 # define obstack_freefun(h, newfreefun) \ 350 ((h) -> freefun = (void (*)()) (newfreefun)) 351 352 #endif 353 354 #define obstack_1grow_fast(h,achar) (*((h)->next_free)++ = achar) 244 #define obstack_1grow_fast(h,achar) (*((h)->next_free)++ = (achar)) 355 245 356 246 #define obstack_blank_fast(h,n) ((h)->next_free += (n)) … … 363 253 does not implement __extension__. But that compiler doesn't define 364 254 __GNUC_MINOR__. */ 365 # if __GNUC__ < 2 || ( __NeXT__ && !__GNUC_MINOR__)255 # if __GNUC__ < 2 || (defined __NeXT__ && __NeXT__ && !__GNUC_MINOR__) 366 256 # define __extension__ 367 257 # endif … … 374 264 # define obstack_object_size(OBSTACK) \ 375 265 __extension__ \ 376 ({ struct obstack *__o = (OBSTACK);\266 ({ struct obstack const *__o = (OBSTACK); \ 377 267 (unsigned) (__o->next_free - __o->object_base); }) 378 268 379 269 # define obstack_room(OBSTACK) \ 380 270 __extension__ \ 381 ({ struct obstack *__o = (OBSTACK);\271 ({ struct obstack const *__o = (OBSTACK); \ 382 272 (unsigned) (__o->chunk_limit - __o->next_free); }) 383 273 … … 392 282 # define obstack_empty_p(OBSTACK) \ 393 283 __extension__ \ 394 ({ struct obstack *__o = (OBSTACK);\284 ({ struct obstack const *__o = (OBSTACK); \ 395 285 (__o->chunk->prev == 0 && __o->next_free - __o->chunk->contents == 0); }) 396 286 … … 401 291 if (__o->next_free + __len > __o->chunk_limit) \ 402 292 _obstack_newchunk (__o, __len); \ 403 _obstack_memcpy (__o->next_free, (where), __len);\293 memcpy (__o->next_free, where, __len); \ 404 294 __o->next_free += __len; \ 405 295 (void) 0; }) … … 411 301 if (__o->next_free + __len + 1 > __o->chunk_limit) \ 412 302 _obstack_newchunk (__o, __len + 1); \ 413 _obstack_memcpy (__o->next_free, (where), __len);\303 memcpy (__o->next_free, where, __len); \ 414 304 __o->next_free += __len; \ 415 305 *(__o->next_free)++ = 0; \ … … 421 311 if (__o->next_free + 1 > __o->chunk_limit) \ 422 312 _obstack_newchunk (__o, 1); \ 423 *(__o->next_free)++ = (datum); \424 (void) 0; }) 425 426 /* These assume that the obstack alignment is good enough for pointers or ints,427 and that the data added so far to the current object313 obstack_1grow_fast (__o, datum); \ 314 (void) 0; }) 315 316 /* These assume that the obstack alignment is good enough for pointers 317 or ints, and that the data added so far to the current object 428 318 shares that much alignment. */ 429 319 … … 433 323 if (__o->next_free + sizeof (void *) > __o->chunk_limit) \ 434 324 _obstack_newchunk (__o, sizeof (void *)); \ 435 *((void **)__o->next_free)++ = ((void *)datum); \ 436 (void) 0; }) 325 obstack_ptr_grow_fast (__o, datum); }) \ 437 326 438 327 # define obstack_int_grow(OBSTACK,datum) \ … … 441 330 if (__o->next_free + sizeof (int) > __o->chunk_limit) \ 442 331 _obstack_newchunk (__o, sizeof (int)); \ 443 *((int *)__o->next_free)++ = ((int)datum); \ 444 (void) 0; }) 445 446 # define obstack_ptr_grow_fast(h,aptr) (*((void **) (h)->next_free)++ = (void *)aptr) 447 # define obstack_int_grow_fast(h,aint) (*((int *) (h)->next_free)++ = (int) aint) 332 obstack_int_grow_fast (__o, datum); }) 333 334 # define obstack_ptr_grow_fast(OBSTACK,aptr) \ 335 __extension__ \ 336 ({ struct obstack *__o1 = (OBSTACK); \ 337 *(const void **) __o1->next_free = (aptr); \ 338 __o1->next_free += sizeof (const void *); \ 339 (void) 0; }) 340 341 # define obstack_int_grow_fast(OBSTACK,aint) \ 342 __extension__ \ 343 ({ struct obstack *__o1 = (OBSTACK); \ 344 *(int *) __o1->next_free = (aint); \ 345 __o1->next_free += sizeof (int); \ 346 (void) 0; }) 448 347 449 348 # define obstack_blank(OBSTACK,length) \ … … 453 352 if (__o->chunk_limit - __o->next_free < __len) \ 454 353 _obstack_newchunk (__o, __len); \ 455 __o->next_free += __len;\354 obstack_blank_fast (__o, __len); \ 456 355 (void) 0; }) 457 356 … … 476 375 /* The local variable is named __o1 to avoid a name conflict 477 376 when obstack_blank is called. */ 478 # define obstack_finish(OBSTACK) 377 # define obstack_finish(OBSTACK) \ 479 378 __extension__ \ 480 379 ({ struct obstack *__o1 = (OBSTACK); \ 481 void *value; \ 482 value = (void *) __o1->object_base; \ 483 if (__o1->next_free == value) \ 380 void *__value = (void *) __o1->object_base; \ 381 if (__o1->next_free == __value) \ 484 382 __o1->maybe_empty_object = 1; \ 485 383 __o1->next_free \ … … 490 388 __o1->next_free = __o1->chunk_limit; \ 491 389 __o1->object_base = __o1->next_free; \ 492 value; })390 __value; }) 493 391 494 392 # define obstack_free(OBSTACK, OBJ) \ … … 497 395 void *__obj = (OBJ); \ 498 396 if (__obj > (void *)__o->chunk && __obj < (void *)__o->chunk_limit) \ 499 __o->next_free = __o->object_base = __obj;\397 __o->next_free = __o->object_base = (char *)__obj; \ 500 398 else (obstack_free) (__o, __obj); }) 501 399 … … 527 425 (((h)->next_free + (h)->temp > (h)->chunk_limit) \ 528 426 ? (_obstack_newchunk ((h), (h)->temp), 0) : 0), \ 529 _obstack_memcpy ((h)->next_free, (where), (h)->temp),\427 memcpy ((h)->next_free, where, (h)->temp), \ 530 428 (h)->next_free += (h)->temp) 531 429 … … 534 432 (((h)->next_free + (h)->temp + 1 > (h)->chunk_limit) \ 535 433 ? (_obstack_newchunk ((h), (h)->temp + 1), 0) : 0), \ 536 _obstack_memcpy ((h)->next_free, (where), (h)->temp),\434 memcpy ((h)->next_free, where, (h)->temp), \ 537 435 (h)->next_free += (h)->temp, \ 538 436 *((h)->next_free)++ = 0) … … 541 439 ( (((h)->next_free + 1 > (h)->chunk_limit) \ 542 440 ? (_obstack_newchunk ((h), 1), 0) : 0), \ 543 (*((h)->next_free)++ = (datum)))441 obstack_1grow_fast (h, datum)) 544 442 545 443 # define obstack_ptr_grow(h,datum) \ 546 444 ( (((h)->next_free + sizeof (char *) > (h)->chunk_limit) \ 547 445 ? (_obstack_newchunk ((h), sizeof (char *)), 0) : 0), \ 548 (*((char **) (((h)->next_free+=sizeof(char *))-sizeof(char *))) = ((char *) datum)))446 obstack_ptr_grow_fast (h, datum)) 549 447 550 448 # define obstack_int_grow(h,datum) \ 551 449 ( (((h)->next_free + sizeof (int) > (h)->chunk_limit) \ 552 450 ? (_obstack_newchunk ((h), sizeof (int)), 0) : 0), \ 553 (*((int *) (((h)->next_free+=sizeof(int))-sizeof(int))) = ((int) datum))) 554 555 # define obstack_ptr_grow_fast(h,aptr) (*((char **) (h)->next_free)++ = (char *) aptr) 556 # define obstack_int_grow_fast(h,aint) (*((int *) (h)->next_free)++ = (int) aint) 451 obstack_int_grow_fast (h, datum)) 452 453 # define obstack_ptr_grow_fast(h,aptr) \ 454 (((const void **) ((h)->next_free += sizeof (void *)))[-1] = (aptr)) 455 456 # define obstack_int_grow_fast(h,aint) \ 457 (((int *) ((h)->next_free += sizeof (int)))[-1] = (aptr)) 557 458 558 459 # define obstack_blank(h,length) \ … … 560 461 (((h)->chunk_limit - (h)->next_free < (h)->temp) \ 561 462 ? (_obstack_newchunk ((h), (h)->temp), 0) : 0), \ 562 ((h)->next_free +=(h)->temp))463 obstack_blank_fast (h, (h)->temp)) 563 464 564 465 # define obstack_alloc(h,length) \ … … 571 472 (obstack_grow0 ((h), (where), (length)), obstack_finish ((h))) 572 473 573 # define obstack_finish(h) 474 # define obstack_finish(h) \ 574 475 ( ((h)->next_free == (h)->object_base \ 575 476 ? (((h)->maybe_empty_object = 1), 0) \ … … 583 484 ? ((h)->next_free = (h)->chunk_limit) : 0), \ 584 485 (h)->object_base = (h)->next_free, \ 585 __INT_TO_PTR ((h)->temp)) 586 587 # if defined __STDC__ && __STDC__ 588 # define obstack_free(h,obj) \ 486 (void *) __INT_TO_PTR ((h)->temp)) 487 488 # define obstack_free(h,obj) \ 589 489 ( (h)->temp = (char *) (obj) - (char *) (h)->chunk, \ 590 490 (((h)->temp > 0 && (h)->temp < (h)->chunk_limit - (char *) (h)->chunk)\ … … 592 492 = (h)->temp + (char *) (h)->chunk) \ 593 493 : (((obstack_free) ((h), (h)->temp + (char *) (h)->chunk), 0), 0))) 594 # else595 # define obstack_free(h,obj) \596 ( (h)->temp = (char *) (obj) - (char *) (h)->chunk, \597 (((h)->temp > 0 && (h)->temp < (h)->chunk_limit - (char *) (h)->chunk)\598 ? (int) ((h)->next_free = (h)->object_base \599 = (h)->temp + (char *) (h)->chunk) \600 : (_obstack_free ((h), (h)->temp + (char *) (h)->chunk), 0)))601 # endif602 494 603 495 #endif /* not __GNUC__ or not __STDC__ */ -
Property cvs2svn:cvs-rev
changed from
Note:
See TracChangeset
for help on using the changeset viewer.