diff options
| author | Michael Brown | 2007-01-29 05:12:29 +0100 |
|---|---|---|
| committer | Michael Brown | 2007-01-29 05:12:29 +0100 |
| commit | c42a38470992c70716b683968bc8479df90ad984 (patch) | |
| tree | 43397a190c2c83ec20df5df92e11be6018f8160f /src/core/ebuffer.c | |
| parent | Should be correct for building RSA (diff) | |
| download | ipxe-c42a38470992c70716b683968bc8479df90ad984.tar.gz ipxe-c42a38470992c70716b683968bc8479df90ad984.tar.xz ipxe-c42a38470992c70716b683968bc8479df90ad984.zip | |
Moved most buffer debug messages to DBG2.
Make expand_buffer() a non-inline function, so that we can add debug
messages.
Expandable buffers now don't *always* round up to the next power of two.
This allows e.g. loading a 137MB ISO image on a machine with only 256MB
RAM...
Diffstat (limited to 'src/core/ebuffer.c')
| -rw-r--r-- | src/core/ebuffer.c | 16 |
1 files changed, 12 insertions, 4 deletions
diff --git a/src/core/ebuffer.c b/src/core/ebuffer.c index 16d49a12e..4401a34b9 100644 --- a/src/core/ebuffer.c +++ b/src/core/ebuffer.c @@ -40,13 +40,21 @@ static int ebuffer_expand ( struct buffer *buffer, size_t new_len ) { userptr_t new_addr; /* Round new_len up to the nearest power of two, to reduce - * total number of reallocations required. + * total number of reallocations required. Don't do this for + * the first expansion; this allows for protocols that do + * actually know the exact length in advance. */ - while ( actual_len < new_len ) - actual_len <<= 1; + if ( buffer->len ) { + while ( actual_len < new_len ) + actual_len <<= 1; + } else { + actual_len = new_len; + } /* Reallocate buffer */ - new_addr = urealloc ( buffer->addr, actual_len ); +#warning "urealloc() has issues with length zero" + new_addr = urealloc ( buffer->addr, // actual_len ); + actual_len ? actual_len : 1 ); if ( ! new_addr ) return -ENOMEM; |
