mirror of
https://github.com/ashinn/chibi-scheme.git
synced 2025-05-18 21:29:19 +02:00
Don't bother resetting weak references if none have been allocated.
This commit is contained in:
parent
d1c71adb40
commit
b4c7a7081d
3 changed files with 15 additions and 5 deletions
17
gc.c
17
gc.c
|
@ -277,12 +277,16 @@ void sexp_conservative_mark (sexp ctx) {
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#if SEXP_USE_WEAK_REFERENCES
|
#if SEXP_USE_WEAK_REFERENCES
|
||||||
void sexp_reset_weak_references(sexp ctx) {
|
int sexp_reset_weak_references(sexp ctx) {
|
||||||
int i, len, all_reset_p;
|
int i, len, broke, all_reset_p;
|
||||||
sexp_heap h = sexp_context_heap(ctx);
|
sexp_heap h;
|
||||||
sexp p, t, end, *v;
|
sexp p, t, end, *v;
|
||||||
sexp_free_list q, r;
|
sexp_free_list q, r;
|
||||||
for ( ; h; h=h->next) { /* just scan the whole heap */
|
if (sexp_not(sexp_global(ctx, SEXP_G_WEAK_OBJECTS_PRESENT)))
|
||||||
|
return 0;
|
||||||
|
broke = 0;
|
||||||
|
/* just scan the whole heap */
|
||||||
|
for (h = sexp_context_heap(ctx) ; h; h=h->next) {
|
||||||
p = sexp_heap_first_block(h);
|
p = sexp_heap_first_block(h);
|
||||||
q = h->free_list;
|
q = h->free_list;
|
||||||
end = sexp_heap_end(h);
|
end = sexp_heap_end(h);
|
||||||
|
@ -309,6 +313,7 @@ void sexp_reset_weak_references(sexp ctx) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (all_reset_p) { /* ephemerons */
|
if (all_reset_p) { /* ephemerons */
|
||||||
|
broke++;
|
||||||
len += sexp_type_weak_len_extra(t);
|
len += sexp_type_weak_len_extra(t);
|
||||||
for ( ; i<len; i++) v[i] = SEXP_FALSE;
|
for ( ; i<len; i++) v[i] = SEXP_FALSE;
|
||||||
}
|
}
|
||||||
|
@ -317,9 +322,11 @@ void sexp_reset_weak_references(sexp ctx) {
|
||||||
p = (sexp) (((char*)p)+sexp_heap_align(sexp_allocated_bytes(ctx, p)));
|
p = (sexp) (((char*)p)+sexp_heap_align(sexp_allocated_bytes(ctx, p)));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
sexp_debug_printf("%p (broke %d weak references)", ctx, broke);
|
||||||
|
return broke;
|
||||||
}
|
}
|
||||||
#else
|
#else
|
||||||
#define sexp_reset_weak_references(ctx)
|
#define sexp_reset_weak_references(ctx) 0
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#if SEXP_USE_FINALIZERS
|
#if SEXP_USE_FINALIZERS
|
||||||
|
|
|
@ -1261,6 +1261,7 @@ enum sexp_context_globals {
|
||||||
SEXP_G_FOLD_CASE_P,
|
SEXP_G_FOLD_CASE_P,
|
||||||
#endif
|
#endif
|
||||||
#if SEXP_USE_WEAK_REFERENCES
|
#if SEXP_USE_WEAK_REFERENCES
|
||||||
|
SEXP_G_WEAK_OBJECTS_PRESENT,
|
||||||
SEXP_G_FILE_DESCRIPTORS,
|
SEXP_G_FILE_DESCRIPTORS,
|
||||||
SEXP_G_NUM_FILE_DESCRIPTORS,
|
SEXP_G_NUM_FILE_DESCRIPTORS,
|
||||||
#endif
|
#endif
|
||||||
|
|
2
sexp.c
2
sexp.c
|
@ -403,6 +403,7 @@ void sexp_init_context_globals (sexp ctx) {
|
||||||
sexp_global(ctx, SEXP_G_PRESERVATIVES) = SEXP_NULL;
|
sexp_global(ctx, SEXP_G_PRESERVATIVES) = SEXP_NULL;
|
||||||
#endif
|
#endif
|
||||||
#if SEXP_USE_WEAK_REFERENCES
|
#if SEXP_USE_WEAK_REFERENCES
|
||||||
|
sexp_global(ctx, SEXP_G_WEAK_OBJECTS_PRESENT) = SEXP_FALSE;
|
||||||
sexp_global(ctx, SEXP_G_FILE_DESCRIPTORS) = SEXP_FALSE;
|
sexp_global(ctx, SEXP_G_FILE_DESCRIPTORS) = SEXP_FALSE;
|
||||||
sexp_global(ctx, SEXP_G_NUM_FILE_DESCRIPTORS) = SEXP_ZERO;
|
sexp_global(ctx, SEXP_G_NUM_FILE_DESCRIPTORS) = SEXP_ZERO;
|
||||||
#endif
|
#endif
|
||||||
|
@ -1673,6 +1674,7 @@ sexp sexp_open_output_file_descriptor (sexp ctx, sexp self, sexp_sint_t n, sexp
|
||||||
sexp sexp_make_ephemeron_op(sexp ctx, sexp self, sexp_sint_t n, sexp key, sexp value) {
|
sexp sexp_make_ephemeron_op(sexp ctx, sexp self, sexp_sint_t n, sexp key, sexp value) {
|
||||||
sexp res = sexp_alloc_type(ctx, pair, SEXP_EPHEMERON);
|
sexp res = sexp_alloc_type(ctx, pair, SEXP_EPHEMERON);
|
||||||
if (!sexp_exceptionp(res)) {
|
if (!sexp_exceptionp(res)) {
|
||||||
|
sexp_global(ctx, SEXP_G_WEAK_OBJECTS_PRESENT) = SEXP_TRUE;
|
||||||
sexp_ephemeron_key(res) = key;
|
sexp_ephemeron_key(res) = key;
|
||||||
sexp_ephemeron_value(res) = value;
|
sexp_ephemeron_value(res) = value;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue