mirror of
https://github.com/ruby/ruby.git
synced 2022-11-09 12:17:21 -05:00
enum.c: check if reentered
* enum.c (cmpint_reenter_check): extract from nmin_cmp and nmin_block_cmp. * enum.c (nmin_cmp): check if reentered before rb_cmpint. [Feature #13437] git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@58971 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
parent
7cdb2840df
commit
e4cc791f87
2 changed files with 28 additions and 7 deletions
19
enum.c
19
enum.c
|
@ -1263,16 +1263,24 @@ struct nmin_data {
|
||||||
const char *method;
|
const char *method;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
static VALUE
|
||||||
|
cmpint_reenter_check(struct nmin_data *data, VALUE val)
|
||||||
|
{
|
||||||
|
if (RBASIC(data->buf)->klass) {
|
||||||
|
rb_raise(rb_eRuntimeError, "%s reentered", data->method);
|
||||||
|
}
|
||||||
|
return val;
|
||||||
|
}
|
||||||
|
|
||||||
static int
|
static int
|
||||||
nmin_cmp(const void *ap, const void *bp, void *_data)
|
nmin_cmp(const void *ap, const void *bp, void *_data)
|
||||||
{
|
{
|
||||||
struct cmp_opt_data cmp_opt = { 0, 0 };
|
struct cmp_opt_data cmp_opt = { 0, 0 };
|
||||||
struct nmin_data *data = (struct nmin_data *)_data;
|
struct nmin_data *data = (struct nmin_data *)_data;
|
||||||
VALUE a = *(const VALUE *)ap, b = *(const VALUE *)bp;
|
VALUE a = *(const VALUE *)ap, b = *(const VALUE *)bp;
|
||||||
if (RBASIC(data->buf)->klass) {
|
#define rb_cmpint(cmp, a, b) rb_cmpint(cmpint_reenter_check(data, (cmp)), a, b)
|
||||||
rb_raise(rb_eRuntimeError, "%s reentered", data->method);
|
|
||||||
}
|
|
||||||
return OPTIMIZED_CMP(a, b, cmp_opt);
|
return OPTIMIZED_CMP(a, b, cmp_opt);
|
||||||
|
#undef rb_cmpint
|
||||||
}
|
}
|
||||||
|
|
||||||
static int
|
static int
|
||||||
|
@ -1281,13 +1289,10 @@ nmin_block_cmp(const void *ap, const void *bp, void *_data)
|
||||||
struct nmin_data *data = (struct nmin_data *)_data;
|
struct nmin_data *data = (struct nmin_data *)_data;
|
||||||
VALUE a = *(const VALUE *)ap, b = *(const VALUE *)bp;
|
VALUE a = *(const VALUE *)ap, b = *(const VALUE *)bp;
|
||||||
VALUE cmp = rb_yield_values(2, a, b);
|
VALUE cmp = rb_yield_values(2, a, b);
|
||||||
if (RBASIC(data->buf)->klass) {
|
cmpint_reenter_check(data, cmp);
|
||||||
rb_raise(rb_eRuntimeError, "%s reentered", data->method);
|
|
||||||
}
|
|
||||||
return rb_cmpint(cmp, a, b);
|
return rb_cmpint(cmp, a, b);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
static void
|
static void
|
||||||
nmin_filter(struct nmin_data *data)
|
nmin_filter(struct nmin_data *data)
|
||||||
{
|
{
|
||||||
|
|
|
@ -604,6 +604,22 @@ class TestEnumerable < Test::Unit::TestCase
|
||||||
[o, o, o].sort_by {|x| x }
|
[o, o, o].sort_by {|x| x }
|
||||||
c.call
|
c.call
|
||||||
end
|
end
|
||||||
|
|
||||||
|
assert_raise_with_message(RuntimeError, /reentered/) do
|
||||||
|
i = 0
|
||||||
|
c = nil
|
||||||
|
o = Object.new
|
||||||
|
class << o; self; end.class_eval do
|
||||||
|
define_method(:<=>) do |x|
|
||||||
|
callcc {|c2| c ||= c2 }
|
||||||
|
i += 1
|
||||||
|
0
|
||||||
|
end
|
||||||
|
end
|
||||||
|
[o, o].min(1)
|
||||||
|
assert_operator(i, :<=, 5, "infinite loop")
|
||||||
|
c.call
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def test_reverse_each
|
def test_reverse_each
|
||||||
|
|
Loading…
Add table
Reference in a new issue