diff options
author | Tristan Gingold <gingold@adacore.com> | 2011-07-25 13:34:40 +0000 |
---|---|---|
committer | Tristan Gingold <gingold@adacore.com> | 2011-07-25 13:34:40 +0000 |
commit | 179809c050ff97d2f72bab90b8b6fdc7f95eb0b7 (patch) | |
tree | bf93782fed4a5994e50d5befaa2c1e48435015d4 /gas | |
parent | d9b3f62eb21e18fca7e009d440ca16cefbce6cd6 (diff) | |
download | gdb-179809c050ff97d2f72bab90b8b6fdc7f95eb0b7.zip gdb-179809c050ff97d2f72bab90b8b6fdc7f95eb0b7.tar.gz gdb-179809c050ff97d2f72bab90b8b6fdc7f95eb0b7.tar.bz2 |
2011-07-25 Tristan Gingold <gingold@adacore.com>
* frags.c (frag_grow): Simplify the code.
Diffstat (limited to 'gas')
-rw-r--r-- | gas/ChangeLog | 4 | ||||
-rw-r--r-- | gas/frags.c | 46 |
2 files changed, 30 insertions, 20 deletions
diff --git a/gas/ChangeLog b/gas/ChangeLog index fd5769e..eab1325 100644 --- a/gas/ChangeLog +++ b/gas/ChangeLog @@ -1,3 +1,7 @@ +2011-07-25 Tristan Gingold <gingold@adacore.com> + + * frags.c (frag_grow): Simplify the code. + 2011-07-24 Maciej W. Rozycki <macro@codesourcery.com> Chao-ying Fu <fu@mips.com> Richard Sandiford <rdsandiford@googlemail.com> diff --git a/gas/frags.c b/gas/frags.c index fe3b4cc..a0a0a29 100644 --- a/gas/frags.c +++ b/gas/frags.c @@ -75,41 +75,47 @@ frag_alloc (struct obstack *ob) return ptr; } -/* Try to augment current frag by nchars chars. +/* 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. */ + and begin a new frag. Do not set up any fields of *now_frag. */ void frag_grow (unsigned int nchars) { if (obstack_room (&frchain_now->frch_obstack) < nchars) { - unsigned int n; long oldc; + long newc; + /* Not enough room in this frag. Close it. */ 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. */ + for extremely big (like 2GB initialized) frags. */ if (nchars < 0x10000) - frchain_now->frch_obstack.chunk_size = 2 * nchars; + newc = 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; + newc = nchars + 0x10000; + newc += SIZEOF_STRUCT_FRAG; + + if (newc > 0) + { + /* Force to allocate at least NEWC bytes. */ + oldc = obstack_chunk_size (&frchain_now->frch_obstack); + obstack_chunk_size (&frchain_now->frch_obstack) = newc; + + /* Do the real work: create a new frag. */ + frag_new (0); + + /* Restore the old chunk size. */ + obstack_chunk_size (&frchain_now->frch_obstack) = oldc; + } + + /* Check for success (also handles negative values of NEWC). */ + if (obstack_room (&frchain_now->frch_obstack) < nchars) + as_fatal (_("can't extend frag %u chars"), nchars); } - if (obstack_room (&frchain_now->frch_obstack) < nchars) - as_fatal (_("can't extend frag %u chars"), nchars); } /* Call this to close off a completed frag, and start up a new (empty) |