summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authornobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2015-10-29 14:31:48 +0000
committernobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2015-10-29 14:31:48 +0000
commitd8a27d374a76c3ccde8bb7edfcb6e9a9bcd53411 (patch)
treebaf04f8dc76b7d358e38059f877b1c53de66cf82
parent78e436671a547bbee709af33662d6824586b5560 (diff)
ENC_ASSERT
* encoding.c (ENC_ASSERT): make an expression, and prevent the argument from further expansions. * encoding.c (rb_enc_check_str): assert before using. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@52359 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
-rw-r--r--encoding.c7
1 files changed, 3 insertions, 4 deletions
diff --git a/encoding.c b/encoding.c
index e94f11b6a8..4d044d1cba 100644
--- a/encoding.c
+++ b/encoding.c
@@ -19,7 +19,8 @@
#ifndef ENC_DEBUG
#define ENC_DEBUG 0
#endif
-#define ENC_ASSERT(expr) do { if (ENC_DEBUG) {assert(expr);} } while (0)
+#define ENC_ASSERT (!ENC_DEBUG)?(void)0:assert
+#define MUST_STRING(str) (ENC_ASSERT(RB_TYPE_P(str, T_STRING)), str)
#undef rb_ascii8bit_encindex
#undef rb_utf8_encindex
@@ -860,9 +861,7 @@ static rb_encoding* enc_compatible_str(VALUE str1, VALUE str2);
rb_encoding*
rb_enc_check_str(VALUE str1, VALUE str2)
{
- rb_encoding *enc = enc_compatible_str(str1, str2);
- ENC_ASSERT(TYPE(str1) == T_STRING);
- ENC_ASSERT(TYPE(str2) == T_STRING);
+ rb_encoding *enc = enc_compatible_str(MUST_STRING(str1), MUST_STRING(str2));
if (!enc)
rb_raise(rb_eEncCompatError, "incompatible character encodings: %s and %s",
rb_enc_name(rb_enc_get(str1)),