[Feature:trunk] RubyVM::InstructionSequence to accept IOs

Rippere$B$Oe(BRipper#initializee$B$Ge(BIOe$B$r<u$1IU$1$^$9$,!"e(BISeqe$B$O$=$&$O$J$C$F$$$^$;$s!#e(B
e$BHsBP>N$J$N$Ge(BISeqe$B$be(BIOe$B$r<u$1IU$1$k$h$&$K$9$k$N$O$I$&$G$7$g$&$+!#e(B

Signed-off-by: Urabe, Shyuohei [email protected]

iseq.c | 6 ++++±
1 files changed, 5 insertions(+), 1 deletions(-)

diff --git a/iseq.c b/iseq.c
index 3c957c7…2d86f5d 100644
— a/iseq.c
+++ b/iseq.c
@@ -538,10 +538,14 @@ rb_iseq_compile_with_option(VALUE src, VALUE file,
VALUE line, VALUE opt)
rb_compile_option_t option;
const char *fn = StringValueCStr(file);
int ln = NUM2INT(line);

  • NODE *node = parse_string(StringValue(src), fn, ln);
  • NODE *node;
    rb_thread_t *th = GET_THREAD();
    make_compile_option(&option, opt);

  • if (rb_obj_respond_to(src, rb_intern(“gets”), 0))

  •    node = rb_compile_file(fn, src, ln);
    
  • else

  •    node = rb_compile_string(fn, StringValue(src), ln);
    

    if (th->base_block && th->base_block->iseq) {
    return rb_iseq_new_with_opt(node, th->base_block->iseq->name,
    file, line, th->base_block->iseq->self,
    – 1.6.0.4

e$B%A%1%C%He(B #2674 e$B$,99?7$5$l$^$7$?!#e(B (by _ wanabe)

e$B%o%J%Y$H?=$7$^$9!#e(B

e$B$;$C$+$/e(B rb_compile_file e$B$,$"$k$N$G!“e(BIO
e$B$r<u$1IU$1$F$/$l$k$J$ie(B
e$B$=$NJ}$,4r$7$$$H;W$$$^$9!#$G$9$N$G!”$3$N%Q%C%A$K;[email protected]$G$9!#e(B

http://redmine.ruby-lang.org/issues/show/2674

(2010/03/31 2:28), _ wanabe wrote::

e$B$;$C$+$/e(B rb_compile_file e$B$,$"$k$N$G!“e(BIO e$B$r<u$1IU$1$F$/$l$k$J$ie(B
e$B$=$NJ}$,4r$7$$$H;W$$$^$9!#$G$9$N$G!”$3$N%Q%C%A$K;[email protected]$G$9!#e(B

e$B!!$9$_$^$;$s!$$3$N7oK:$l$F$$$^$7$?!%e(BIO
e$B$r<u$1IU$1$k$N$O$$$$$s$G$9e(B
e$B$,!$e(Bgets
e$B$N$"$j$J$7!$$G8+J,$1$k$N$,@[email protected]$15$$K$J$C$F$$$^$9!%[email protected](B
e$B$1!$e(BRuby e$BE*$Ke(B OK e$B$H$+e(B NG
e$B$H$+!$C/$+H=CG$7$F$b$i$($l$P!%e(B

e$B$3$3$G;H$&$N$Oe(B gets [email protected][email protected]$C$1!)e(B

e$B%A%1%C%He(B #2674 e$B$,99?7$5$l$^$7$?!#e(B (by _ wanabe)

e$B$"$j$,$H$&$4$6$$$^$9!#e(B
NG e$B$J%1!<%9$r8+$D$1$F$7$^$C$?$N$GJs9p$7$^$9!#$3$l$Ge(B SEGV
e$B$7$^$9!#e(B

a = [nil]
def a.gets
raise
end
RubyVM::InstructionSequence.compile(a)

e$BCf$r8+$k$H!"e(Blex_io_gets e$B$+$i:G=E$Ke(B rb_io_getline_1
e$B$r8F$S=P$7$Fe(B
GetOpenFile e$B$Ge(B RFILE() e$B$r;H$C$F$$$k$h$&$G$9$N$G!"e(B
src e$B$,e(B T_FILE
e$B$+$I$&$+$GH=CG$9$k$N$,$$$$$N$G$O$J$$$+$H;W$$$^$9!#e(B

e$B$"$k$$$Oe(B rb_parser_compile_file e$BFbIt$G!“e(Bfile e$B$,e(B T_FILE
e$B$+$I$&$+$Ge(B
lex_gets e$B$rJQ$($k!Je(Brb_io_gets e$B$r8F$V$+e(B rb_funcall
e$B7PM3$Ge(B gets e$B$9$k$+!Ke(B
e$B$H$$$&$N$b9M$($^$7$?$,!”$A$g$C$H1F6AHO0O$,$o$+$j$^$;$s$G$7$?!#e(B

http://redmine.ruby-lang.org/issues/show/2674

_ wanabe e$B$5$s$O=q$-$^$7$?e(B:

e$B$"$j$,$H$&$4$6$$$^$9!#e(B
NG e$B$J%1!<%9$r8+$D$1$F$7$^$C$?$N$GJs9p$7$^$9!#$3$l$Ge(B SEGV e$B$7$^$9!#e(B

e$B$=$l$Oe(Brb_compile_filee$B$N%P%0$G$Oe(B…

Signed-off-by: Urabe, Shyuohei [email protected]

iseq.c | 2 ++
parse.y | 14 +++++++±-----
2 files changed, 10 insertions(+), 6 deletions(-)

diff --git a/iseq.c b/iseq.c
index 77f1497…2cccfcc 100644
— a/iseq.c
+++ b/iseq.c
@@ -551,6 +551,8 @@ rb_iseq_compile_with_option(VALUE src, VALUE file,
VALUE filepath, VALUE line, V
node = rb_compile_file(fn, src, ln);
else
node = rb_compile_string(fn, StringValue(src), ln);

  • if (!node)
  •    rb_exc_raise(GET_THREAD()->errinfo);
    
    if (th->base_block && th->base_block->iseq) {
    return rb_iseq_new_with_opt(node, th->base_block->iseq->name,
    file, filepath, line, th->base_block->iseq->self,
    diff --git a/parse.y b/parse.y
    index 340a825…438b8f5 100644
    — a/parse.y
    +++ b/parse.y
    @@ -5138,6 +5138,12 @@ lex_getline(struct parser_params *parser)

static const rb_data_type_t parser_data_type;

+static VALUE
+lex_get_generic(struct parser_params *parser, VALUE src)
+{

  • return rb_funcall(src, rb_intern(“gets”), 0);
    +}

#ifndef RIPPER
static NODE*
parser_compile_string(volatile VALUE vparser, const char *f, VALUE s,
int line)
@@ -5209,7 +5215,7 @@ rb_parser_compile_file(volatile VALUE vparser,
const char *f, VALUE file, int st
NODE *node;

 TypedData_Get_Struct(vparser, struct parser_params, 

&parser_data_type, parser);

  • lex_gets = lex_io_gets;
  • lex_gets = lex_get_generic;
    lex_input = file;
    lex_pbeg = lex_p = lex_pend = 0;
    compile_for_eval = rb_parse_in_eval();
    @@ -10319,11 +10325,7 @@ ripper_warningS(struct parser_params *parser,
    const char *fmt, const char *str)
    STR_NEW2(fmt), STR_NEW2(str));
    }

-static VALUE
-ripper_lex_get_generic(struct parser_params *parser, VALUE src)
-{

  • return rb_funcall(src, ripper_id_gets, 0);
    -}
    +#define ripper_lex_get_generic lex_get_generic

static VALUE
ripper_s_allocate(VALUE klass)

e$B1sF#$G$9!#e(B

2010e$BG/e(B3e$B7ne(B31e$BF|e(B14:38 Urabe S.
[email protected]:

_ wanabe e$B$5$s$O=q$-$^$7$?e(B:

e$B$"$j$,$H$&$4$6$$$^$9!#e(B
NG e$B$J%1!<%9$r8+$D$1$F$7$^$C$?$N$GJs9p$7$^$9!#$3$l$Ge(B SEGV e$B$7$^$9!#e(B

e$B$=$l$Oe(Brb_compile_filee$B$N%P%0$G$Oe(B…

rb_compile_file e$B$Oe(B T_FILE
e$B$r<u$1<h$k$H$$$&;[email protected]$C$?$N$G$7$g$&!#e(B

e$BKNIt$5$s$N%Q%C%A$r$"$F$k$H!"%a%=%C%I8F$S=P$7J,$NB.EYNt2=$,!D!De(B
e$B$O$H$b$+$/!"e(BIO#gets
e$B$r:FDj5A$9$k$3$H$G%Q!<%9Cf$KG$0U$N%3!<%I$,e(B
e$B<B9T$G$-$k$h$&$K$J$j$^$9$,!"Bg>fIW$G$7$g$&$+!#e(B

ripper e$B$,$9$G$K$d$C$F$k$o$1$G$9$,!"e(Bripper

e$B$OF0:n<[email protected]$J$5$=$&e(B

e$B$J$N$G?.MQ$G$-$^$;$s!D!De(B

e$B$H$j$"$($:e(B continuation e$B$r;H$&$HMn$A$^$7$?!#e(B

$ ./ruby -e ’
require “continuation”
$code = “p :foo”
class IO
def gets
callcc {|c| $c = c }
code, $code = $code, nil
code
end
end
load “foo.rb”
$c.call

:foo
-e:11: [BUG] Segmentation fault
(e$BN,e(B)

continuation e$B$O<[email protected]$$H$7$F$b!"2?$+L/$J1F6A$O$J$$$G$9$+$M!#e(B
load/require e$BL?Na$r>h$C<h$l$k$h$&$K$J$k$H$+5$$K$J$j$^$9!#e(B

$ cat foo.rb
p :innocent

$ ./ruby.new -e ’
$code = “p :evil”
class IO
def gets
code, $code = $code, nil
code
end
end

load "foo.rb"


:evil

IO#gets e$B$,:FDj5A$G$-$k>u67$J$i$J$s$G$b$d$jJ|Bj$G$O$"$k$N$G$9$,!#e(B
wanabe e$B$5$s$HF1$8$/!"e(BT_FILE
e$B$+$I$&$+$GH=CG$9$k$N$,[email protected]$H;W$$e(B
e$B$^$7$?!#e(B

e$B%A%1%C%He(B #2674 e$B$,99?7$5$l$^$7$?!#e(B (by Yusuke E.)

Target version 1.9.2e$B$+$ie(B1.9.xe$B$KJQ99e(B

e$B1sF#$G$9!#e(B

e$B;DG0$G$9$,!“e(B4/1
e$B$N;[email protected]$G!V$=$&$$$&;EMM$H7h$^$l$PFC$K0[[email protected]$O$”$j$^$;$s!We(B
e$B$H$$$&>u67$G!"[email protected]$,[email protected]$($F$7$^$C$?$h$&$J$N$G!"e(Bspec freeze
e$B$^$Ge(B
e$B$K$O9g0U$,$G$-$J$+$C$?$H9M$($^$9!#e(B
target e$B$re(B 1.9.x e$B$K$5$;[email protected]$-$^$9!#e(B


Yusuke E. [email protected]

http://redmine.ruby-lang.org/issues/show/2674

e$B%A%1%C%He(B #2674 e$B$,99?7$5$l$^$7$?!#e(B (by Shyouhei U.)

e$B$"$C!"$O$$!#e(B

e$B$F$+e(B1.9.3e$B$C$F$$$&e(Btargete$B:n$j$^$;$se(B?

http://redmine.ruby-lang.org/issues/show/2674

e$BKNIt$G$9!#e(B

Yusuke ENDOH e$B$5$s$O=q$-$^$7$?e(B:

rb_compile_file e$B$Oe(B T_FILE e$B$r<u$1<h$k$H$$$&;[email protected]$C$?$N$G$7$g$&!#e(B

getse$B$8$c$J$-$c%d%@$H$$$&6/$$F05!$,$"$k$o$1$G$O$J$$$N$G!"$=$&$$$&;EMM$H7h$^$l$Pe(B
e$BFC$K0[[email protected]$O$"$j$^$;$s!#[email protected]$=$N>l9g$Oe(Brippere$B$be(BT_FILEe$B$N$[$&$KE]$9$Y$-$G$7$g$&$M!#e(B

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs