Skip to content

Commit c9284ff

Browse files
committed
Use Encoding::BINARY for JOHAB
* A dummy encoding does not understand JOHAB anyway. * Creating an extra encoding leads to significant complexity and slowdowns in Ruby implementations: https://bugs.ruby-lang.org/issues/18949
1 parent fc939f5 commit c9284ff

File tree

2 files changed

+2
-40
lines changed

2 files changed

+2
-40
lines changed

ext/pg.c

Lines changed: 0 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -127,26 +127,6 @@ const char * const (pg_enc_pg2ruby_mapping[][2]) = {
127127
static struct st_table *enc_pg2ruby;
128128

129129

130-
/*
131-
* Look up the JOHAB encoding, creating it as a dummy encoding if it's not
132-
* already defined.
133-
*/
134-
static rb_encoding *
135-
pg_find_or_create_johab(void)
136-
{
137-
static const char * const aliases[] = { "JOHAB", "Windows-1361", "CP1361" };
138-
int enc_index;
139-
size_t i;
140-
141-
for (i = 0; i < sizeof(aliases)/sizeof(aliases[0]); ++i) {
142-
enc_index = rb_enc_find_index(aliases[i]);
143-
if (enc_index > 0) return rb_enc_from_index(enc_index);
144-
}
145-
146-
enc_index = rb_define_dummy_encoding(aliases[0]);
147-
return rb_enc_from_index(enc_index);
148-
}
149-
150130
/*
151131
* Return the given PostgreSQL encoding ID as an rb_encoding.
152132
*
@@ -187,10 +167,6 @@ pg_get_pg_encname_as_rb_encoding( const char *pg_encname )
187167
return rb_enc_find( pg_enc_pg2ruby_mapping[i][1] );
188168
}
189169

190-
/* JOHAB isn't a builtin encoding, so make up a dummy encoding if it's seen */
191-
if ( strncmp(pg_encname, "JOHAB", 5) == 0 )
192-
return pg_find_or_create_johab();
193-
194170
/* Fallthrough to ASCII-8BIT */
195171
return rb_ascii8bit_encoding();
196172
}

spec/pg/connection_spec.rb

Lines changed: 2 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1807,10 +1807,10 @@
18071807
expect( @conn.internal_encoding ).to eq( Encoding::ASCII_8BIT )
18081808
end
18091809

1810-
it "the connection should use JOHAB dummy encoding when it's set to JOHAB" do
1810+
it "the connection should use the BINARY encoding when it's set to JOHAB" do
18111811
@conn.set_client_encoding "JOHAB"
18121812
val = @conn.exec("SELECT chr(x'3391'::int)").values[0][0]
1813-
expect( val.encoding.name ).to eq( "JOHAB" )
1813+
expect( val.encoding ).to eq( Encoding::BINARY )
18141814
expect( val.unpack("H*")[0] ).to eq( "dc65" )
18151815
end
18161816

@@ -1877,20 +1877,6 @@
18771877
expect { @conn.set_client_encoding( nil ) }.to raise_error(TypeError)
18781878
end
18791879

1880-
it "can use an encoding with high index for client encoding" do
1881-
# Allocate a lot of encoding indices, so that MRI's ENCODING_INLINE_MAX is exceeded
1882-
unless Encoding.name_list.include?("pgtest-0")
1883-
256.times do |eidx|
1884-
Encoding::UTF_8.replicate("pgtest-#{eidx}")
1885-
end
1886-
end
1887-
1888-
# Now allocate the JOHAB encoding with an unusual high index
1889-
@conn.set_client_encoding "JOHAB"
1890-
val = @conn.exec("SELECT chr(x'3391'::int)").values[0][0]
1891-
expect( val.encoding.name ).to eq( "JOHAB" )
1892-
end
1893-
18941880
end
18951881

18961882
describe "respect and convert character encoding of input strings" do

0 commit comments

Comments
 (0)