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:
parent
ef0736604a
commit
e1680f8cc1
2 changed files with 20 additions and 4 deletions
|
@ -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>
|
Wed Jan 12 16:25:12 2011 Yuki Sonoda (Yugui) <yugui@yugui.jp>
|
||||||
|
|
||||||
* lib/net/http.rb (Net::HTTP#connect): makes it timeout during
|
* lib/net/http.rb (Net::HTTP#connect): makes it timeout during
|
||||||
|
|
18
enum.c
18
enum.c
|
@ -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;
|
struct sort_by_data *data = (struct sort_by_data *)_data;
|
||||||
VALUE ary = data->ary;
|
VALUE ary = data->ary;
|
||||||
|
VALUE v;
|
||||||
|
|
||||||
ENUM_WANT_SVALUE();
|
ENUM_WANT_SVALUE();
|
||||||
|
|
||||||
|
v = rb_yield(i);
|
||||||
|
|
||||||
if (RBASIC(ary)->klass) {
|
if (RBASIC(ary)->klass) {
|
||||||
rb_raise(rb_eRuntimeError, "sort_by reentered");
|
rb_raise(rb_eRuntimeError, "sort_by reentered");
|
||||||
}
|
}
|
||||||
|
if (RARRAY_LEN(data->buf) != SORT_BY_BUFSIZE*2) {
|
||||||
RARRAY_PTR(data->buf)[data->n*2] = rb_yield(i);
|
rb_raise(rb_eRuntimeError, "sort_by reentered");
|
||||||
|
}
|
||||||
|
|
||||||
|
RARRAY_PTR(data->buf)[data->n*2] = v;
|
||||||
RARRAY_PTR(data->buf)[data->n*2+1] = i;
|
RARRAY_PTR(data->buf)[data->n*2+1] = i;
|
||||||
data->n++;
|
data->n++;
|
||||||
if (data->n == SORT_BY_BUFSIZE) {
|
if (data->n == SORT_BY_BUFSIZE) {
|
||||||
|
@ -802,13 +808,17 @@ sort_by_i(VALUE i, VALUE _data, int argc, VALUE *argv)
|
||||||
static int
|
static int
|
||||||
sort_by_cmp(const void *ap, const void *bp, void *data)
|
sort_by_cmp(const void *ap, const void *bp, void *data)
|
||||||
{
|
{
|
||||||
VALUE a = *(VALUE *)ap;
|
VALUE a;
|
||||||
VALUE b = *(VALUE *)bp;
|
VALUE b;
|
||||||
VALUE ary = (VALUE)data;
|
VALUE ary = (VALUE)data;
|
||||||
|
|
||||||
if (RBASIC(ary)->klass) {
|
if (RBASIC(ary)->klass) {
|
||||||
rb_raise(rb_eRuntimeError, "sort_by reentered");
|
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);
|
return rb_cmpint(rb_funcall(a, id_cmp, 1, b), a, b);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue