summaryrefslogtreecommitdiffstats
path: root/lib.c
diff options
context:
space:
mode:
authorKaz Kylheku <kaz@kylheku.com>2014-03-12 00:34:10 -0700
committerKaz Kylheku <kaz@kylheku.com>2014-03-12 00:34:10 -0700
commit5bf88f48fe8233955b3346ccea14f8e3fae38286 (patch)
treeda9adbd5427b8e69e2ace69794f64fe4e1e4b494 /lib.c
parent5382f4a6aa4a38c5f2f229f79bee55dfcb3843fc (diff)
downloadtxr-5bf88f48fe8233955b3346ccea14f8e3fae38286.tar.gz
txr-5bf88f48fe8233955b3346ccea14f8e3fae38286.tar.bz2
txr-5bf88f48fe8233955b3346ccea14f8e3fae38286.zip
* eval.c (plus_s, prof_s): New symbol global variables.
(op_prof, me_pprof): New static functions. (eval_init): Intern prof symbol, store in prof_s. Captured interned + symbol in plus_s. Register prof operator and pprof macro. * gc.c (gc_bytes): New global variable. (more): Use nse function chk_malloc_gc_more instead of chk_malloc. (make_obj): Increment gc_bytes. * lib.c (malloc_bytes): New global variable. (chk_malloc, chk_realloc): Increment malloc_bytes. (chk_calloc): Bugfix: incorrect size in recursion into oom_realloc. Incorrect calculation of malloc_high_bound. Increment malloc_bytes. (chk_malloc_gc_more): New function. * lib.h (alloc_bytes_t): New typedef. (malloc_bytes, gc_bytes): Declared. (chk_malloc_gc_more): Declared. * stream.c (format_s): New symbol global. (stream_init): format_s inited. format_s used to register formatv function. * stream.h (format_s): Declared. * txr.1: Documented prof and pprof. * genvim.txr: Recognize reg_fun calls with intern followed by a preceding assignment or other syntax. * txr.vim: Updated.
Diffstat (limited to 'lib.c')
-rw-r--r--lib.c21
1 files changed, 18 insertions, 3 deletions
diff --git a/lib.c b/lib.c
index 839dc116..e7fa9ff9 100644
--- a/lib.c
+++ b/lib.c
@@ -1287,6 +1287,8 @@ val equal(val left, val right)
static mem_t *malloc_low_bound, *malloc_high_bound;
+alloc_bytes_t malloc_bytes;
+
mem_t *chk_malloc(size_t size)
{
mem_t *ptr = (mem_t *) malloc(size);
@@ -1299,23 +1301,35 @@ mem_t *chk_malloc(size_t size)
malloc_low_bound = ptr;
else if (ptr + size > malloc_high_bound)
malloc_high_bound = ptr + size;
+ malloc_bytes += size;
+ return ptr;
+}
+
+mem_t *chk_malloc_gc_more(size_t size)
+{
+ mem_t *ptr = (mem_t *) malloc(size);
+ assert (!async_sig_enabled);
+ if (size && ptr == 0)
+ ptr = (mem_t *) oom_realloc(0, size);
return ptr;
}
mem_t *chk_calloc(size_t n, size_t size)
{
mem_t *ptr = (mem_t *) calloc(n, size);
+ cnum total = (cnum) size * (cnum) n;
assert (!async_sig_enabled);
if (size && ptr == 0) {
- ptr = (mem_t *) oom_realloc(0, size);
- memset(ptr, 0, n * size);
+ ptr = (mem_t *) oom_realloc(0, total);
+ memset(ptr, 0, total);
}
if (ptr < malloc_low_bound)
malloc_low_bound = ptr;
else if (ptr + size > malloc_high_bound)
- malloc_high_bound = ptr + size;
+ malloc_high_bound = ptr + total;
+ malloc_bytes += total;
return ptr;
}
@@ -1331,6 +1345,7 @@ mem_t *chk_realloc(mem_t *old, size_t size)
malloc_low_bound = newptr;
else if (newptr + size > malloc_high_bound)
malloc_high_bound = newptr + size;
+ malloc_bytes += size;
return newptr;
}