summaryrefslogtreecommitdiff
path: root/string.c
diff options
context:
space:
mode:
authormame <mame@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2018-12-26 14:42:07 +0000
committermame <mame@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2018-12-26 14:42:07 +0000
commit0df1de8b32f98793f596fd8d3b608fc6f3104e01 (patch)
tree8711fe3fcf97a0d6ff253e1dd1a656c807fddbc5 /string.c
parent5281a0047f6f32103569372ae1a39cfadda4866c (diff)
Revert "string.c: remove the deprecation warnings of `String#bytes` with block"
Forgot to write the ticket number in the commit log... git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@66578 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'string.c')
-rw-r--r--string.c19
1 files changed, 18 insertions, 1 deletions
diff --git a/string.c b/string.c
index 118403b934..71afc98ba5 100644
--- a/string.c
+++ b/string.c
@@ -42,6 +42,8 @@
# define HAVE_CRYPT_R 1
#endif
+#define STRING_ENUMERATORS_WANTARRAY 0 /* next major */
+
#undef rb_str_new
#undef rb_usascii_str_new
#undef rb_utf8_str_new
@@ -7954,7 +7956,22 @@ rb_str_split(VALUE str, const char *sep0)
return rb_str_split_m(1, &sep, str);
}
-#define WANTARRAY(m, size) (!rb_block_given_p() ? rb_ary_new_capa(size) : 0)
+static int
+enumerator_wantarray(const char *method)
+{
+ if (rb_block_given_p()) {
+#if STRING_ENUMERATORS_WANTARRAY
+ rb_warn("given block not used");
+#else
+ rb_warning("passing a block to String#%s is deprecated", method);
+ return 0;
+#endif
+ }
+ return 1;
+}
+
+#define WANTARRAY(m, size) \
+ (enumerator_wantarray(m) ? rb_ary_new_capa(size) : 0)
static inline int
enumerator_element(VALUE ary, VALUE e)