mirror of
https://github.com/ashinn/chibi-scheme.git
synced 2025-05-21 06:39:17 +02:00
fixing signedness bug in heap growing heuristics
This commit is contained in:
parent
4d64568736
commit
758e423c1b
1 changed files with 7 additions and 4 deletions
11
gc.c
11
gc.c
|
@ -205,16 +205,19 @@ void* sexp_try_alloc (sexp ctx, size_t size) {
|
||||||
|
|
||||||
void* sexp_alloc (sexp ctx, size_t size) {
|
void* sexp_alloc (sexp ctx, size_t size) {
|
||||||
void *res;
|
void *res;
|
||||||
size_t max_freed, sum_freed;
|
size_t max_freed, sum_freed, total_size;
|
||||||
sexp_heap h;
|
sexp_heap h;
|
||||||
size = sexp_heap_align(size);
|
size = sexp_heap_align(size);
|
||||||
res = sexp_try_alloc(ctx, size);
|
res = sexp_try_alloc(ctx, size);
|
||||||
if (! res) {
|
if (! res) {
|
||||||
max_freed = sexp_unbox_fixnum(sexp_gc(ctx, &sum_freed));
|
max_freed = sexp_unbox_fixnum(sexp_gc(ctx, &sum_freed));
|
||||||
h = sexp_heap_last(sexp_context_heap(ctx));
|
for (total_size=0, h=sexp_context_heap(ctx); h->next; h=h->next)
|
||||||
|
total_size += h->size;
|
||||||
|
total_size += h->size;
|
||||||
if (((max_freed < size)
|
if (((max_freed < size)
|
||||||
|| ((h->size - sum_freed) > (h->size*SEXP_GROW_HEAP_RATIO)))
|
|| ((total_size > sum_freed)
|
||||||
&& ((! SEXP_MAXIMUM_HEAP_SIZE) || (h->size < SEXP_MAXIMUM_HEAP_SIZE)))
|
&& (total_size - sum_freed) > (total_size*SEXP_GROW_HEAP_RATIO)))
|
||||||
|
&& ((!SEXP_MAXIMUM_HEAP_SIZE) || (total_size < SEXP_MAXIMUM_HEAP_SIZE)))
|
||||||
sexp_grow_heap(ctx, size);
|
sexp_grow_heap(ctx, size);
|
||||||
res = sexp_try_alloc(ctx, size);
|
res = sexp_try_alloc(ctx, size);
|
||||||
if (! res)
|
if (! res)
|
||||||
|
|
Loading…
Add table
Reference in a new issue