TOPLEVEL_BINDING broken in Ruby 1.9 (CVS)

Hi Ruby folks.

When testing the fcgi module I noticed that TOPLEVEL_BINDING seems to be
broken in Ruby 1.9.

As soon as you eval something in TOPLEVEL_BINDING Ruby segfaults:

irb(main):001:0> TOPLEVEL_BINDING
=> #Binding:0x402b4074

irb(main):002:0> eval(‘puts “Hello!”’, TOPLEVEL_BINDING)
(irb):2: [BUG] Segmentation fault
ruby 1.9.0 (2004-05-27) [i686-linux-gnu]

FCGI uses this to eval class defining code within the binding. However
replacing TOPLEVEL_BINDING with a global variable like $toplevel_binding
which is defined from binding at the beginning of the file just works fine
and fixes the problem.

Any comments on this?

Still Ruby is a very nice piece of work. =D

Bye,
phil

···


Please send replies (not followups) to the address set in Reply-To.
Philipp Kern - PK2186-RIPE - http://www.philkern.de

Hi,

At Wed, 2 Jun 2004 04:03:37 +0900,
Philipp Kern wrote in [ruby-talk:102037]:

As soon as you eval something in TOPLEVEL_BINDING Ruby segfaults:

irb(main):001:0> TOPLEVEL_BINDING
=> #Binding:0x402b4074

irb(main):002:0> eval(‘puts “Hello!”’, TOPLEVEL_BINDING)
(irb):2: [BUG] Segmentation fault
ruby 1.9.0 (2004-05-27) [i686-linux-gnu]

I expect it has been fixed.

$ ruby -v -e ‘eval(%[puts “Hello!”], TOPLEVEL_BINDING)’
ruby 1.9.0 (2004-05-28) [i686-linux]
Hello!

Apply this patch if you need it immediately.

Index: eval.c

···

===================================================================
RCS file: /cvs/ruby/src/ruby/eval.c,v
retrieving revision 1.666
retrieving revision 1.667
diff -U2 -p -d -r1.666 -r1.667
— eval.c 26 May 2004 05:19:49 -0000 1.666
+++ eval.c 28 May 2004 02:20:34 -0000 1.667
@@ -2932,5 +2932,4 @@ rb_eval(self, n)
PUSH_ITER(ITER_PRE);
if (nd_type(node) == NODE_ITER) {

  •       ruby_frame->node = node;
          result = rb_eval(self, node->nd_iter);
      }
    

@@ -6044,5 +6043,5 @@ eval(self, src, scope, file, line)
old_wrapper = ruby_wrapper;
ruby_wrapper = data->wrapper;

  • if (file == 0 || (line == 1 && strcmp(file, “(eval)”) == 0)) {
  • if ((file == 0 || (line == 1 && strcmp(file, “(eval)”) == 0)) && data->frame.node) {
    file = data->frame.node->nd_file;
    if (!file) file = “builtin”;


Nobu Nakada

I expect it has been fixed.

Hm some more flaws with ActiveRecord so I think I go back to ruby18 for a
while |:

$ ruby -v -e ‘eval(%[puts “Hello!”], TOPLEVEL_BINDING)’
ruby 1.9.0 (2004-05-28) [i686-linux]
Hello!

This indeed works. What makes you think that it’s fixed now? I’ll update
from CVS as soon as helium’s repository is back online.

Bye,
phil

···

On 2004-06-01, nobu.nokada@softhome.net nobu.nokada@softhome.net wrote:

Please send replies (not followups) to the address set in Reply-To.
Philipp Kern - PK2186-RIPE - http://www.philkern.de