ruby-changes:11235
From: shyouhei <ko1@a...>
Date: Mon, 9 Mar 2009 10:01:56 +0900 (JST)
Subject: [ruby-changes:11235] Ruby:r22844 (ruby_1_8_6): merge revision(s) 21997:
shyouhei 2009-03-09 10:01:46 +0900 (Mon, 09 Mar 2009) New Revision: 22844 http://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=rev&revision=22844 Log: merge revision(s) 21997: * re.c (match_check): check if MatchData is initialized. [ruby-core:18749] Modified files: branches/ruby_1_8_6/ChangeLog branches/ruby_1_8_6/re.c branches/ruby_1_8_6/version.h Index: ruby_1_8_6/ChangeLog =================================================================== --- ruby_1_8_6/ChangeLog (revision 22843) +++ ruby_1_8_6/ChangeLog (revision 22844) @@ -1,3 +1,8 @@ +Mon Mar 9 10:01:26 2009 Yukihiro Matsumoto <matz@r...> + + * re.c (match_check): check if MatchData is initialized. + [ruby-core:18749] + Mon Mar 9 09:55:57 2009 Shugo Maeda <shugo@r...> * lib/rexml/rexml.rb: incremented Ruby::VERSION. Thanks, Jeremy Index: ruby_1_8_6/re.c =================================================================== --- ruby_1_8_6/re.c (revision 22843) +++ ruby_1_8_6/re.c (revision 22844) @@ -682,6 +682,14 @@ return (VALUE)match; } +static void +match_check(VALUE match) +{ + if (!RMATCH(match)->str) { + rb_raise(rb_eTypeError, "uninitialized Match"); + } +} + /* :nodoc: */ static VALUE match_init_copy(obj, orig) @@ -717,6 +725,7 @@ match_size(match) VALUE match; { + match_check(match); return INT2FIX(RMATCH(match)->regs->num_regs); } @@ -739,6 +748,7 @@ { int i = NUM2INT(n); + match_check(match); if (i < 0 || RMATCH(match)->regs->num_regs <= i) rb_raise(rb_eIndexError, "index %d out of matches", i); @@ -768,6 +778,7 @@ { int i = NUM2INT(n); + match_check(match); if (i < 0 || RMATCH(match)->regs->num_regs <= i) rb_raise(rb_eIndexError, "index %d out of matches", i); @@ -796,6 +807,7 @@ { int i = NUM2INT(n); + match_check(match); if (i < 0 || RMATCH(match)->regs->num_regs <= i) rb_raise(rb_eIndexError, "index %d out of matches", i); @@ -959,6 +971,7 @@ VALUE match; { if (NIL_P(match)) return Qnil; + match_check(match); if (nth >= RMATCH(match)->regs->num_regs) { return Qnil; } @@ -979,6 +992,7 @@ long start, end, len; if (NIL_P(match)) return Qnil; + match_check(match); if (nth >= RMATCH(match)->regs->num_regs) { return Qnil; } @@ -1021,6 +1035,7 @@ VALUE str; if (NIL_P(match)) return Qnil; + match_check(match); if (RMATCH(match)->BEG(0) == -1) return Qnil; str = rb_str_substr(RMATCH(match)->str, 0, RMATCH(match)->BEG(0)); if (OBJ_TAINTED(match)) OBJ_TAINT(str); @@ -1047,6 +1062,7 @@ long pos; if (NIL_P(match)) return Qnil; + match_check(match); if (RMATCH(match)->BEG(0) == -1) return Qnil; str = RMATCH(match)->str; pos = RMATCH(match)->END(0); @@ -1062,6 +1078,7 @@ int i; if (NIL_P(match)) return Qnil; + match_check(match); if (RMATCH(match)->BEG(0) == -1) return Qnil; for (i=RMATCH(match)->regs->num_regs-1; RMATCH(match)->BEG(i) == -1 && i > 0; i--) @@ -1099,12 +1116,17 @@ VALUE match; int start; { - struct re_registers *regs = RMATCH(match)->regs; - VALUE ary = rb_ary_new2(regs->num_regs); - VALUE target = RMATCH(match)->str; + struct re_registers *regs; + VALUE ary; + VALUE target; int i; int taint = OBJ_TAINTED(match); - + + match_check(match); + regs = RMATCH(match)->regs; + ary = rb_ary_new2(regs->num_regs); + target = RMATCH(match)->str; + for (i=start; i<regs->num_regs; i++) { if (regs->beg[i] == -1) { rb_ary_push(ary, Qnil); @@ -1236,6 +1258,7 @@ VALUE *argv; VALUE match; { + match_check(match); return rb_values_at(match, RMATCH(match)->regs->num_regs, argc, argv, match_entry); } @@ -1262,12 +1285,16 @@ rb_raise(rb_eArgError, "wrong number of arguments (%d for 0)", argc); } else { - struct re_registers *regs = RMATCH(match)->regs; - VALUE target = RMATCH(match)->str; + struct re_registers *regs; + VALUE target; VALUE result = rb_ary_new(); int i; int taint = OBJ_TAINTED(match); + match_check(match); + regs = RMATCH(match)->regs; + target = RMATCH(match)->str; + for (i=0; i<regs->num_regs; i++) { VALUE str = rb_str_substr(target, regs->beg[i], regs->end[i]-regs->beg[i]); if (taint) OBJ_TAINT(str); @@ -1317,6 +1344,7 @@ match_string(match) VALUE match; { + match_check(match); return RMATCH(match)->str; /* str is frozen */ } Index: ruby_1_8_6/version.h =================================================================== --- ruby_1_8_6/version.h (revision 22843) +++ ruby_1_8_6/version.h (revision 22844) @@ -2,7 +2,7 @@ #define RUBY_RELEASE_DATE "2009-03-09" #define RUBY_VERSION_CODE 186 #define RUBY_RELEASE_CODE 20090309 -#define RUBY_PATCHLEVEL 359 +#define RUBY_PATCHLEVEL 360 #define RUBY_VERSION_MAJOR 1 #define RUBY_VERSION_MINOR 8 -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/