Adding optional padding on heap objects for debugging.

This commit is contained in:
Alex Shinn 2014-02-01 21:22:14 +09:00
parent 9deba4dbf1
commit 776fc91be4
2 changed files with 8 additions and 4 deletions

8
gc.c
View file

@ -98,7 +98,7 @@ sexp_uint_t sexp_allocated_bytes (sexp ctx, sexp x) {
if (!sexp_pointerp(x) || (sexp_pointer_tag(x) >= sexp_context_num_types(ctx))) if (!sexp_pointerp(x) || (sexp_pointer_tag(x) >= sexp_context_num_types(ctx)))
return sexp_heap_align(1); return sexp_heap_align(1);
t = sexp_object_type(ctx, x); t = sexp_object_type(ctx, x);
res = sexp_type_size_of_object(t, x); res = sexp_type_size_of_object(t, x) + SEXP_GC_PAD;
#if SEXP_USE_DEBUG_GC #if SEXP_USE_DEBUG_GC
if (res == 0) { if (res == 0) {
fprintf(stderr, SEXP_BANNER("%p zero-size object: %p"), ctx, x); fprintf(stderr, SEXP_BANNER("%p zero-size object: %p"), ctx, x);
@ -537,7 +537,7 @@ void* sexp_alloc (sexp ctx, size_t size) {
void *res; void *res;
size_t max_freed, sum_freed, total_size; size_t max_freed, sum_freed, total_size;
sexp_heap h = sexp_context_heap(ctx); sexp_heap h = sexp_context_heap(ctx);
size = sexp_heap_align(size); size = sexp_heap_align(size) + SEXP_GC_PAD;
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));
@ -649,7 +649,7 @@ void sexp_offset_heap_pointers (sexp_heap heap, sexp_heap from_heap, sexp* types
sexp_dl_handle(p) = NULL; sexp_dl_handle(p) = NULL;
#endif #endif
} }
p = (sexp) (((char*)p)+sexp_heap_align(sexp_type_size_of_object(t, p))); p = (sexp) (((char*)p)+sexp_heap_align(sexp_type_size_of_object(t, p))+SEXP_GC_PAD);
} }
} }
@ -688,7 +688,7 @@ void sexp_offset_heap_pointers (sexp_heap heap, sexp_heap from_heap, sexp* types
} }
} }
t = types[sexp_pointer_tag(p)]; t = types[sexp_pointer_tag(p)];
p = (sexp) (((char*)p)+sexp_heap_align(sexp_type_size_of_object(t, p))); p = (sexp) (((char*)p)+sexp_heap_align(sexp_type_size_of_object(t, p)+SEXP_GC_PAD));
} }
} }
} }

View file

@ -388,6 +388,10 @@
#define SEXP_USE_HEADER_MAGIC 0 #define SEXP_USE_HEADER_MAGIC 0
#endif #endif
#ifndef SEXP_GC_PAD
#define SEXP_GC_PAD 0
#endif
#ifndef SEXP_USE_SAFE_ACCESSORS #ifndef SEXP_USE_SAFE_ACCESSORS
#define SEXP_USE_SAFE_ACCESSORS 0 #define SEXP_USE_SAFE_ACCESSORS 0
#endif #endif