Skip to content

Instantly share code, notes, and snippets.

@rdp
Created December 13, 2008 11:36
Index: gc.c
===================================================================
--- gc.c (revision 20686)
+++ gc.c (working copy)
@@ -1,4 +1,4 @@
-/**********************************************************************
+/*
gc.c -
@@ -497,6 +497,8 @@
# define STACK_LEVEL_MAX 655300
#endif
+
+
#ifdef C_ALLOCA
# define SET_STACK_END VALUE stack_end; alloca(0);
# define STACK_END (&stack_end)
@@ -560,12 +562,32 @@
return STACK_LENGTH;
}
+/* note not good for those whose stacks grow upward, yet */
+void *deepest_spot_so_far = (void *) -1;
+
+void
+clean_stack()
+{
+ SET_STACK_END;
+ if((void *) STACK_END < deepest_spot_so_far) {
+ deepest_spot_so_far = STACK_END;
+ return;
+ }
+ if((void *) STACK_END == deepest_spot_so_far)
+ return;
+
+ memset(deepest_spot_so_far, '\0', ((int) STACK_END - (int) deepest_spot_so_far - 1));
+ deepest_spot_so_far = STACK_END;
+
+}
+
int
ruby_stack_check()
{
int ret;
-
CHECK_STACK(ret);
+ clean_stack();
+
return ret;
}
@@ -1431,6 +1453,7 @@
static void
garbage_collect()
{
+ clean_stack(); // so we can call GC.start to note the current depth
struct gc_list *list;
struct FRAME * volatile frame; /* gcc 2.7.2.3 -O2 bug?? */
jmp_buf save_regs_gc_mark;
Index: gc.c
===================================================================
--- gc.c (revision 20686)
+++ gc.c (working copy)
@@ -1,4 +1,4 @@
-/**********************************************************************
+/*
gc.c -
@@ -497,6 +497,8 @@
# define STACK_LEVEL_MAX 655300
#endif
+
+
#ifdef C_ALLOCA
# define SET_STACK_END VALUE stack_end; alloca(0);
# define STACK_END (&stack_end)
@@ -560,12 +562,40 @@
return STACK_LENGTH;
}
+/* note not good for those whose stacks grow upward, yet */
+void *deepest_spot_so_far = (void *) -1;
+
+void note_stack_depth_for_cleaning()
+{
+ SET_STACK_END;
+ if((void *) STACK_END < deepest_spot_so_far) {
+ deepest_spot_so_far = STACK_END;
+ }
+}
+
+void
+clean_stack()
+{
+ SET_STACK_END;
+ if((void *) STACK_END < deepest_spot_so_far) {
+ deepest_spot_so_far = STACK_END;
+ return;
+ }
+ if((void *) STACK_END == deepest_spot_so_far)
+ return;
+
+ memset(deepest_spot_so_far, '\0', ((int) STACK_END - (int) deepest_spot_so_far - 1));
+ deepest_spot_so_far = STACK_END;
+
+}
+
int
ruby_stack_check()
{
int ret;
-
CHECK_STACK(ret);
+ clean_stack();
+
return ret;
}
@@ -1431,6 +1461,7 @@
static void
garbage_collect()
{
+ clean_stack(); // so we can call GC.start to note the current depth
struct gc_list *list;
struct FRAME * volatile frame; /* gcc 2.7.2.3 -O2 bug?? */
jmp_buf save_regs_gc_mark;
Index: rubysig.h
===================================================================
--- rubysig.h (revision 20686)
+++ rubysig.h (working copy)
@@ -80,8 +80,10 @@
RUBY_EXTERN int rb_thread_critical;
RUBY_EXTERN int rb_thread_pending;
void rb_thread_schedule _((void));
+void note_stack_depth_for_cleaning();
#if defined(HAVE_SETITIMER) || defined(_THREAD_SAFE)
# define CHECK_INTS do {\
+ note_stack_depth_for_cleaning();\
if (!(rb_prohibit_interrupt || rb_thread_critical)) {\
if (rb_thread_pending) rb_thread_schedule();\
if (rb_trap_pending) rb_trap_exec();\
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment