don't shrink in array_allocate
This commit is contained in:
parent
e1e80badf0
commit
12caccfd48
@ -56,25 +56,28 @@ void* array_allocate(array* x,uint64 membersize,int64 pos) {
|
|||||||
/* second case of overflow: pos*membersize too large */
|
/* second case of overflow: pos*membersize too large */
|
||||||
if (__unlikely(!umult64(membersize,pos+1,&wanted))) return 0;
|
if (__unlikely(!umult64(membersize,pos+1,&wanted))) return 0;
|
||||||
|
|
||||||
if (__unlikely(wanted >= (uint64)x->allocated)) {
|
if (wanted > (uint64)x->initialized) {
|
||||||
/* round up a little */
|
if (__unlikely(wanted >= (uint64)x->allocated)) {
|
||||||
if (membersize<8)
|
/* round up a little */
|
||||||
wanted=(wanted+127)&(-128ll); /* round up to multiple of 128 */
|
if (membersize<8)
|
||||||
else
|
wanted=(wanted+127)&(-128ll); /* round up to multiple of 128 */
|
||||||
wanted=(wanted+4095)&(-4096ll); /* round up to 4k pages */
|
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))
|
if (sizeof(size_t) != sizeof(int64) && __unlikely((size_t)(wanted) != wanted))
|
||||||
return 0;
|
return 0;
|
||||||
{
|
{
|
||||||
char* tmp=realloc(x->p,wanted);
|
char* tmp=realloc(x->p,wanted);
|
||||||
if (__unlikely(!tmp)) return 0;
|
if (__unlikely(!tmp)) return 0;
|
||||||
x->p=tmp;
|
x->p=tmp;
|
||||||
|
}
|
||||||
|
x->allocated=wanted;
|
||||||
|
byte_zero(x->p+x->initialized,x->allocated-x->initialized);
|
||||||
}
|
}
|
||||||
x->allocated=wanted;
|
x->initialized=(pos+1)*membersize;
|
||||||
byte_zero(x->p+x->initialized,x->allocated-x->initialized);
|
|
||||||
}
|
}
|
||||||
x->initialized=(pos+1)*membersize;
|
|
||||||
return x->p+pos*membersize;
|
return x->p+pos*membersize;
|
||||||
}
|
}
|
||||||
|
@ -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;
|
if ((n=kevent(io_master,0,0,y,100,milliseconds!=-1?&ts:0))==-1) return -1;
|
||||||
for (i=n-1; i>=0; --i) {
|
for (i=n-1; i>=0; --i) {
|
||||||
io_entry* e=array_get(&io_fds,sizeof(io_entry),y[--n].ident);
|
io_entry* e=array_get(&io_fds,sizeof(io_entry),y[--n].ident);
|
||||||
|
#ifdef DEBUG
|
||||||
|
if (!e) {
|
||||||
|
e=e;
|
||||||
|
}
|
||||||
|
#endif
|
||||||
if (e) {
|
if (e) {
|
||||||
if (y[n].flags&EV_ERROR) {
|
if (y[n].flags&EV_ERROR) {
|
||||||
/* error; signal whatever app is looking for */
|
/* error; signal whatever app is looking for */
|
||||||
|
Loading…
x
Reference in New Issue
Block a user