Browse Source

don't shrink in array_allocate

master
Felix von Leitner 16 years ago
parent
commit
e01f09c988
  1. 35
      array/array_allocate.c
  2. 5
      io/io_waituntil2.c

35
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;
}

5
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 */

Loading…
Cancel
Save