From 12caccfd48ca99b05be32a42843e2ad68a66a67f Mon Sep 17 00:00:00 2001 From: leitner Date: Wed, 24 Aug 2005 17:30:40 +0000 Subject: [PATCH] don't shrink in array_allocate --- array/array_allocate.c | 35 +++++++++++++++++++---------------- io/io_waituntil2.c | 5 +++++ 2 files changed, 24 insertions(+), 16 deletions(-) diff --git a/array/array_allocate.c b/array/array_allocate.c index b76f223..681b6d4 100644 --- a/array/array_allocate.c +++ b/array/array_allocate.c @@ -56,25 +56,28 @@ void* array_allocate(array* x,uint64 membersize,int64 pos) { /* second case of overflow: pos*membersize too large */ if (__unlikely(!umult64(membersize,pos+1,&wanted))) return 0; - if (__unlikely(wanted >= (uint64)x->allocated)) { - /* round up a little */ - if (membersize<8) - wanted=(wanted+127)&(-128ll); /* round up to multiple of 128 */ - else - wanted=(wanted+4095)&(-4096ll); /* round up to 4k pages */ + if (wanted > (uint64)x->initialized) { + if (__unlikely(wanted >= (uint64)x->allocated)) { + /* round up a little */ + if (membersize<8) + wanted=(wanted+127)&(-128ll); /* round up to multiple of 128 */ + else + wanted=(wanted+4095)&(-4096ll); /* round up to 4k pages */ - if (__unlikely(wanted<128)) return 0; /* overflow during rounding */ + if (__unlikely(wanted<128)) return 0; /* overflow during rounding */ - if (sizeof(size_t) != sizeof(int64) && __unlikely((size_t)(wanted) != wanted)) - return 0; - { - char* tmp=realloc(x->p,wanted); - if (__unlikely(!tmp)) return 0; - x->p=tmp; + if (sizeof(size_t) != sizeof(int64) && __unlikely((size_t)(wanted) != wanted)) + return 0; + { + char* tmp=realloc(x->p,wanted); + if (__unlikely(!tmp)) return 0; + x->p=tmp; + } + x->allocated=wanted; + byte_zero(x->p+x->initialized,x->allocated-x->initialized); } - x->allocated=wanted; - byte_zero(x->p+x->initialized,x->allocated-x->initialized); + x->initialized=(pos+1)*membersize; } - x->initialized=(pos+1)*membersize; + return x->p+pos*membersize; } diff --git a/io/io_waituntil2.c b/io/io_waituntil2.c index 5af8585..764b9ff 100644 --- a/io/io_waituntil2.c +++ b/io/io_waituntil2.c @@ -75,6 +75,11 @@ int64 io_waituntil2(int64 milliseconds) { if ((n=kevent(io_master,0,0,y,100,milliseconds!=-1?&ts:0))==-1) return -1; for (i=n-1; i>=0; --i) { io_entry* e=array_get(&io_fds,sizeof(io_entry),y[--n].ident); +#ifdef DEBUG + if (!e) { + e=e; + } +#endif if (e) { if (y[n].flags&EV_ERROR) { /* error; signal whatever app is looking for */