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

* array.c (sort_1, sort_2): check for reentered and if elements are

accessible.  [ruby-core:16679]


git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@16321 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
nobu 2008-05-08 00:51:55 +00:00
parent 68c67143b2
commit 4c2b10e0d6
2 changed files with 10 additions and 5 deletions

View file

@ -1,6 +1,7 @@
Thu May 8 08:56:31 2008 Nobuyoshi Nakada <nobu@ruby-lang.org> Thu May 8 09:51:52 2008 Nobuyoshi Nakada <nobu@ruby-lang.org>
* array.c (sort_1, sort_2): check reentered. [ruby-core:16679] * array.c (sort_1, sort_2): check for reentered and if elements are
accessible. [ruby-core:16679]
Thu May 8 06:43:52 2008 Nobuyoshi Nakada <nobu@ruby-lang.org> Thu May 8 06:43:52 2008 Nobuyoshi Nakada <nobu@ruby-lang.org>

10
array.c
View file

@ -1442,21 +1442,23 @@ rb_ary_reverse_m(VALUE ary)
return rb_ary_reverse(rb_ary_dup(ary)); return rb_ary_reverse(rb_ary_dup(ary));
} }
static void static VALUE
check_reentered(VALUE *klass) check_reentered(VALUE *klass)
{ {
if (*klass) { if (*klass) {
rb_raise(rb_eRuntimeError, "sort! reentered"); rb_raise(rb_eRuntimeError, "sort! reentered");
} }
return Qnil;
} }
static int static int
sort_1(const void *ap, const void *bp, void *dummy) sort_1(const void *ap, const void *bp, void *dummy)
{ {
VALUE retval = check_reentered(dummy);
VALUE a = *(const VALUE *)ap, b = *(const VALUE *)bp; VALUE a = *(const VALUE *)ap, b = *(const VALUE *)bp;
VALUE retval = rb_yield_values(2, a, b);
int n; int n;
retval = rb_yield_values(2, a, b);
n = rb_cmpint(retval, a, b); n = rb_cmpint(retval, a, b);
check_reentered(dummy); check_reentered(dummy);
return n; return n;
@ -1465,7 +1467,7 @@ sort_1(const void *ap, const void *bp, void *dummy)
static int static int
sort_2(const void *ap, const void *bp, void *dummy) sort_2(const void *ap, const void *bp, void *dummy)
{ {
VALUE retval; VALUE retval = check_reentered(dummy);
VALUE a = *(const VALUE *)ap, b = *(const VALUE *)bp; VALUE a = *(const VALUE *)ap, b = *(const VALUE *)bp;
int n; int n;
@ -1515,6 +1517,8 @@ rb_ary_sort_bang(VALUE ary)
RARRAY(ary)->len = RARRAY(tmp)->len; RARRAY(ary)->len = RARRAY(tmp)->len;
RARRAY(ary)->aux.capa = RARRAY(tmp)->aux.capa; RARRAY(ary)->aux.capa = RARRAY(tmp)->aux.capa;
FL_UNSET(ary, ELTS_SHARED); FL_UNSET(ary, ELTS_SHARED);
RARRAY(tmp)->ptr = 0;
RARRAY(tmp)->len = 0;
RBASIC(tmp)->klass = RBASIC(ary)->klass; RBASIC(tmp)->klass = RBASIC(ary)->klass;
} }
return ary; return ary;