1
0
Fork 0
mirror of https://github.com/ruby/ruby.git synced 2022-11-09 12:17:21 -05:00

* debug.c (ruby_set_debug_option): separated from main.c.

* gc.c (ruby_gc_stress), signal.c (ruby_enable_coredump): prefixed.


git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@12665 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
nobu 2007-06-29 07:57:24 +00:00
parent e648fc4923
commit eae8a9143f
5 changed files with 54 additions and 29 deletions

View file

@ -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

41
debug.c
View file

@ -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

12
gc.c
View file

@ -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();
}

16
main.c
View file

@ -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);

View file

@ -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