Skip to content

Conversation

shyouhei
Copy link
Member

After I organise header files, this is the largest one now. I think it's a bit too large to read through. Why not split it into files.

Why did they even exist?
My bad.  The document is clearly broken.  Maybe I pressed my delete key
too much. [ci skip]
2,291 lines are too much!  include/ruby/encoding.h became the biggest
header file once it had doxygen comments.  Let us split it into smaller
parts, so that we can better organise their contents.
These functions assume ASCII compatibility.  That has to be ensured in
their caller.
Nobu doesn't like (char*) cast.
@nobu
Copy link
Member

nobu commented Oct 5, 2021

I meant

diff --git a/string.c b/string.c
index 78e2ba923f3..7c2235450d6 100644
--- a/string.c
+++ b/string.c
@@ -5706,7 +5706,7 @@ rb_str_setbyte(VALUE str, VALUE index, VALUE value)
     long pos = NUM2LONG(index);
     long len = RSTRING_LEN(str);
     char *head, *left = 0;
-    unsigned char *ptr;
+    char *ptr;
     rb_encoding *enc;
     int cr = ENC_CODERANGE_UNKNOWN, width, nlen;
 
@@ -5717,18 +5717,18 @@ rb_str_setbyte(VALUE str, VALUE index, VALUE value)
 
     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);

@shyouhei shyouhei merged commit f032c09 into ruby:master Oct 5, 2021
@shyouhei shyouhei deleted the encoding branch October 5, 2021 05:18
@shyouhei
Copy link
Member Author

shyouhei commented Oct 5, 2021

@nobu That's also okay. But ultimately, ONIGENC_LEFT_ADJUST_CHAR_HEAD operates over OnigUChar*. Using unsigned char here seems a bit more natural, to me.

@nobu
Copy link
Member

nobu commented Oct 5, 2021

But rb_enc_left_char_head does not use unsigned char.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants