GCC Wikia
Advertisement

このページを編集する際は,編集に関する方針に従ってください.[]

概要[]

引数[]

  • struct obstack *h
  • int size
  • int alignment
  • POINTER (*chunkfun) (long)
    • なぜPTRをつかわないのだろう?
  • void (*freefun) (void *)

実装[]

141: int
142: _obstack_begin (struct obstack *h, int size, int alignment,
143:                 POINTER (*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;
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 - 1) & ~(DEFAULT_ROUNDING - 1))
161:                     + 4 + DEFAULT_ROUNDING - 1)
162:                    & ~(DEFAULT_ROUNDING - 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);
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: }



リンク元

Advertisement