summaryrefslogtreecommitdiffstats
path: root/lib.c
diff options
context:
space:
mode:
authorKaz Kylheku <kaz@kylheku.com>2012-04-05 09:41:49 -0700
committerKaz Kylheku <kaz@kylheku.com>2012-04-05 09:41:49 -0700
commit050fe79a752814cf63ae9f40620febbb86cae1ce (patch)
treed3aeb85e115ef1621513be9c49ad7b5a676c3d40 /lib.c
parentc162f73f9cfd0bb48675dc11bd56ac359451510b (diff)
downloadtxr-050fe79a752814cf63ae9f40620febbb86cae1ce.tar.gz
txr-050fe79a752814cf63ae9f40620febbb86cae1ce.tar.bz2
txr-050fe79a752814cf63ae9f40620febbb86cae1ce.zip
Code cleanup and tweaking.
* gc.c (BACKPTR_VEC_SIZE): Preprocessor symbol renamed to CHECKOBJ_VEC_SIZE. (FULL_GC_INTERVAL): Increased to 40 since the modified algorithm now leaves less work for the full gc to do. (backptr, backptr_idx): Static variables renamed to checkobj and checkobj_idx. (mark): Follows rename of backptr and backptr_idx. (gc): Commented out handy printf added. (gc_set): Use in_malloc_range check to avoid adding to the check array pointers which are being stored in non-heap locations, since non-heap locations are already GC roots. (gc_mutated): Follows variable renaming. (gc_push): Just do the push using gc_set. * lib.c (malloc_low_bound, malloc_high_bound): New variables. (chk_malloc, chk_calloc, chk_realloc): Updated malloc_low_bound and malloc_high_bound. (in_malloc_range): New function. * lib.h (in_malloc_range): Declared.
Diffstat (limited to 'lib.c')
-rw-r--r--lib.c19
1 files changed, 19 insertions, 0 deletions
diff --git a/lib.c b/lib.c
index ae6fd998..52197df1 100644
--- a/lib.c
+++ b/lib.c
@@ -930,11 +930,17 @@ val cobj_equal_op(val left, val right)
return eq(left, right);
}
+static mem_t *malloc_low_bound, *malloc_high_bound;
+
mem_t *chk_malloc(size_t size)
{
mem_t *ptr = (mem_t *) malloc(size);
if (size && ptr == 0)
ptr = (mem_t *) oom_realloc(0, size);
+ if (ptr < malloc_low_bound)
+ malloc_low_bound = ptr;
+ else if (ptr + size > malloc_high_bound)
+ malloc_high_bound = ptr + size;
return ptr;
}
@@ -945,6 +951,10 @@ mem_t *chk_calloc(size_t n, size_t size)
ptr = (mem_t *) oom_realloc(0, size);
memset(ptr, 0, n * size);
}
+ if (ptr < malloc_low_bound)
+ malloc_low_bound = ptr;
+ else if (ptr + size > malloc_high_bound)
+ malloc_high_bound = ptr + size;
return ptr;
}
@@ -953,9 +963,18 @@ mem_t *chk_realloc(mem_t *old, size_t size)
mem_t *newptr = (mem_t *) realloc(old, size);
if (size != 0 && newptr == 0)
newptr = oom_realloc(old, size);
+ if (newptr < malloc_low_bound)
+ malloc_low_bound = newptr;
+ else if (newptr + size > malloc_high_bound)
+ malloc_high_bound = newptr + size;
return newptr;
}
+int in_malloc_range(mem_t *ptr)
+{
+ return ptr >= malloc_low_bound && ptr < malloc_high_bound;
+}
+
wchar_t *chk_strdup(const wchar_t *str)
{
size_t nchar = wcslen(str) + 1;