зеркало из https://github.com/github/ruby.git
* array.c (sort_1, sort_2): check reentered. [ruby-core:16679]
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@16320 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
Родитель
4264ca9436
Коммит
68c67143b2
|
@ -1,3 +1,7 @@
|
||||||
|
Thu May 8 08:56:31 2008 Nobuyoshi Nakada <nobu@ruby-lang.org>
|
||||||
|
|
||||||
|
* array.c (sort_1, sort_2): check reentered. [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>
|
||||||
|
|
||||||
* dln.c (dln_find_exe_r, dln_find_file_r): reentrant versions.
|
* dln.c (dln_find_exe_r, dln_find_file_r): reentrant versions.
|
||||||
|
|
14
array.c
14
array.c
|
@ -1442,6 +1442,14 @@ rb_ary_reverse_m(VALUE ary)
|
||||||
return rb_ary_reverse(rb_ary_dup(ary));
|
return rb_ary_reverse(rb_ary_dup(ary));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static void
|
||||||
|
check_reentered(VALUE *klass)
|
||||||
|
{
|
||||||
|
if (*klass) {
|
||||||
|
rb_raise(rb_eRuntimeError, "sort! reentered");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
static int
|
static int
|
||||||
sort_1(const void *ap, const void *bp, void *dummy)
|
sort_1(const void *ap, const void *bp, void *dummy)
|
||||||
{
|
{
|
||||||
|
@ -1450,6 +1458,7 @@ sort_1(const void *ap, const void *bp, void *dummy)
|
||||||
int n;
|
int n;
|
||||||
|
|
||||||
n = rb_cmpint(retval, a, b);
|
n = rb_cmpint(retval, a, b);
|
||||||
|
check_reentered(dummy);
|
||||||
return n;
|
return n;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1471,6 +1480,7 @@ sort_2(const void *ap, const void *bp, void *dummy)
|
||||||
|
|
||||||
retval = rb_funcall(a, id_cmp, 1, b);
|
retval = rb_funcall(a, id_cmp, 1, b);
|
||||||
n = rb_cmpint(retval, a, b);
|
n = rb_cmpint(retval, a, b);
|
||||||
|
check_reentered(dummy);
|
||||||
|
|
||||||
return n;
|
return n;
|
||||||
}
|
}
|
||||||
|
@ -1500,12 +1510,12 @@ rb_ary_sort_bang(VALUE ary)
|
||||||
|
|
||||||
RBASIC(tmp)->klass = 0;
|
RBASIC(tmp)->klass = 0;
|
||||||
ruby_qsort(RARRAY_PTR(tmp), RARRAY_LEN(tmp), sizeof(VALUE),
|
ruby_qsort(RARRAY_PTR(tmp), RARRAY_LEN(tmp), sizeof(VALUE),
|
||||||
rb_block_given_p()?sort_1:sort_2, 0);
|
rb_block_given_p()?sort_1:sort_2, &RBASIC(tmp)->klass);
|
||||||
RARRAY(ary)->ptr = RARRAY(tmp)->ptr;
|
RARRAY(ary)->ptr = RARRAY(tmp)->ptr;
|
||||||
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);
|
||||||
rb_gc_force_recycle(tmp);
|
RBASIC(tmp)->klass = RBASIC(ary)->klass;
|
||||||
}
|
}
|
||||||
return ary;
|
return ary;
|
||||||
}
|
}
|
||||||
|
|
Загрузка…
Ссылка в новой задаче