Permalink
Browse files

Fix JRUBY-6572 and unexclude a bunch of passing tests.

I mostly just traced through the MRI logic for handling binary
mode and tried to match up code. There's also a few fixes to make
some of our ported logic match MRI more exactly.

We have accumulated enough fixes that test_io_m17n has many tests
working now. I removed them from excludes.
  • Loading branch information...
1 parent 5bb3172 commit 8fecee704ce6c7441fa3d907ee09113f44b89977 @headius headius committed May 16, 2012
@@ -622,12 +622,13 @@ private IRubyObject getline(Ruby runtime, ByteList separator, long limit, ByteLi
IRubyObject result = getlineInner(runtime, separator, limit, cache);
if (runtime.is1_9() && !result.isNil()) {
- Encoding internal = getInternalEncoding(runtime);
+ Encoding internal = internalEncoding;
+ Encoding external = externalEncoding;
- if (internal != null) {
+ if (internal != external) {
result = RubyString.newStringNoCopy(runtime,
RubyString.transcode(runtime.getCurrentContext(),
- ((RubyString) result).getByteList(), getExternalEncoding(runtime), internal,
+ ((RubyString) result).getByteList(), external, internal,
runtime.getNil()));
}
}
@@ -659,7 +660,7 @@ private IRubyObject getlineInner(Ruby runtime, ByteList separator, long limit, B
return str;
} else if (limit == 0) {
if (runtime.is1_9()) {
- return RubyString.newEmptyString(runtime, getExternalEncoding(runtime));
+ return RubyString.newEmptyString(runtime, externalEncoding);
} else {
return RubyString.newEmptyString(runtime);
}
@@ -626,6 +626,7 @@ public static RubyString newStringNoCopy(Ruby runtime, byte[] bytes) {
private static EmptyByteListHolder EMPTY_BYTELISTS[] = new EmptyByteListHolder[4];
static EmptyByteListHolder getEmptyByteList(Encoding enc) {
+ if (enc == null) enc = ASCIIEncoding.INSTANCE;
int index = enc.getIndex();
EmptyByteListHolder bytes;
if (index < EMPTY_BYTELISTS.length && (bytes = EMPTY_BYTELISTS[index]) != null) {
@@ -635,6 +636,7 @@ static EmptyByteListHolder getEmptyByteList(Encoding enc) {
}
private static EmptyByteListHolder prepareEmptyByteList(Encoding enc) {
+ if (enc == null) enc = ASCIIEncoding.INSTANCE;
int index = enc.getIndex();
if (index >= EMPTY_BYTELISTS.length) {
EmptyByteListHolder tmp[] = new EmptyByteListHolder[index + 4];
@@ -86,18 +86,30 @@ public static EncodingOption getEncodingOptionFromObject(IRubyObject options) {
return createEncodingOption(runtime, extEncoding, intEncoding, false);
}
+ // c: rb_io_ext_int_to_encs
private static EncodingOption createEncodingOption(Ruby runtime, Encoding extEncoding,
Encoding intEncoding, boolean isBom) {
+ boolean defaultExt = false;
if (extEncoding == null) {
extEncoding = runtime.getDefaultExternalEncoding();
+ defaultExt = true;
}
- if (intEncoding == null) {
+ if (intEncoding == null && extEncoding != ASCIIEncoding.INSTANCE) {
+ /* If external is ASCII-8BIT, no default transcoding */
intEncoding = runtime.getDefaultInternalEncoding();
}
- // NOTE: This logic used to do checks for int == ext, etc, like in rb_io_ext_int_to_encs,
- // but that logic seems specific to how MRI's IO sets up "enc" and "enc2". We explicitly separate
- // external and internal, so consumers should decide how to deal with int == ext.
- return new EncodingOption(extEncoding, intEncoding, isBom);
+ if (intEncoding == null || intEncoding == extEncoding) {
+ /* No internal encoding => use external + no transcoding */
+ return new EncodingOption(
+ null,
+ (defaultExt && intEncoding != extEncoding) ? null : extEncoding,
+ isBom);
+ } else {
+ return new EncodingOption(
+ extEncoding,
+ intEncoding,
+ isBom);
+ }
}
// c: parse_mode_enc
@@ -142,11 +154,15 @@ public static EncodingOption getEncodingNoOption(Ruby runtime, ModeFlags modeFla
if (modeFlags.isBinary()) {
return new EncodingOption(
ASCIIEncoding.INSTANCE,
- runtime.getDefaultInternalEncoding(), false);
+ null, false);
} else {
return new EncodingOption(
runtime.getDefaultExternalEncoding(),
runtime.getDefaultInternalEncoding(), false);
}
}
+
+ public String toString() {
+ return "EncodingOption(int:" + internalEncoding + ", ext:" + externalEncoding + ", bom:" + bom + ")";
+ }
}
@@ -1,63 +1,35 @@
-exclude :test_binary, "needs investigation"
exclude :test_binmode, "needs investigation"
exclude :test_binmode2, "needs investigation"
exclude :test_binmode3, "needs investigation"
exclude :test_binmode_paragraph_nonasciicompat, "needs investigation"
exclude :test_binmode_write_ascii_incompat_internal, "needs investigation"
exclude :test_both_textmode_binmode, "needs investigation"
exclude :test_cbuf, "needs investigation"
-exclude :test_cbuf_select, "needs investigation"
exclude :test_cr_decorator_on_stdout, "needs investigation"
exclude :test_crlf_decorator_on_stdout, "needs investigation"
exclude :test_dup, "needs investigation"
exclude :test_dup_undef, "needs investigation"
-exclude :test_file_foreach, "needs investigation"
-exclude :test_getc_ascii_only, "needs investigation"
+exclude :test_error_nonascii, "needs investigation"
exclude :test_getc_invalid, "needs investigation"
exclude :test_getc_invalid2, "needs investigation"
exclude :test_getc_invalid3, "needs investigation"
-exclude :test_getc_newlineconv, "needs investigation"
exclude :test_getc_newlineconv_invalid, "needs investigation"
exclude :test_getc_stateful_conversion, "needs investigation"
exclude :test_gets_invalid, "needs investigation"
exclude :test_gets_limit, "needs investigation"
-exclude :test_gets_nil, "needs investigation"
+exclude :test_inspect_nonascii, "needs investigation"
exclude :test_invalid_r, "needs investigation"
exclude :test_invalid_w, "needs investigation"
-exclude :test_io_new_enc, "needs investigation"
exclude :test_lf_decorator_on_stdout, "needs investigation"
-exclude :test_marshal, "needs investigation"
exclude :test_nonascii_terminator, "needs investigation"
-exclude :test_open_ascii, "needs investigation"
-exclude :test_open_nonascii, "needs investigation"
exclude :test_open_pipe_r_enc, "needs investigation"
exclude :test_open_pipe_r_enc2, "needs investigation"
-exclude :test_open_r, "needs investigation"
-exclude :test_open_r_enc, "needs investigation"
-exclude :test_open_r_enc_enc, "needs investigation"
-exclude :test_open_r_enc_enc_in_opt, "needs investigation"
-exclude :test_open_r_enc_in_opt, "needs investigation"
-exclude :test_open_r_encname_encname, "needs investigation"
-exclude :test_open_r_encname_encname_in_opt, "needs investigation"
exclude :test_open_r_encname_in_opt, "needs investigation"
exclude :test_open_r_ext_enc_in_opt, "needs investigation"
exclude :test_open_r_ext_encname_in_opt, "needs investigation"
-exclude :test_open_r_externalencname_internalencname_in_opt, "needs investigation"
-exclude :test_open_rb, "needs investigation"
exclude :test_open_w, "needs investigation"
-exclude :test_open_w_enc, "needs investigation"
-exclude :test_open_w_enc_enc, "needs investigation"
-exclude :test_open_w_enc_enc_in_opt, "needs investigation"
-exclude :test_open_w_enc_enc_in_opt2, "needs investigation"
-exclude :test_open_w_enc_enc_perm, "needs investigation"
-exclude :test_open_w_enc_in_opt, "needs investigation"
exclude :test_open_w_enc_in_opt2, "needs investigation"
-exclude :test_open_wb, "needs investigation"
exclude :test_pipe, "needs investigation"
-exclude :test_pipe_conversion, "needs investigation"
-exclude :test_pipe_convert_partial_read, "needs investigation"
-exclude :test_pipe_terminator_conversion, "needs investigation"
-exclude :test_popen_r_enc, "needs investigation"
exclude :test_popen_r_enc_enc, "needs investigation"
exclude :test_popen_r_enc_enc_in_opt, "needs investigation"
exclude :test_popen_r_enc_enc_in_opt2, "needs investigation"
@@ -67,17 +39,10 @@
exclude :test_puts_widechar, "needs investigation"
exclude :test_read_all, "needs investigation"
exclude :test_read_all_invalid, "needs investigation"
-exclude :test_read_encoding, "needs investigation"
exclude :test_read_mode, "needs investigation"
exclude :test_read_newline_conversion_error, "needs investigation"
exclude :test_read_newline_conversion_with_encoding_conversion, "needs investigation"
-exclude :test_read_newline_conversion_without_encoding_conversion, "needs investigation"
exclude :test_read_stateful, "needs investigation"
-exclude :test_s_foreach_enc, "needs investigation"
-exclude :test_s_foreach_enc_enc, "needs investigation"
-exclude :test_s_foreach_enc_enc_in_opt, "needs investigation"
-exclude :test_s_foreach_enc_enc_in_opt2, "needs investigation"
-exclude :test_s_foreach_enc_in_opt, "needs investigation"
exclude :test_s_foreach_enc_in_opt2, "needs investigation"
exclude :test_s_foreach_open_args_enc, "needs investigation"
exclude :test_s_foreach_open_args_enc_enc, "needs investigation"
@@ -88,18 +53,13 @@
exclude :test_s_pipe_invalid, "needs investigation"
exclude :test_s_pipe_undef, "needs investigation"
exclude :test_s_pipe_undef_replace_string, "needs investigation"
-exclude :test_set_encoding, "needs investigation"
-exclude :test_set_encoding2, "needs investigation"
exclude :test_set_encoding_binmode, "needs investigation"
exclude :test_set_encoding_enc, "needs investigation"
exclude :test_set_encoding_invalid, "needs investigation"
-exclude :test_set_encoding_nil, "needs investigation"
exclude :test_set_encoding_undef, "needs investigation"
exclude :test_set_encoding_undef_replace, "needs investigation"
exclude :test_stdin, "needs investigation"
exclude :test_stdin_external_encoding_with_reopen, "needs investigation"
-exclude :test_strip_bom, "needs investigation"
-exclude :test_terminator_conversion, "needs investigation"
exclude :test_terminator_conversion2, "needs investigation"
exclude :test_terminator_stateful_conversion, "needs investigation"
exclude :test_text_mode, "needs investigation"
@@ -108,7 +68,6 @@
exclude :test_textmode_decode_universal_newline_gets, "needs investigation"
exclude :test_textmode_decode_universal_newline_read, "needs investigation"
exclude :test_textmode_decode_universal_newline_utf16, "needs investigation"
-exclude :test_textmode_encode_newline, "needs investigation"
exclude :test_textmode_encode_newline_enc, "needs investigation"
exclude :test_textmode_paragraph_binaryread, "needs investigation"
exclude :test_textmode_paragraph_nonasciicompat, "needs investigation"
@@ -121,14 +80,9 @@
exclude :test_ungetc_stateful_conversion2, "needs investigation"
exclude :test_ungetc_str, "needs investigation"
exclude :test_w_xml_attr, "needs investigation"
-exclude :test_write_ascii_incompat, "needs investigation"
exclude :test_write_conversion, "needs investigation"
exclude :test_write_conversion_anyenc_stateful, "needs investigation"
exclude :test_write_conversion_anyenc_stateful_nosync, "needs investigation"
exclude :test_write_conversion_anyenc_stateless, "needs investigation"
exclude :test_write_conversion_fixenc, "needs investigation"
exclude :test_write_mode, "needs investigation"
-exclude :test_write_mode_fail, "needs investigation"
-exclude :test_write_noenc, "needs investigation"
-exclude :test_error_nonascii, "needs investigation"
-exclude :test_inspect_nonascii, "needs investigation"

0 comments on commit 8fecee7

Please sign in to comment.