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

* enum.c (sort_by_i): reenter check more strictly.

(sort_by_cmp): ditto.
  [ruby-dev:43003] reported by Usaku NAKAMURA.


git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@30521 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
akr 2011-01-12 10:27:48 +00:00
parent ef0736604a
commit e1680f8cc1
2 changed files with 20 additions and 4 deletions

View file

@ -1,3 +1,9 @@
Wed Jan 12 19:09:29 2011 Tanaka Akira <akr@fsij.org>
* enum.c (sort_by_i): reenter check more strictly.
(sort_by_cmp): ditto.
[ruby-dev:43003] reported by Usaku NAKAMURA.
Wed Jan 12 16:25:12 2011 Yuki Sonoda (Yugui) <yugui@yugui.jp>
* lib/net/http.rb (Net::HTTP#connect): makes it timeout during

16
enum.c
View file

@ -782,14 +782,20 @@ sort_by_i(VALUE i, VALUE _data, int argc, VALUE *argv)
{
struct sort_by_data *data = (struct sort_by_data *)_data;
VALUE ary = data->ary;
VALUE v;
ENUM_WANT_SVALUE();
v = rb_yield(i);
if (RBASIC(ary)->klass) {
rb_raise(rb_eRuntimeError, "sort_by reentered");
}
if (RARRAY_LEN(data->buf) != SORT_BY_BUFSIZE*2) {
rb_raise(rb_eRuntimeError, "sort_by reentered");
}
RARRAY_PTR(data->buf)[data->n*2] = rb_yield(i);
RARRAY_PTR(data->buf)[data->n*2] = v;
RARRAY_PTR(data->buf)[data->n*2+1] = i;
data->n++;
if (data->n == SORT_BY_BUFSIZE) {
@ -802,13 +808,17 @@ sort_by_i(VALUE i, VALUE _data, int argc, VALUE *argv)
static int
sort_by_cmp(const void *ap, const void *bp, void *data)
{
VALUE a = *(VALUE *)ap;
VALUE b = *(VALUE *)bp;
VALUE a;
VALUE b;
VALUE ary = (VALUE)data;
if (RBASIC(ary)->klass) {
rb_raise(rb_eRuntimeError, "sort_by reentered");
}
a = *(VALUE *)ap;
b = *(VALUE *)bp;
return rb_cmpint(rb_funcall(a, id_cmp, 1, b), a, b);
}