mirror of
https://github.com/dankamongmen/notcurses.git
synced 2024-11-02 09:40:15 +00:00
EGCPool: early realloc failure is not a hard fail
We do proactive reallocations of the EGCPool once we get to 90% capacity, to avoid expensive exhaustive searches. When we're over half the maximum size, though, this will fail. We shouldn't treat that as a hard failure, but instead proceed on to the search. This lets us hit the full 32MB EGCPool size #486.
This commit is contained in:
parent
08e769f989
commit
3ddb1d3166
@ -43,8 +43,7 @@ egcpool_grow(egcpool* pool, size_t len){
|
|||||||
while(len > newsize - pool->poolsize){ // ensure we make enough space
|
while(len > newsize - pool->poolsize){ // ensure we make enough space
|
||||||
newsize *= 2;
|
newsize *= 2;
|
||||||
}
|
}
|
||||||
// offsets only have 25 bits available...
|
if(newsize > 1u << 25u){
|
||||||
if(newsize >= 1u << 25u){
|
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
// nasty cast here because c++ source might include this header :/
|
// nasty cast here because c++ source might include this header :/
|
||||||
@ -129,7 +128,7 @@ egcpool_stash(egcpool* pool, const char* egc, size_t ulen){
|
|||||||
if(!duplicated){
|
if(!duplicated){
|
||||||
duplicated = strdup(egc);
|
duplicated = strdup(egc);
|
||||||
}
|
}
|
||||||
if(egcpool_grow(pool, len)){
|
if(egcpool_grow(pool, len) && searched){
|
||||||
free(duplicated);
|
free(duplicated);
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
@ -140,6 +139,7 @@ egcpool_stash(egcpool* pool, const char* egc, size_t ulen){
|
|||||||
// memory. if we find it, write it out, and update used count. if we come
|
// memory. if we find it, write it out, and update used count. if we come
|
||||||
// back to where we started, force a growth and try again.
|
// back to where we started, force a growth and try again.
|
||||||
int curpos = pool->poolwrite;
|
int curpos = pool->poolwrite;
|
||||||
|
//fprintf(stderr, "Stashing [%s] %d starting at %d\n", egc, len, curpos);
|
||||||
do{
|
do{
|
||||||
if(curpos == pool->poolsize){
|
if(curpos == pool->poolsize){
|
||||||
curpos = 0;
|
curpos = 0;
|
||||||
@ -167,6 +167,7 @@ egcpool_stash(egcpool* pool, const char* egc, size_t ulen){
|
|||||||
pool->poolwrite = curpos + len;
|
pool->poolwrite = curpos + len;
|
||||||
pool->poolused += len;
|
pool->poolused += len;
|
||||||
free(duplicated);
|
free(duplicated);
|
||||||
|
//fprintf(stderr, "Stashing AT %d\n", curpos);
|
||||||
return curpos;
|
return curpos;
|
||||||
}
|
}
|
||||||
if(pool->poolwrite > curpos && pool->poolwrite - (len - need) < curpos){
|
if(pool->poolwrite > curpos && pool->poolwrite - (len - need) < curpos){
|
||||||
|
Loading…
Reference in New Issue
Block a user