summaryrefslogtreecommitdiff
path: root/enum.c
diff options
context:
space:
mode:
authornobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2017-05-30 13:12:22 (GMT)
committernobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2017-05-30 13:12:22 (GMT)
commite4cc791f87700ea6d59d358e2f688fcc85c45676 (patch)
tree32659abb3ce0c13650098010675cb6fa498c618d /enum.c
parent7cdb2840dfa66de6455a3a3034229047de54bdd1 (diff)
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
Diffstat (limited to 'enum.c')
-rw-r--r--enum.c19
1 files changed, 12 insertions, 7 deletions
diff --git a/enum.c b/enum.c
index 5c973e6..362c706 100644
--- a/enum.c
+++ b/enum.c
@@ -1263,16 +1263,24 @@ struct nmin_data {
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
nmin_cmp(const void *ap, const void *bp, void *_data)
{
struct cmp_opt_data cmp_opt = { 0, 0 };
struct nmin_data *data = (struct nmin_data *)_data;
VALUE a = *(const VALUE *)ap, b = *(const VALUE *)bp;
- if (RBASIC(data->buf)->klass) {
- rb_raise(rb_eRuntimeError, "%s reentered", data->method);
- }
+#define rb_cmpint(cmp, a, b) rb_cmpint(cmpint_reenter_check(data, (cmp)), a, b)
return OPTIMIZED_CMP(a, b, cmp_opt);
+#undef rb_cmpint
}
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;
VALUE a = *(const VALUE *)ap, b = *(const VALUE *)bp;
VALUE cmp = rb_yield_values(2, a, b);
- if (RBASIC(data->buf)->klass) {
- rb_raise(rb_eRuntimeError, "%s reentered", data->method);
- }
+ cmpint_reenter_check(data, cmp);
return rb_cmpint(cmp, a, b);
}
-
static void
nmin_filter(struct nmin_data *data)
{