/* * frag_grow() * * Try to augment current frag by nchars chars. * If there is no room, close of the current frag with a ".fill 0" * and begin a new frag. Unless the new frag has nchars chars available * do not return. Do not set up any fields of *now_frag. */ void frag_grow( unsigned int nchars) { if(frags.chunk_size == 0) { know(flagseen['n']); as_fatal("with -n a section directive must be seen before assembly " "can begin"); } if ((int)(obstack_room(&frags)) < nchars) { unsigned int n,oldn; long oldc; frag_wane (frag_now); frag_new (0); oldn=(unsigned)-1; oldc=frags.chunk_size; frags.chunk_size=2*nchars; while((int)(n=obstack_room(&frags)) < nchars && n < oldn) { frag_wane(frag_now); frag_new(0); oldn=n; } frags.chunk_size=oldc; } if ((int)(obstack_room(&frags)) < nchars) as_fatal ("Can't extend frag %d. chars", nchars); }
void frag_grow (unsigned int nchars) { if (obstack_room (&frchain_now->frch_obstack) < nchars) { unsigned int n; long oldc; frag_wane (frag_now); frag_new (0); oldc = frchain_now->frch_obstack.chunk_size; /* Try to allocate a bit more than needed right now. But don't do this if we would waste too much memory. Especially necessary for extremely big (like 2GB initialized) frags. */ if (nchars < 0x10000) frchain_now->frch_obstack.chunk_size = 2 * nchars; else frchain_now->frch_obstack.chunk_size = nchars + 0x10000; frchain_now->frch_obstack.chunk_size += SIZEOF_STRUCT_FRAG; if (frchain_now->frch_obstack.chunk_size > 0) while ((n = obstack_room (&frchain_now->frch_obstack)) < nchars && (unsigned long) frchain_now->frch_obstack.chunk_size > nchars) { frag_wane (frag_now); frag_new (0); } frchain_now->frch_obstack.chunk_size = oldc; } if (obstack_room (&frchain_now->frch_obstack) < nchars) as_fatal (_("can't extend frag %u chars"), nchars); }
int _IO_obstack_vprintf (struct obstack *obstack, const char *format, va_list args) { struct obstack_FILE { struct _IO_obstack_file ofile; } new_f; int result; int size; int room; #ifdef _IO_MTSAFE_IO new_f.ofile.file.file._lock = NULL; #endif _IO_no_init (&new_f.ofile.file.file, _IO_USER_LOCK, -1, NULL, NULL); _IO_JUMPS (&new_f.ofile.file) = &_IO_obstack_jumps; room = obstack_room (obstack); size = obstack_object_size (obstack) + room; if (size == 0) { /* We have to handle the allocation a bit different since the `_IO_str_init_static' function would handle a size of zero different from what we expect. */ /* Get more memory. */ obstack_make_room (obstack, 64); /* Recompute how much room we have. */ room = obstack_room (obstack); size = room; assert (size != 0); } _IO_str_init_static_internal ((struct _IO_strfile_ *) &new_f.ofile, obstack_base (obstack), size, obstack_next_free (obstack)); /* Now allocate the rest of the current chunk. */ assert (size == (new_f.ofile.file.file._IO_write_end - new_f.ofile.file.file._IO_write_base)); assert (new_f.ofile.file.file._IO_write_ptr == (new_f.ofile.file.file._IO_write_base + obstack_object_size (obstack))); obstack_blank_fast (obstack, room); new_f.ofile.obstack = obstack; result = _IO_vfprintf (&new_f.ofile.file.file, format, args); /* Shrink the buffer to the space we really currently need. */ obstack_blank_fast (obstack, (new_f.ofile.file.file._IO_write_ptr - new_f.ofile.file.file._IO_write_end)); return result; }
static _IO_size_t _IO_obstack_xsputn (_IO_FILE *fp, const void *data, _IO_size_t n) { struct obstack *obstack = ((struct _IO_obstack_file *) fp)->obstack; if (fp->_IO_write_ptr + n > fp->_IO_write_end) { int size; /* We need some more memory. First shrink the buffer to the space we really currently need. */ obstack_blank_fast (obstack, fp->_IO_write_ptr - fp->_IO_write_end); /* Now grow for N bytes, and put the data there. */ obstack_grow (obstack, data, n); /* Setup the buffer pointers again. */ fp->_IO_write_base = obstack_base (obstack); fp->_IO_write_ptr = obstack_next_free (obstack); size = obstack_room (obstack); fp->_IO_write_end = fp->_IO_write_ptr + size; /* Now allocate the rest of the current chunk. */ obstack_blank_fast (obstack, size); } else fp->_IO_write_ptr = __mempcpy (fp->_IO_write_ptr, data, n); return n; }
void runSuccess() { struct obstack o; obstack_init(&o); if (obstack_room(&o) >= sizeof(char)) { obstack_1grow_fast(&o, anyint()); } }
void frag_append_1_char (int datum) { frag_alloc_check (&frchain_now->frch_obstack); if (obstack_room (&frchain_now->frch_obstack) <= 1) { frag_wane (frag_now); frag_new (0); } obstack_1grow (&frchain_now->frch_obstack, datum); }
void frag_grow (unsigned int nchars) { if (obstack_room (&frchain_now->frch_obstack) < nchars) { long oldc; long newc; /* Try to allocate a bit more than needed right now. But don't do this if we would waste too much memory. Especially necessary for extremely big (like 2GB initialized) frags. */ if (nchars < 0x10000) newc = 2 * nchars; else newc = nchars + 0x10000; newc += SIZEOF_STRUCT_FRAG; /* Check for possible overflow. */ if (newc < 0) as_fatal (_("can't extend frag %u chars"), nchars); /* Force to allocate at least NEWC bytes, but not less than the default. */ oldc = obstack_chunk_size (&frchain_now->frch_obstack); if (newc > oldc) obstack_chunk_size (&frchain_now->frch_obstack) = newc; while (obstack_room (&frchain_now->frch_obstack) < nchars) { /* Not enough room in this frag. Close it and start a new one. This must be done in a loop because the created frag may not be big enough if the current obstack chunk is used. */ frag_wane (frag_now); frag_new (0); } /* Restore the old chunk size. */ obstack_chunk_size (&frchain_now->frch_obstack) = oldc; } }
void testValues() { f = 2; struct obstack o; obstack_init(&o); if (obstack_room(&o) >= sizeof(char)) { obstack_1grow_fast(&o, anyint()); } //@ assert f == 2; //@ assert vacuous: \false; }
static int _IO_obstack_overflow (_IO_FILE *fp, int c) { struct obstack *obstack = ((struct _IO_obstack_file *) fp)->obstack; int size; /* Make room for another character. This might as well allocate a new chunk a memory and moves the old contents over. */ assert (c != EOF); obstack_1grow (obstack, c); /* Setup the buffer pointers again. */ fp->_IO_write_base = obstack_base (obstack); fp->_IO_write_ptr = obstack_next_free (obstack); size = obstack_room (obstack); fp->_IO_write_end = fp->_IO_write_ptr + size; /* Now allocate the rest of the current chunk. */ obstack_blank_fast (obstack, size); return c; }
/* Grow an obstack with formatted output. Return the number of bytes added to OBS. No trailing nul byte is added, and the object should be closed with obstack_finish before use. Upon memory allocation error, call obstack_alloc_failed_handler. Upon other error, return -1. */ int obstack_vprintf (struct obstack *obs, const char *format, va_list args) { /* If we are close to the end of the current obstack chunk, use a stack-allocated buffer and copy, to reduce the likelihood of a small-size malloc. Otherwise, print directly into the obstack. */ enum { CUTOFF = 1024 }; char buf[CUTOFF]; char *base = obstack_next_free (obs); size_t len = obstack_room (obs); char *str; if (len < CUTOFF) { base = buf; len = CUTOFF; } str = vasnprintf (base, &len, format, args); if (!str) { if (errno == ENOMEM) obstack_alloc_failed_handler (); return -1; } if (str == base && str != buf) /* The output was already computed in place, but we need to account for its size. */ obstack_blank_fast (obs, len); else { /* The output exceeded available obstack space or we used buf; copy the resulting string. */ obstack_grow (obs, str, len); if (str != buf) free (str); } return len; }
int frag_room (void) { return obstack_room (&frchain_now->frch_obstack); }