ruby-changes:68268
From: Nobuyoshi <ko1@a...>
Date: Tue, 5 Oct 2021 17:23:13 +0900 (JST)
Subject: [ruby-changes:68268] cd182c5ee1 (master): Adjust types to rb_enc_left_char_head
https://git.ruby-lang.org/ruby.git/commit/?id=cd182c5ee1 From cd182c5ee14c7a799a0ce422021d6ecb6a0b166e Mon Sep 17 00:00:00 2001 From: Nobuyoshi Nakada <nobu@r...> Date: Tue, 5 Oct 2021 17:14:29 +0900 Subject: Adjust types to rb_enc_left_char_head I dislike unnatural casts. --- include/ruby/internal/encoding/encoding.h | 2 +- string.c | 9 ++++----- 2 files changed, 5 insertions(+), 6 deletions(-) diff --git a/include/ruby/internal/encoding/encoding.h b/include/ruby/internal/encoding/encoding.h index ae2e15773d..b4274b7f55 100644 --- a/include/ruby/internal/encoding/encoding.h +++ b/include/ruby/internal/encoding/encoding.h @@ -694,7 +694,7 @@ rb_enc_prev_char(const char *s, const char *p, const char *e, const rb_encoding https://github.com/ruby/ruby/blob/trunk/include/ruby/internal/encoding/encoding.h#L694 * @return Pointer to the head of the character that contains `p`. */ static inline char * -rb_enc_left_char_head(const char *s, const void *p, const char *e, const rb_encoding *enc) +rb_enc_left_char_head(const char *s, const char *p, const char *e, const rb_encoding *enc) { const OnigUChar *us = RBIMPL_CAST((const OnigUChar *)s); const OnigUChar *up = RBIMPL_CAST((const OnigUChar *)p); diff --git a/string.c b/string.c index 4cd5f5e677..1f143853e4 100644 --- a/string.c +++ b/string.c @@ -5705,8 +5705,7 @@ rb_str_setbyte(VALUE str, VALUE index, VALUE value) https://github.com/ruby/ruby/blob/trunk/string.c#L5705 { long pos = NUM2LONG(index); long len = RSTRING_LEN(str); - char *head, *left = 0; - unsigned char *ptr; + char *ptr, *head, *left = 0; rb_encoding *enc; int cr = ENC_CODERANGE_UNKNOWN, width, nlen; @@ -5717,18 +5716,18 @@ rb_str_setbyte(VALUE str, VALUE index, VALUE value) https://github.com/ruby/ruby/blob/trunk/string.c#L5716 VALUE v = rb_to_int(value); VALUE w = rb_int_and(v, INT2FIX(0xff)); - unsigned char byte = NUM2INT(w) & 0xFF; + char byte = (char)(NUM2INT(w) & 0xFF); if (!str_independent(str)) str_make_independent(str); enc = STR_ENC_GET(str); head = RSTRING_PTR(str); - ptr = (unsigned char *)&head[pos]; + ptr = &head[pos]; if (!STR_EMBED_P(str)) { cr = ENC_CODERANGE(str); switch (cr) { case ENC_CODERANGE_7BIT: - left = (char *)ptr; + left = ptr; *ptr = byte; if (ISASCII(byte)) goto end; nlen = rb_enc_precise_mbclen(left, head+len, enc); -- cgit v1.2.1 -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/