Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

split encoding.h #4909

Merged
merged 7 commits into from
Oct 5, 2021
Merged

split encoding.h #4909

merged 7 commits into from
Oct 5, 2021

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.
string.c Outdated Show resolved Hide resolved
string.c Outdated Show resolved Hide resolved
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
2 participants