Skip to content

Commit 1f3c52d

Browse files
committed
Fix rb_interned_str: create strings with BINARY (akak ASCII_8BIT) encoding
[Bug #21842] The documentation always stated as much, and it's consistent with the rb_str_* family of functions.
1 parent c56ce8a commit 1f3c52d

File tree

5 files changed

+10
-10
lines changed

5 files changed

+10
-10
lines changed

encoding.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1367,7 +1367,7 @@ enc_names_i(st_data_t name, st_data_t idx, st_data_t args)
13671367
VALUE *arg = (VALUE *)args;
13681368

13691369
if ((int)idx == (int)arg[0]) {
1370-
VALUE str = rb_interned_str_cstr((char *)name);
1370+
VALUE str = rb_enc_interned_str_cstr((char *)name, rb_usascii_encoding());
13711371
rb_ary_push(arg[1], str);
13721372
}
13731373
return ST_CONTINUE;
@@ -1873,7 +1873,7 @@ static int
18731873
rb_enc_name_list_i(st_data_t name, st_data_t idx, st_data_t arg)
18741874
{
18751875
VALUE ary = (VALUE)arg;
1876-
VALUE str = rb_interned_str_cstr((char *)name);
1876+
VALUE str = rb_enc_interned_str_cstr((char *)name, rb_usascii_encoding());
18771877
rb_ary_push(ary, str);
18781878
return ST_CONTINUE;
18791879
}
@@ -1921,7 +1921,7 @@ rb_enc_aliases_enc_i(st_data_t name, st_data_t orig, st_data_t arg)
19211921
str = rb_fstring_cstr(rb_enc_name(enc));
19221922
rb_ary_store(ary, idx, str);
19231923
}
1924-
key = rb_interned_str_cstr((char *)name);
1924+
key = rb_enc_interned_str_cstr((char *)name, rb_usascii_encoding());
19251925
rb_hash_aset(aliases, key, str);
19261926
return ST_CONTINUE;
19271927
}

ext/io/console/console.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -84,9 +84,9 @@ getattr(int fd, conmode *t)
8484
static ID id_getc, id_close;
8585
static ID id_gets, id_flush, id_chomp_bang;
8686

87-
#ifndef HAVE_RB_INTERNED_STR_CSTR
87+
#ifndef HAVE_RB_ENC_INTERNED_STR_CSTR
8888
# define rb_str_to_interned_str(str) rb_str_freeze(str)
89-
# define rb_interned_str_cstr(str) rb_str_freeze(rb_usascii_str_new_cstr(str))
89+
# define rb_enc_interned_str_cstr(str, enc) rb_str_freeze(rb_usascii_str_new_cstr(str))
9090
#endif
9191

9292
#if defined HAVE_RUBY_FIBER_SCHEDULER_H
@@ -1897,7 +1897,7 @@ console_ttyname(VALUE io)
18971897
size_t size = sizeof(termname);
18981898
int e;
18991899
if (ttyname_r(fd, tn, size) == 0)
1900-
return rb_interned_str_cstr(tn);
1900+
return rb_enc_interned_str_cstr(tn, rb_usascii_encoding());
19011901
if ((e = errno) == ERANGE) {
19021902
VALUE s = rb_str_new(0, size);
19031903
while (1) {
@@ -1921,7 +1921,7 @@ console_ttyname(VALUE io)
19211921
int e = errno;
19221922
rb_syserr_fail_str(e, rb_sprintf("ttyname(%d)", fd));
19231923
}
1924-
return rb_interned_str_cstr(tn);
1924+
return rb_enc_interned_str_cstr(tn, rb_usascii_encoding());
19251925
}
19261926
# else
19271927
# error No ttyname function

ext/io/console/extconf.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
have_func("rb_syserr_new_str(0, Qnil)") or
1010
abort
1111

12-
have_func("rb_interned_str_cstr")
12+
have_func("rb_enc_interned_str_cstr")
1313
have_func("rb_io_path", "ruby/io.h")
1414
have_func("rb_io_descriptor", "ruby/io.h")
1515
have_func("rb_io_get_write_io", "ruby/io.h")

gc/default/default.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9582,7 +9582,7 @@ rb_gc_impl_init(void)
95829582
VALUE opts;
95839583
/* \GC build options */
95849584
rb_define_const(rb_mGC, "OPTS", opts = rb_ary_new());
9585-
#define OPT(o) if (o) rb_ary_push(opts, rb_interned_str(#o, sizeof(#o) - 1))
9585+
#define OPT(o) if (o) rb_ary_push(opts, rb_enc_interned_str(#o, sizeof(#o) - 1, rb_usascii_encoding()))
95869586
OPT(GC_DEBUG);
95879587
OPT(USE_RGENGC);
95889588
OPT(RGENGC_DEBUG);

string.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12709,7 +12709,7 @@ VALUE
1270912709
rb_interned_str(const char *ptr, long len)
1271012710
{
1271112711
struct RString fake_str = {RBASIC_INIT};
12712-
return register_fstring(setup_fake_str(&fake_str, ptr, len, ENCINDEX_US_ASCII), true, false);
12712+
return register_fstring(setup_fake_str(&fake_str, ptr, len, ENCINDEX_ASCII_8BIT), true, false);
1271312713
}
1271412714

1271512715
VALUE

0 commit comments

Comments
 (0)