Annotation of researchv10dc/cmd/gcc/obstack.c, revision 1.1

1.1     ! root        1: /* obstack.c - subroutines used implicitly by object stack macros
        !             2:    Copyright (C) 1988 Free Software Foundation, Inc.
        !             3: 
        !             4:                       NO WARRANTY
        !             5: 
        !             6:   BECAUSE THIS PROGRAM IS LICENSED FREE OF CHARGE, WE PROVIDE ABSOLUTELY
        !             7: NO WARRANTY, TO THE EXTENT PERMITTED BY APPLICABLE STATE LAW.  EXCEPT
        !             8: WHEN OTHERWISE STATED IN WRITING, FREE SOFTWARE FOUNDATION, INC,
        !             9: RICHARD M. STALLMAN AND/OR OTHER PARTIES PROVIDE THIS PROGRAM "AS IS"
        !            10: WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING,
        !            11: BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
        !            12: FITNESS FOR A PARTICULAR PURPOSE.  THE ENTIRE RISK AS TO THE QUALITY
        !            13: AND PERFORMANCE OF THE PROGRAM IS WITH YOU.  SHOULD THE PROGRAM PROVE
        !            14: DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING, REPAIR OR
        !            15: CORRECTION.
        !            16: 
        !            17:  IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW WILL RICHARD M.
        !            18: STALLMAN, THE FREE SOFTWARE FOUNDATION, INC., AND/OR ANY OTHER PARTY
        !            19: WHO MAY MODIFY AND REDISTRIBUTE THIS PROGRAM AS PERMITTED BELOW, BE
        !            20: LIABLE TO YOU FOR DAMAGES, INCLUDING ANY LOST PROFITS, LOST MONIES, OR
        !            21: OTHER SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE
        !            22: USE OR INABILITY TO USE (INCLUDING BUT NOT LIMITED TO LOSS OF DATA OR
        !            23: DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY THIRD PARTIES OR
        !            24: A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS) THIS
        !            25: PROGRAM, EVEN IF YOU HAVE BEEN ADVISED OF THE POSSIBILITY OF SUCH
        !            26: DAMAGES, OR FOR ANY CLAIM BY ANY OTHER PARTY.
        !            27: 
        !            28:                GENERAL PUBLIC LICENSE TO COPY
        !            29: 
        !            30:   1. You may copy and distribute verbatim copies of this source file
        !            31: as you receive it, in any medium, provided that you conspicuously and
        !            32: appropriately publish on each copy a valid copyright notice "Copyright
        !            33:  (C) 1988 Free Software Foundation, Inc."; and include following the
        !            34: copyright notice a verbatim copy of the above disclaimer of warranty
        !            35: and of this License.  You may charge a distribution fee for the
        !            36: physical act of transferring a copy.
        !            37: 
        !            38:   2. You may modify your copy or copies of this source file or
        !            39: any portion of it, and copy and distribute such modifications under
        !            40: the terms of Paragraph 1 above, provided that you also do the following:
        !            41: 
        !            42:     a) cause the modified files to carry prominent notices stating
        !            43:     that you changed the files and the date of any change; and
        !            44: 
        !            45:     b) cause the whole of any work that you distribute or publish,
        !            46:     that in whole or in part contains or is a derivative of this
        !            47:     program or any part thereof, to be licensed at no charge to all
        !            48:     third parties on terms identical to those contained in this
        !            49:     License Agreement (except that you may choose to grant more extensive
        !            50:     warranty protection to some or all third parties, at your option).
        !            51: 
        !            52:     c) You may charge a distribution fee for the physical act of
        !            53:     transferring a copy, and you may at your option offer warranty
        !            54:     protection in exchange for a fee.
        !            55: 
        !            56: Mere aggregation of another unrelated program with this program (or its
        !            57: derivative) on a volume of a storage or distribution medium does not bring
        !            58: the other program under the scope of these terms.
        !            59: 
        !            60:   3. You may copy and distribute this program or any portion of it in
        !            61: compiled, executable or object code form under the terms of Paragraphs
        !            62: 1 and 2 above provided that you do the following:
        !            63: 
        !            64:     a) accompany it with the complete corresponding machine-readable
        !            65:     source code, which must be distributed under the terms of
        !            66:     Paragraphs 1 and 2 above; or,
        !            67: 
        !            68:     b) accompany it with a written offer, valid for at least three
        !            69:     years, to give any third party free (except for a nominal
        !            70:     shipping charge) a complete machine-readable copy of the
        !            71:     corresponding source code, to be distributed under the terms of
        !            72:     Paragraphs 1 and 2 above; or,
        !            73: 
        !            74:     c) accompany it with the information you received as to where the
        !            75:     corresponding source code may be obtained.  (This alternative is
        !            76:     allowed only for noncommercial distribution and only if you
        !            77:     received the program in object code or executable form alone.)
        !            78: 
        !            79: For an executable file, complete source code means all the source code for
        !            80: all modules it contains; but, as a special exception, it need not include
        !            81: source code for modules which are standard libraries that accompany the
        !            82: operating system on which the executable file runs.
        !            83: 
        !            84:   4. You may not copy, sublicense, distribute or transfer this program
        !            85: except as expressly provided under this License Agreement.  Any attempt
        !            86: otherwise to copy, sublicense, distribute or transfer this program is void and
        !            87: your rights to use the program under this License agreement shall be
        !            88: automatically terminated.  However, parties who have received computer
        !            89: software programs from you with this License Agreement will not have
        !            90: their licenses terminated so long as such parties remain in full compliance.
        !            91: 
        !            92:   5. If you wish to incorporate parts of this program into other free
        !            93: programs whose distribution conditions are different, write to the Free
        !            94: Software Foundation at 675 Mass Ave, Cambridge, MA 02139.  We have not yet
        !            95: worked out a simple rule that can be stated here, but we will often permit
        !            96: this.  We will be guided by the two goals of preserving the free status of
        !            97: all derivatives our free software and of promoting the sharing and reuse of
        !            98: software.
        !            99: 
        !           100: 
        !           101: In other words, you are welcome to use, share and improve this program.
        !           102: You are forbidden to forbid anyone else to use, share and improve
        !           103: what you give them.   Help stamp out software-hoarding!  */
        !           104: 
        !           105: 
        !           106: #include "obstack.h"
        !           107: 
        !           108: #ifdef __STDC__
        !           109: #define POINTER void *
        !           110: #else
        !           111: #define POINTER char *
        !           112: #endif
        !           113: 
        !           114: /* Determine default alignment.  */
        !           115: struct fooalign {char x; double d;};
        !           116: #define DEFAULT_ALIGNMENT ((int) &(((struct fooalign *) 0)->d))
        !           117: 
        !           118: /* The non-GNU-C macros copy the obstack into this global variable
        !           119:    to avoid multiple evaluation.  */
        !           120: 
        !           121: struct obstack *_obstack;
        !           122: 
        !           123: /* Initialize an obstack H for use.  Specify chunk size SIZE.
        !           124:    Objects start on multiples of ALIGNMENT (0 means use default).
        !           125:    CHUNKFUN is the function to use to allocate chunks,
        !           126:    and FREEFUN the function to free them.  */
        !           127: 
        !           128: void
        !           129: _obstack_begin (h, size, alignment, chunkfun, freefun)
        !           130:      struct obstack *h;
        !           131:      int size;
        !           132:      int alignment;
        !           133:      POINTER (*chunkfun) ();
        !           134:      void (*freefun) ();
        !           135: {
        !           136:   register struct _obstack_chunk* chunk; /* points to new chunk */
        !           137: 
        !           138:   if (alignment == 0)
        !           139:     alignment = DEFAULT_ALIGNMENT;
        !           140: 
        !           141:   h->chunkfun = (struct _obstack_chunk * (*)()) chunkfun;
        !           142:   h->freefun = freefun;
        !           143:   h->chunk_size = size;
        !           144:   h->alignment_mask = alignment - 1;
        !           145: 
        !           146:   chunk        = h->chunk = (*h->chunkfun) (h->chunk_size);
        !           147:   h->next_free = h->object_base = chunk->contents;
        !           148:   h->chunk_limit = chunk->limit
        !           149:    = (char *) chunk + h->chunk_size;
        !           150:   chunk->prev = 0;
        !           151: }
        !           152: 
        !           153: /* Allocate a new current chunk for the obstack *H
        !           154:    on the assumption that LENGTH bytes need to be added
        !           155:    to the current object, or a new object of length LENGTH allocated.
        !           156:    Copies any partial object from the end of the old chunk
        !           157:    to the beginning of the new one.  */
        !           158: 
        !           159: void
        !           160: _obstack_newchunk (h, length)
        !           161:      struct obstack *h;
        !           162:      int length;
        !           163: {
        !           164:   register struct _obstack_chunk*      old_chunk = h->chunk;
        !           165:   register struct _obstack_chunk*      new_chunk;
        !           166:   register long        new_size;
        !           167:   register int obj_size = h->next_free - h->object_base;
        !           168:   register int i;
        !           169: 
        !           170:   /* Compute size for new chunk.  */
        !           171:   new_size = (obj_size + length) << 1;
        !           172:   if (new_size < h->chunk_size)
        !           173:     new_size = h->chunk_size;
        !           174: 
        !           175:   /* Allocate and initialize the new chunk.  */
        !           176:   new_chunk = h->chunk = (*h->chunkfun) (new_size);
        !           177:   new_chunk->prev = old_chunk;
        !           178:   new_chunk->limit = h->chunk_limit = (char *) new_chunk + new_size;
        !           179: 
        !           180:   /* Move the existing object to the new chunk.
        !           181:      Word at a time is fast and is safe because these
        !           182:      structures are aligned at least that much.  */
        !           183:   for (i = (obj_size + sizeof (int) - 1) / sizeof (int) - 1; i >= 0; i--)
        !           184:     ((int *)new_chunk->contents)[i] = ((int *)h->object_base)[i];
        !           185: 
        !           186:   h->object_base = new_chunk->contents;
        !           187:   h->next_free = h->object_base + obj_size;
        !           188: }
        !           189: 
        !           190: /* Free objects in obstack H, including OBJ and everything allocate
        !           191:    more recently than OBJ.  If OBJ is zero, free everything in H.  */
        !           192: 
        !           193: void
        !           194: #ifdef __STDC__
        !           195: #undef obstack_free
        !           196: obstack_free (h, obj)
        !           197: 
        !           198: #else
        !           199: _obstack_free (h, obj)
        !           200: #endif
        !           201:      struct obstack *h;
        !           202:      POINTER obj;
        !           203: {
        !           204:   register struct _obstack_chunk*  lp; /* below addr of any objects in this chunk */
        !           205:   register struct _obstack_chunk*  plp;        /* point to previous chunk if any */
        !           206: 
        !           207:   lp = (h)->chunk;
        !           208:   while (lp != 0 && ((POINTER)lp > obj || (POINTER)(lp)->limit < obj))
        !           209:     {
        !           210:       plp = lp -> prev;
        !           211:       (*h->freefun) (lp);
        !           212:       lp = plp;
        !           213:     }
        !           214:   if (lp)
        !           215:     {
        !           216:       (h)->object_base = (h)->next_free = (char *)(obj);
        !           217:       (h)->chunk_limit = lp->limit;
        !           218:       (h)->chunk = lp;
        !           219:     }
        !           220:   else if (obj != 0)
        !           221:     /* obj is not in any of the chunks! */
        !           222:     abort ();
        !           223: }
        !           224: 
        !           225: #if 0
        !           226: /* These are now turned off because the applications do not use it
        !           227:    and it uses bcopy via obstack_grow, which causes trouble on sysV.  */
        !           228: 
        !           229: /* Now define the functional versions of the obstack macros.
        !           230:    Define them to simply use the corresponding macros to do the job.  */
        !           231: 
        !           232: #ifdef __STDC__
        !           233: /* These function definitions do not work with non-ANSI preprocessors;
        !           234:    they won't pass through the macro names in parentheses.  */
        !           235: 
        !           236: /* The function names appear in parentheses in order to prevent
        !           237:    the macro-definitions of the names from being expanded there.  */
        !           238: 
        !           239: POINTER (obstack_base) (obstack)
        !           240:      struct obstack *obstack;
        !           241: {
        !           242:   return obstack_base (obstack);
        !           243: }
        !           244: 
        !           245: POINTER (obstack_next_free) (obstack)
        !           246:      struct obstack *obstack;
        !           247: {
        !           248:   return obstack_next_free (obstack);
        !           249: }
        !           250: 
        !           251: int (obstack_object_size) (obstack)
        !           252:      struct obstack *obstack;
        !           253: {
        !           254:   return obstack_object_size (obstack);
        !           255: }
        !           256: 
        !           257: int (obstack_room) (obstack)
        !           258:      struct obstack *obstack;
        !           259: {
        !           260:   return obstack_room (obstack);
        !           261: }
        !           262: 
        !           263: void (obstack_grow) (obstack, pointer, length)
        !           264:      struct obstack *obstack;
        !           265:      POINTER pointer;
        !           266:      int length;
        !           267: {
        !           268:   obstack_grow (obstack, pointer, length);
        !           269: }
        !           270: 
        !           271: void (obstack_grow0) (obstack, pointer, length)
        !           272:      struct obstack *obstack;
        !           273:      POINTER pointer;
        !           274:      int length;
        !           275: {
        !           276:   obstack_grow0 (obstack, pointer, length);
        !           277: }
        !           278: 
        !           279: void (obstack_1grow) (obstack, character)
        !           280:      struct obstack *obstack;
        !           281:      int character;
        !           282: {
        !           283:   obstack_1grow (obstack, character);
        !           284: }
        !           285: 
        !           286: void (obstack_blank) (obstack, length)
        !           287:      struct obstack *obstack;
        !           288:      int length;
        !           289: {
        !           290:   obstack_blank (obstack, length);
        !           291: }
        !           292: 
        !           293: void (obstack_1grow_fast) (obstack, character)
        !           294:      struct obstack *obstack;
        !           295:      int character;
        !           296: {
        !           297:   obstack_1grow_fast (obstack, character);
        !           298: }
        !           299: 
        !           300: void (obstack_blank_fast) (obstack, length)
        !           301:      struct obstack *obstack;
        !           302:      int length;
        !           303: {
        !           304:   obstack_blank_fast (obstack, length);
        !           305: }
        !           306: 
        !           307: POINTER (obstack_finish) (obstack)
        !           308:      struct obstack *obstack;
        !           309: {
        !           310:   return obstack_finish (obstack);
        !           311: }
        !           312: 
        !           313: POINTER (obstack_alloc) (obstack, length)
        !           314:      struct obstack *obstack;
        !           315:      int length;
        !           316: {
        !           317:   return obstack_alloc (obstack, length);
        !           318: }
        !           319: 
        !           320: POINTER (obstack_copy) (obstack, pointer, length)
        !           321:      struct obstack *obstack;
        !           322:      POINTER pointer;
        !           323:      int length;
        !           324: {
        !           325:   return obstack_copy (obstack, pointer, length);
        !           326: }
        !           327: 
        !           328: POINTER (obstack_copy0) (obstack, pointer, length)
        !           329:      struct obstack *obstack;
        !           330:      POINTER pointer;
        !           331:      int length;
        !           332: {
        !           333:   return obstack_copy0 (obstack, pointer, length);
        !           334: }
        !           335: 
        !           336: #endif /* __STDC__ */
        !           337: 
        !           338: #endif /* 0 */

unix.superglobalmegacorp.com

This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.