summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--ChangeLog6
-rw-r--r--debug.c41
-rw-r--r--gc.c12
-rw-r--r--main.c16
-rw-r--r--signal.c8
5 files changed, 54 insertions, 29 deletions
diff --git a/ChangeLog b/ChangeLog
index ea988c5160..209875a3a5 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,9 @@
+Fri Jun 29 16:57:22 2007 Nobuyoshi Nakada <nobu@ruby-lang.org>
+
+ * debug.c (ruby_set_debug_option): separated from main.c.
+
+ * gc.c (ruby_gc_stress), signal.c (ruby_enable_coredump): prefixed.
+
Fri Jun 29 16:39:06 2007 Koichi Sasada <ko1@atdot.net>
* proc.c (proc_new): fix to return a proc object
diff --git a/debug.c b/debug.c
index 1612e80eb5..cd1b80f58c 100644
--- a/debug.c
+++ b/debug.c
@@ -12,6 +12,7 @@
#include "ruby/ruby.h"
#include "debug.h"
+#include "yarvcore.h"
void
ruby_debug_print_indent(int level, int debug_level, int indent_level)
@@ -26,7 +27,7 @@ ruby_debug_print_indent(int level, int debug_level, int indent_level)
}
VALUE
-ruby_debug_print_value(int level, int debug_level, char *header, VALUE obj)
+ruby_debug_print_value(int level, int debug_level, const char *header, VALUE obj)
{
if (level < debug_level) {
VALUE str;
@@ -45,7 +46,7 @@ ruby_debug_print_v(VALUE v)
}
ID
-ruby_debug_print_id(int level, int debug_level, char *header, ID id)
+ruby_debug_print_id(int level, int debug_level, const char *header, ID id)
{
if (level < debug_level) {
fprintf(stderr, "DBG> %s: %s\n", header, rb_id2name(id));
@@ -55,13 +56,13 @@ ruby_debug_print_id(int level, int debug_level, char *header, ID id)
}
NODE *
-ruby_debug_print_node(int level, int debug_level, char *header, NODE *node)
+ruby_debug_print_node(int level, int debug_level, const char *header, const NODE *node)
{
if (level < debug_level) {
- fprintf(stderr, "DBG> %s: %s (%d)\n", header,
+ fprintf(stderr, "DBG> %s: %s (%lu)\n", header,
ruby_node_name(nd_type(node)), nd_line(node));
}
- return node;
+ return (NODE *)node;
}
void
@@ -69,3 +70,33 @@ ruby_debug_breakpoint(void)
{
/* */
}
+
+#ifdef RUBY_DEBUG_ENV
+#include <ctype.h>
+
+void
+ruby_set_debug_option(const char *str)
+{
+ const char *end;
+ int len;
+
+ if (!str) return;
+ for (; *str; str = end) {
+ while (ISSPACE(*str) || *str == ',') str++;
+ if (!*str) break;
+ end = str;
+ while (*end && !ISSPACE(*end) && *end != ',') end++;
+ len = end - str;
+#define SET_WHEN(name, var) \
+ if (len == sizeof(name) - 1 && \
+ strncmp(str, name, len) == 0) { \
+ extern int ruby_##var; \
+ ruby_##var = 1; \
+ continue; \
+ }
+ SET_WHEN("gc_stress", gc_stress);
+ SET_WHEN("core", enable_coredump);
+ fprintf(stderr, "unexpected debug option: %.*s\n", len, str);
+ }
+}
+#endif
diff --git a/gc.c b/gc.c
index e4283fb719..a21ced7bd9 100644
--- a/gc.c
+++ b/gc.c
@@ -148,7 +148,7 @@ VALUE *rb_gc_stack_start = 0;
VALUE *rb_gc_register_stack_start = 0;
#endif
-int gc_stress = 0;
+int ruby_gc_stress = 0;
#ifdef DJGPP
@@ -201,7 +201,7 @@ rb_memerror(void)
static VALUE
gc_stress_get(VALUE self)
{
- return gc_stress ? Qtrue : Qfalse;
+ return ruby_gc_stress ? Qtrue : Qfalse;
}
/*
@@ -220,7 +220,7 @@ static VALUE
gc_stress_set(VALUE self, VALUE bool)
{
rb_secure(2);
- gc_stress = RTEST(bool);
+ ruby_gc_stress = RTEST(bool);
return bool;
}
@@ -235,7 +235,7 @@ ruby_xmalloc(size_t size)
if (size == 0) size = 1;
malloc_increase += size;
- if (gc_stress || malloc_increase > malloc_limit) {
+ if (ruby_gc_stress || malloc_increase > malloc_limit) {
garbage_collect();
}
RUBY_CRITICAL(mem = malloc(size));
@@ -283,7 +283,7 @@ ruby_xrealloc(void *ptr, size_t size)
if (!ptr) return ruby_xmalloc(size);
if (size == 0) size = 1;
malloc_increase += size;
- if (gc_stress) garbage_collect();
+ if (ruby_gc_stress) garbage_collect();
RUBY_CRITICAL(mem = realloc(ptr, size));
if (!mem) {
if (garbage_collect()) {
@@ -466,7 +466,7 @@ rb_newobj_from_heap(void)
{
VALUE obj;
- if (gc_stress || !freelist) {
+ if (ruby_gc_stress || !freelist) {
if(!garbage_collect()) {
rb_memerror();
}
diff --git a/main.c b/main.c
index 82144b7c5a..24fbc2e9f3 100644
--- a/main.c
+++ b/main.c
@@ -30,20 +30,8 @@ int
main(int argc, char **argv, char **envp)
{
#ifdef RUBY_DEBUG_ENV
- RUBY_EXTERN int gc_stress;
- RUBY_EXTERN int enable_coredump;
- char *str;
- str = getenv("RUBY_DEBUG");
- if (str) {
- for (str = strtok(str, ","); str; str = strtok(NULL, ",")) {
- if (strcmp(str, "gc_stress") == 0)
- gc_stress = 1;
- else if (strcmp(str, "core") == 0)
- enable_coredump = 1;
- else
- fprintf(stderr, "unexpected debug option: %s\n", str);
- }
- }
+ extern void ruby_set_debug_option(const char *);
+ ruby_set_debug_option(getenv("RUBY_DEBUG"));
#endif
#ifdef _WIN32
NtInitialize(&argc, &argv);
diff --git a/signal.c b/signal.c
index 4cdb9120f6..44c2d2df7d 100644
--- a/signal.c
+++ b/signal.c
@@ -529,9 +529,9 @@ sigsegv(int sig)
exit(1);
}
else {
- extern int gc_stress;
+ extern int ruby_gc_stress;
segv_received = 1;
- gc_stress = 0;
+ ruby_gc_stress = 0;
rb_bug("Segmentation fault");
}
}
@@ -994,7 +994,7 @@ init_sigchld(int sig)
}
#ifdef RUBY_DEBUG_ENV
-int enable_coredump = 0;
+int ruby_enable_coredump = 0;
#endif
/*
@@ -1070,7 +1070,7 @@ Init_signal(void)
#endif
#ifdef RUBY_DEBUG_ENV
- if (!enable_coredump)
+ if (!ruby_enable_coredump)
#endif
{
#ifdef SIGBUS