At Mon, 17 Dec 2001 23:59:17 +0900,
ts <decoux / moulon.inra.fr> wrote:
> n> yycompile(), but it'll need to be freed.  I have no good idea
> n> but making it (also RNode->nd_file) a String VALUE.
> 
>  Well actually I see also only this solution, but it seems a big
>  modification 

Agreed.  It's not glad.

>  Someone else has another idea ?

Another one, what about registering the filenames to a list?


Index: gc.c =================================================================== RCS file: /cvs/ruby/src/ruby/gc.c,v retrieving revision 1.82 diff -u -2 -p -r1.82 gc.c --- gc.c 2001/12/11 03:48:08 1.82 +++ gc.c 2001/12/17 17:00:24 @@ -430,5 +430,52 @@ init_mark_stack() static void rb_gc_mark_children(VALUE ptr); +static st_table *source_filenames; + +char * +rb_source_filename(f) + const char *f; +{ + VALUE name; + + if (!source_filenames) { + source_filenames = st_init_strtable(); + } + + if (!st_lookup(source_filenames, f, (char *)&name)) { + name = rb_str_new2(f); + OBJ_FREEZE(name); + f = RSTRING(name)->ptr; + st_add_direct(source_filenames, f, name); + } + else { + f = RSTRING(name)->ptr; + } + + return (char *)f; +} + static void +mark_source_filename(f) + const char *f; +{ + VALUE name; + + if (!f) return; + if (!source_filenames) return; + if (!st_lookup(source_filenames, f, (char *)&name)) return; + FL_SET(name, FL_MARK); +} + +static enum st_retval +sweep_source_filename(key, value) + char *key; + char *value; +{ + if (!(RBASIC(value)->flags & FL_MARK)) + return ST_DELETE; + return ST_CONTINUE; +} + +static void gc_mark_all() { @@ -606,4 +653,5 @@ rb_gc_mark_children(ptr) case T_NODE: + mark_source_filename(obj->as.node.nd_file); switch (nd_type(obj)) { case NODE_IF: /* 1,2,3 */ @@ -848,4 +896,6 @@ gc_sweep() } } + + st_foreach(source_filenames, sweep_source_filename, 0); freelist = 0; Index: parse.y =================================================================== RCS file: /cvs/ruby/src/ruby/parse.y,v retrieving revision 1.136 diff -u -2 -p -r1.136 parse.y --- parse.y 2001/12/11 03:48:08 1.136 +++ parse.y 2001/12/17 16:59:52 @@ -2111,4 +2111,6 @@ int ruby__end__seen; static VALUE ruby_debug_lines; +extern char *rb_source_filename _((const char *)); + static NODE* yycompile(f, line) @@ -2119,4 +2121,6 @@ yycompile(f, line) NODE *node = 0; + f = rb_source_filename(f); + if (!compile_for_eval && rb_safe_level() == 0 && rb_const_defined(rb_cObject, rb_intern("SCRIPT_LINES__"))) { @@ -2229,5 +2233,5 @@ rb_compile_file(f, file, start) ruby_sourceline = start - 1; - return yycompile(strdup(f), start); + return yycompile(f, start); }
Nobu Nakada