From c42a38470992c70716b683968bc8479df90ad984 Mon Sep 17 00:00:00 2001 From: Michael Brown Date: Mon, 29 Jan 2007 04:12:29 +0000 Subject: 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... --- src/core/ebuffer.c | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) (limited to 'src/core/ebuffer.c') 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; -- cgit v1.2.3-55-g7522