~ chicken-core (chicken-5) b88c768ed1143134a213b008395701409abb39e0


commit b88c768ed1143134a213b008395701409abb39e0
Author:     Jim Ursetto <zbigniewsz@gmail.com>
AuthorDate: Mon Aug 12 15:51:41 2013 -0500
Commit:     Peter Bex <peter.bex@xs4all.nl>
CommitDate: Tue Aug 13 20:52:06 2013 +0200

    Make trace buffer resizable at runtime, via ##sys#resize-trace-buffer
    
     - Add C_resize_trace_buffer
     - Add ##sys#resize-trace-buffer interface, returning old size
     - Move check for min trace buffer size to C_clear_trace_buffer,
       where the buffer is actually allocated
     - In the current implementation, resizing the buffer clears its contents.
    
    Signed-off-by: Peter Bex <peter.bex@xs4all.nl>

diff --git a/NEWS b/NEWS
index 4d96844e..5b3cfdb3 100644
--- a/NEWS
+++ b/NEWS
@@ -1,3 +1,8 @@
+4.8.3
+
+- Runtime system
+  - The procedure trace buffer has been made resizable.
+
 4.8.2
 
 - Security fixes
diff --git a/chicken.h b/chicken.h
index e75e79b1..d828a668 100644
--- a/chicken.h
+++ b/chicken.h
@@ -1665,6 +1665,7 @@ C_fctexport void *C_register_lf2(C_word *lf, int count, C_PTABLE_ENTRY *ptable);
 C_fctexport void C_unregister_lf(void *handle);
 C_fctexport C_char *C_dump_trace(int start);
 C_fctexport void C_fcall C_clear_trace_buffer(void) C_regparm;
+C_fctexport C_word C_resize_trace_buffer(C_word size);
 C_fctexport C_word C_fetch_trace(C_word start, C_word buffer);
 C_fctexport C_word C_fcall C_string(C_word **ptr, int len, C_char *str) C_regparm;
 C_fctexport C_word C_fcall C_static_string(C_word **ptr, int len, C_char *str) C_regparm;
diff --git a/eval.scm b/eval.scm
index 607246b6..b6d72fd4 100644
--- a/eval.scm
+++ b/eval.scm
@@ -1534,6 +1534,9 @@
       (##sys#flush-output ##sys#standard-output) ) ) )
 
 (define ##sys#clear-trace-buffer (foreign-lambda void "C_clear_trace_buffer"))
+(define (##sys#resize-trace-buffer i)
+  (##sys#check-exact i)
+  (##core#inline "C_resize_trace_buffer" i))
 
 (define repl
   (let ((eval eval)
diff --git a/runtime.c b/runtime.c
index 85a1b1f8..c018f8bc 100644
--- a/runtime.c
+++ b/runtime.c
@@ -714,9 +714,6 @@ int CHICKEN_initialize(int heap, int stack, int symbols, void *toplevel)
   gc_root_list = NULL;
  
   /* Initialize global variables: */
-  if(C_trace_buffer_size < MIN_TRACE_BUFFER_SIZE)
-    C_trace_buffer_size = MIN_TRACE_BUFFER_SIZE;
-
   if(C_heap_growth <= 0) C_heap_growth = DEFAULT_HEAP_GROWTH;
 
   if(C_heap_shrinkage <= 0) C_heap_shrinkage = DEFAULT_HEAP_SHRINKAGE;
@@ -3875,6 +3872,9 @@ C_regparm void C_fcall C_clear_trace_buffer(void)
   int i;
 
   if(trace_buffer == NULL) {
+    if(C_trace_buffer_size < MIN_TRACE_BUFFER_SIZE)
+      C_trace_buffer_size = MIN_TRACE_BUFFER_SIZE;
+
     trace_buffer = (TRACE_INFO *)C_malloc(sizeof(TRACE_INFO) * C_trace_buffer_size);
 
     if(trace_buffer == NULL)
@@ -3892,6 +3892,15 @@ C_regparm void C_fcall C_clear_trace_buffer(void)
   }
 }
 
+C_word C_resize_trace_buffer(C_word size) {
+  int old_size = C_trace_buffer_size;
+  assert(trace_buffer);
+  free(trace_buffer);
+  trace_buffer = NULL;
+  C_trace_buffer_size = C_unfix(size);
+  C_clear_trace_buffer();
+  return(C_fix(old_size));
+}
 
 C_word C_fetch_trace(C_word starti, C_word buffer)
 {
Trap