-
-
Notifications
You must be signed in to change notification settings - Fork 925
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #2765 from jruby/truffle_encoding
Truffle encoding
- 9.4.12.0
- 9.4.11.0
- 9.4.10.0
- 9.4.9.0
- 9.4.8.0
- 9.4.7.0
- 9.4.6.0
- 9.4.5.0
- 9.4.4.0
- 9.4.3.0
- 9.4.2.0
- 9.4.1.0
- 9.4.0.0
- 9.3.15.0
- 9.3.14.0
- 9.3.13.0
- 9.3.12.0
- 9.3.11.0
- 9.3.10.0
- 9.3.9.0
- 9.3.8.0
- 9.3.7.0
- 9.3.6.0
- 9.3.5.0
- 9.3.4.0
- 9.3.3.0
- 9.3.2.0
- 9.3.1.0
- 9.3.0.0
- 9.2.21.0
- 9.2.20.1
- 9.2.20.0
- 9.2.19.0
- 9.2.18.0
- 9.2.17.0
- 9.2.16.0
- 9.2.15.0
- 9.2.14.0
- 9.2.13.0
- 9.2.12.0
- 9.2.11.1
- 9.2.11.0
- 9.2.10.0
- 9.2.9.0
- 9.2.8.0
- 9.2.7.0
- 9.2.6.0
- 9.2.5.0
- 9.2.4.1
- 9.2.4.0
- 9.2.3.0
- 9.2.2.0
- 9.2.1.0
- 9.2.0.0
- 9.1.17.0
- 9.1.16.0
- 9.1.15.0
- 9.1.14.0
- 9.1.13.0
- 9.1.12.0
- 9.1.11.0
- 9.1.10.0
- 9.1.9.0
- 9.1.8.0
- 9.1.7.0
- 9.1.6.0
- 9.1.5.0
- 9.1.4.0
- 9.1.3.0
- 9.1.2.0
- 9.1.1.0
- 9.1.0.0
- 9.0.5.0
- 9.0.4.0
- 9.0.3.0
- 9.0.1.0
- 9.0.0.0
- 9.0.0.0.rc2
- 9.0.0.0.rc1
- 9.0.0.0.pre2
Showing
41 changed files
with
8,909 additions
and
564 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
5 changes: 0 additions & 5 deletions
5
spec/truffle/tags/core/encoding/converter/asciicompat_encoding_tags.txt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1 @@ | ||
fails:Encoding::Converter.asciicompat_encoding accepts an encoding name as a String argument | ||
fails:Encoding::Converter.asciicompat_encoding coerces non-String/Encoding objects with #to_str | ||
fails:Encoding::Converter.asciicompat_encoding accepts an Encoding object as an argument | ||
fails:Encoding::Converter.asciicompat_encoding returns a corresponding ASCII compatible encoding for ASCII-incompatible encodings | ||
fails:Encoding::Converter.asciicompat_encoding returns nil when the given encoding is ASCII compatible | ||
fails:Encoding::Converter.asciicompat_encoding handles encoding names who resolve to nil encodings |
26 changes: 0 additions & 26 deletions
26
spec/truffle/tags/core/encoding/converter/constants_tags.txt
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,2 @@ | ||
fails:Encoding::Converter#convert returns a String | ||
fails:Encoding::Converter#convert sets the encoding of the result to the target encoding | ||
fails:Encoding::Converter#convert transcodes the given String to the target encoding | ||
fails:Encoding::Converter#convert allows Strings of different encodings to the source encoding | ||
fails:Encoding::Converter#convert reuses the given encoding pair if called multiple times | ||
fails:Encoding::Converter#convert raises UndefinedConversionError if the String contains characters invalid for the target encoding | ||
fails:Encoding::Converter#convert raises an ArgumentError if called on a finished stream |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
1 change: 0 additions & 1 deletion
1
spec/truffle/tags/core/encoding/converter/destination_encoding_tags.txt
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1 @@ | ||
fails:Encoding::Converter#inspect needs to be reviewed for spec completeness | ||
fails:Encoding::Converter#inspect includes the source and destination encodings in the return value |
4 changes: 0 additions & 4 deletions
4
spec/truffle/tags/core/encoding/converter/last_error_tags.txt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,19 +1,2 @@ | ||
fails:Encoding::Converter.new accepts a String for the source encoding | ||
fails:Encoding::Converter.new accepts a String for the destination encoding | ||
fails:Encoding::Converter.new accepts an Encoding object for the source encoding | ||
fails:Encoding::Converter.new accepts an Encoding object for the destination encoding | ||
fails:Encoding::Converter.new raises an Encoding::ConverterNotFoundError if both encodings are the same | ||
fails:Encoding::Converter.new calls #to_str to convert the source encoding argument to an encoding name | ||
fails:Encoding::Converter.new calls #to_str to convert the destination encoding argument to an encoding name | ||
fails:Encoding::Converter.new sets replacement from the options Hash | ||
fails:Encoding::Converter.new calls #to_hash to convert the options argument to a Hash if not a Fixnum | ||
fails:Encoding::Converter.new calls #to_str to convert the replacement object to a String | ||
fails:Encoding::Converter.new raises a TypeError if #to_str does not return a String | ||
fails:Encoding::Converter.new raises a TypeError if passed true for the replacement object | ||
fails:Encoding::Converter.new raises a TypeError if passed false for the replacement object | ||
fails:Encoding::Converter.new raises a TypeError if passed a Fixnum for the replacement object | ||
fails:Encoding::Converter.new accepts an empty String for the replacement object | ||
fails:Encoding::Converter.new when passed nil for the replacement object when the destination encoding is not UTF-8 sets the replacement String to '?' | ||
fails:Encoding::Converter.new when passed nil for the replacement object when the destination encoding is not UTF-8 sets the replacement String encoding to US-ASCII | ||
fails:Encoding::Converter.new when passed nil for the replacement object when the destination encoding is not UTF-8 sets the replacement String to '\uFFFD' | ||
fails:Encoding::Converter.new when passed nil for the replacement object when the destination encoding is not UTF-8 sets the replacement String encoding to UTF-8 |
27 changes: 0 additions & 27 deletions
27
spec/truffle/tags/core/encoding/converter/primitive_convert_tags.txt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,31 +1,4 @@ | ||
fails:Encoding::Converter#primitive_convert accepts a nil source buffer | ||
fails:Encoding::Converter#primitive_convert accepts a String as the source buffer | ||
fails:Encoding::Converter#primitive_convert accepts nil for the destination byte offset | ||
fails:Encoding::Converter#primitive_convert accepts an integer for the destination byte offset | ||
fails:Encoding::Converter#primitive_convert calls #to_int to convert the destination byte offset | ||
fails:Encoding::Converter#primitive_convert raises an ArgumentError if the destination byte offset is greater than the bytesize of the destination buffer | ||
fails:Encoding::Converter#primitive_convert uses the destination byte offset to determine where to write the result in the destination buffer | ||
fails:Encoding::Converter#primitive_convert accepts nil for the destination bytesize | ||
fails:Encoding::Converter#primitive_convert accepts an integer for the destination bytesize | ||
fails:Encoding::Converter#primitive_convert allows a destination bytesize value greater than the bytesize of the source buffer | ||
fails:Encoding::Converter#primitive_convert allows a destination bytesize value less than the bytesize of the source buffer | ||
fails:Encoding::Converter#primitive_convert calls #to_int to convert the destination byte size | ||
fails:Encoding::Converter#primitive_convert uses destination bytesize as the maximumn bytesize of the destination buffer | ||
fails:Encoding::Converter#primitive_convert allows a destination buffer of unlimited size if destination bytesize is nil | ||
fails:Encoding::Converter#primitive_convert accepts an options hash | ||
fails:Encoding::Converter#primitive_convert sets the destination buffer's encoding to the destination encoding if the conversion suceeded | ||
fails:Encoding::Converter#primitive_convert sets the destination buffer's encoding to the destination encoding if the conversion failed | ||
fails:Encoding::Converter#primitive_convert removes the undefined part from the source buffer when returning :undefined_conversion | ||
fails:Encoding::Converter#primitive_convert returns :incomplete_input when source buffer ends unexpectedly and :partial_input isn't specified | ||
fails:Encoding::Converter#primitive_convert clears the source buffer when returning :incomplete_input | ||
fails:Encoding::Converter#primitive_convert returns :source_buffer_empty when source buffer ends unexpectedly and :partial_input is true | ||
fails:Encoding::Converter#primitive_convert clears the source buffer when returning :source_buffer_empty | ||
fails:Encoding::Converter#primitive_convert returns :undefined_conversion when a character in the source buffer is not representable in the output encoding | ||
fails:Encoding::Converter#primitive_convert returns :invalid_byte_sequence when an invalid byte sequence was found in the source buffer | ||
fails:Encoding::Converter#primitive_convert removes consumed and erroneous bytes from the source buffer when returning :invalid_byte_sequence | ||
fails:Encoding::Converter#primitive_convert returns :finished when the conversion succeeded | ||
fails:Encoding::Converter#primitive_convert clears the source buffer when returning :finished | ||
fails:Encoding::Converter#primitive_convert returns :destination_buffer_full when the destination buffer is too small | ||
fails:Encoding::Converter#primitive_convert clears the source buffer when returning :destination_buffer_full | ||
fails:Encoding::Converter#primitive_convert keeps removing invalid bytes from the source buffer | ||
fails:Encoding::Converter#primitive_convert reuses read-again bytes after the first error |
7 changes: 0 additions & 7 deletions
7
spec/truffle/tags/core/encoding/converter/primitive_errinfo_tags.txt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,3 @@ | ||
fails:Encoding::Converter#primitive_errinfo returns [:source_buffer_empty,nil,nil,nil,nil] when no conversion has been attempted | ||
fails:Encoding::Converter#primitive_errinfo returns [:finished,nil,nil,nil,nil] when #primitive_convert last returned :finished | ||
fails:Encoding::Converter#primitive_errinfo returns [:source_buffer_empty,nil,nil,nil, nil] when #convert last succeeded | ||
fails:Encoding::Converter#primitive_errinfo returns [:destination_buffer_full,nil,nil,nil,nil] when #primitive_convert last returned :destination_buffer_full | ||
fails:Encoding::Converter#primitive_errinfo returns the status of the last primitive conversion, even if it was successful and the previous one wasn't | ||
fails:Encoding::Converter#primitive_errinfo returns the state, source encoding, target encoding, and the erroneous bytes when #primitive_convert last returned :undefined_conversion | ||
fails:Encoding::Converter#primitive_errinfo returns the state, source encoding, target encoding, and erroneous bytes when #primitive_convert last returned :incomplete_input | ||
fails:Encoding::Converter#primitive_errinfo returns the state, source encoding, target encoding, erroneous bytes, and the read-again bytes when #primitive_convert last returned :invalid_byte_sequence | ||
fails:Encoding::Converter#primitive_errinfo returns the state, source encoding, target encoding, erroneous bytes, and the read-again bytes when #convert last raised InvalidByteSequenceError | ||
fails:Encoding::Converter#primitive_errinfo returns the state, source encoding, target encoding, erroneous bytes, and the read-again bytes when #finish last raised InvalidByteSequenceError |
6 changes: 0 additions & 6 deletions
6
spec/truffle/tags/core/encoding/converter/replacement_tags.txt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,2 @@ | ||
fails:Encoding::Converter#replacement returns '?' in US-ASCII when the destination encoding is not UTF-8 | ||
fails:Encoding::Converter#replacement returns \uFFFD when the destination encoding is UTF-8 | ||
fails:Encoding::Converter#replacement= accepts a String argument | ||
fails:Encoding::Converter#replacement= accepts a String argument of arbitrary length | ||
fails:Encoding::Converter#replacement= raises a TypeError if assigned a non-String argument | ||
fails:Encoding::Converter#replacement= sets #replacement | ||
fails:Encoding::Converter#replacement= raises an UndefinedConversionError is the argument cannot be converted into the destination encoding | ||
fails:Encoding::Converter#replacement= does not change the replacement character if the argument cannot be converted into the destination encoding |
3 changes: 0 additions & 3 deletions
3
spec/truffle/tags/core/encoding/converter/search_convpath_tags.txt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
1 change: 0 additions & 1 deletion
1
spec/truffle/tags/core/encoding/converter/source_encoding_tags.txt
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
2 changes: 0 additions & 2 deletions
2
spec/truffle/tags/core/encoding/invalid_byte_sequence_error/incomplete_input_tags.txt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1 @@ | ||
fails:Encoding::InvalidByteSequenceError#incomplete_input? returns nil by default | ||
fails:Encoding::InvalidByteSequenceError#incomplete_input? returns true if #primitive_convert returned :incomplete_input for the same data | ||
fails:Encoding::InvalidByteSequenceError#incomplete_input? returns false if #primitive_convert returned :invalid_byte_sequence for the same data |
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,79 +1,16 @@ | ||
fails:String#encode when passed no options transcodes a 7-bit String despite no generic converting being available | ||
fails:String#encode when passed no options raises an Encoding::ConverterNotFoundError when no conversion is possible | ||
fails:String#encode when passed to encoding transcodes a 7-bit String despite no generic converting being available | ||
fails:String#encode when passed to encoding raises an Encoding::ConverterNotFoundError when no conversion is possible | ||
fails:String#encode when passed to encoding raises an Encoding::ConverterNotFoundError for an invalid encoding | ||
fails:String#encode when passed options does not process transcoding options if not transcoding | ||
fails:String#encode when passed options calls #to_hash to convert the object | ||
fails:String#encode when passed options transcodes to Encoding.default_internal when set | ||
fails:String#encode when passed options raises an Encoding::ConverterNotFoundError when no conversion is possible despite ':invalid => :replace, :undef => :replace' | ||
fails:String#encode when passed to, from transcodes between the encodings ignoring the String encoding | ||
fails:String#encode when passed to, from calls #to_str to convert the from object to an Encoding | ||
fails:String#encode when passed to, options replaces undefined characters in the destination encoding | ||
fails:String#encode when passed to, options replaces invalid characters in the destination encoding | ||
fails:String#encode when passed to, options calls #to_hash to convert the options object | ||
fails:String#encode when passed to, from, options replaces undefined characters in the destination encoding | ||
fails:String#encode when passed to, from, options replaces invalid characters in the destination encoding | ||
fails:String#encode when passed to, from, options calls #to_str to convert the to object to an encoding | ||
fails:String#encode when passed to, from, options calls #to_str to convert the from object to an encoding | ||
fails:String#encode when passed to, from, options calls #to_hash to convert the options object | ||
fails:String#encode given the :xml => :text option replaces all instances of '&' with '&' | ||
fails:String#encode given the :xml => :text option replaces all instances of '<' with '<' | ||
fails:String#encode given the :xml => :text option replaces all instances of '>' with '>' | ||
fails:String#encode given the :xml => :text option replaces undefined characters with their upper-case hexadecimal numeric character references | ||
fails:String#encode given the :xml => :attr option surrounds the encoded text with double-quotes | ||
fails:String#encode given the :xml => :attr option replaces all instances of '&' with '&' | ||
fails:String#encode given the :xml => :attr option replaces all instances of '<' with '<' | ||
fails:String#encode given the :xml => :attr option replaces all instances of '>' with '>' | ||
fails:String#encode given the :xml => :attr option replaces all instances of '"' with '"' | ||
fails:String#encode given the :xml => :attr option replaces undefined characters with their upper-case hexadecimal numeric character references | ||
fails:String#encode when passed options returns a copy when Encoding.default_internal is nil | ||
fails:String#encode when passed options normalizes newlines | ||
fails:String#encode when passed to, from returns a copy when both encodings are the same | ||
fails:String#encode when passed to, from returns the transcoded string | ||
fails:String#encode when passed to, options returns a copy when the destination encoding is the same as the String encoding | ||
fails:String#encode when passed to, from, options returns a copy when both encodings are the same | ||
fails:String#encode! raises ArgumentError if the value of the :xml option is not :text or :attr | ||
fails:String#encode! raises a RuntimeError when called on a frozen String | ||
fails:String#encode! raises a RuntimeError when called on a frozen String when it's a no-op | ||
fails:String#encode! when passed no options transcodes to Encoding.default_internal when set | ||
fails:String#encode! when passed no options transcodes a 7-bit String despite no generic converting being available | ||
fails:String#encode! when passed no options raises an Encoding::ConverterNotFoundError when no conversion is possible | ||
fails:String#encode! when passed to encoding accepts a String argument | ||
fails:String#encode! when passed to encoding calls #to_str to convert the object to an Encoding | ||
fails:String#encode! when passed to encoding transcodes to the passed encoding | ||
fails:String#encode! when passed to encoding transcodes Japanese multibyte characters | ||
fails:String#encode! when passed to encoding transcodes a 7-bit String despite no generic converting being available | ||
fails:String#encode! when passed to encoding raises an Encoding::ConverterNotFoundError when no conversion is possible | ||
fails:String#encode! when passed to encoding raises an Encoding::ConverterNotFoundError for an invalid encoding | ||
fails:String#encode! when passed options does not process transcoding options if not transcoding | ||
fails:String#encode! when passed options calls #to_hash to convert the object | ||
fails:String#encode! when passed options transcodes to Encoding.default_internal when set | ||
fails:String#encode! when passed options raises an Encoding::ConverterNotFoundError when no conversion is possible despite ':invalid => :replace, :undef => :replace' | ||
fails:String#encode! when passed to, from transcodes between the encodings ignoring the String encoding | ||
fails:String#encode! when passed to, from calls #to_str to convert the from object to an Encoding | ||
fails:String#encode! when passed to, options replaces undefined characters in the destination encoding | ||
fails:String#encode! when passed to, options replaces invalid characters in the destination encoding | ||
fails:String#encode! when passed to, options calls #to_hash to convert the options object | ||
fails:String#encode! when passed to, from, options replaces undefined characters in the destination encoding | ||
fails:String#encode! when passed to, from, options replaces invalid characters in the destination encoding | ||
fails:String#encode! when passed to, from, options calls #to_str to convert the to object to an encoding | ||
fails:String#encode! when passed to, from, options calls #to_str to convert the from object to an encoding | ||
fails:String#encode! when passed to, from, options calls #to_hash to convert the options object | ||
fails:String#encode! given the :xml => :text option replaces all instances of '&' with '&' | ||
fails:String#encode! given the :xml => :text option replaces all instances of '<' with '<' | ||
fails:String#encode! given the :xml => :text option replaces all instances of '>' with '>' | ||
fails:String#encode! given the :xml => :text option does not replace '"' | ||
fails:String#encode! given the :xml => :text option replaces undefined characters with their upper-case hexadecimal numeric character references | ||
fails:String#encode! given the :xml => :attr option surrounds the encoded text with double-quotes | ||
fails:String#encode! given the :xml => :attr option replaces all instances of '&' with '&' | ||
fails:String#encode! given the :xml => :attr option replaces all instances of '<' with '<' | ||
fails:String#encode! given the :xml => :attr option replaces all instances of '>' with '>' | ||
fails:String#encode! given the :xml => :attr option replaces all instances of '"' with '"' | ||
fails:String#encode! given the :xml => :attr option replaces undefined characters with their upper-case hexadecimal numeric character references | ||
fails:String#encode! when passed no options returns self when Encoding.default_internal is nil | ||
fails:String#encode! when passed no options returns self for a ASCII-only String when Encoding.default_internal is nil | ||
fails:String#encode! when passed options returns self for ASCII-only String when Encoding.default_internal is nil | ||
fails:String#encode! when passed to encoding returns self | ||
fails:String#encode! when passed to, from returns self | ||
fails:String#encode raises ArgumentError if the value of the :xml option is not :text or :attr | ||
fails:String#encode when passed to encoding transcodes Japanese multibyte characters |
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
239 changes: 239 additions & 0 deletions
239
truffle/src/main/java/org/jruby/truffle/nodes/rubinius/EncodingConverterPrimitiveNodes.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,239 @@ | ||
/* | ||
* Copyright (c) 2015 Oracle and/or its affiliates. All rights reserved. This | ||
* code is released under a tri EPL/GPL/LGPL license. You can use it, | ||
* redistribute it and/or modify it under the terms of the: | ||
* | ||
* Eclipse Public License version 1.0 | ||
* GNU General Public License version 2 | ||
* GNU Lesser General Public License version 2.1 | ||
* | ||
* Contains code modified from JRuby's RubyConverter.java | ||
*/ | ||
package org.jruby.truffle.nodes.rubinius; | ||
|
||
import com.oracle.truffle.api.dsl.Specialization; | ||
import com.oracle.truffle.api.source.SourceSection; | ||
import org.jcodings.Encoding; | ||
import org.jcodings.Ptr; | ||
import org.jcodings.transcode.EConv; | ||
import org.jcodings.transcode.EConvResult; | ||
import org.jruby.Ruby; | ||
import org.jruby.runtime.builtin.IRubyObject; | ||
import org.jruby.truffle.runtime.RubyContext; | ||
import org.jruby.truffle.runtime.control.RaiseException; | ||
import org.jruby.truffle.runtime.core.RubyArray; | ||
import org.jruby.truffle.runtime.core.RubyBasicObject; | ||
import org.jruby.truffle.runtime.core.RubyEncoding; | ||
import org.jruby.truffle.runtime.core.RubyEncodingConverter; | ||
import org.jruby.truffle.runtime.core.RubyException; | ||
import org.jruby.truffle.runtime.core.RubyHash; | ||
import org.jruby.truffle.runtime.core.RubyString; | ||
import org.jruby.util.ByteList; | ||
import org.jruby.util.io.EncodingUtils; | ||
|
||
/** | ||
* Rubinius primitives associated with the Ruby {@code Encoding::Converter} class.. | ||
*/ | ||
public abstract class EncodingConverterPrimitiveNodes { | ||
|
||
@RubiniusPrimitive(name = "encoding_converter_allocate") | ||
public static abstract class EncodingConverterAllocateNode extends RubiniusPrimitiveNode { | ||
|
||
public EncodingConverterAllocateNode(RubyContext context, SourceSection sourceSection) { | ||
super(context, sourceSection); | ||
} | ||
|
||
public EncodingConverterAllocateNode(EncodingConverterAllocateNode prev) { | ||
super(prev); | ||
} | ||
|
||
@Specialization | ||
public Object encodingConverterAllocate(RubyEncoding fromEncoding, RubyEncoding toEncoding, RubyHash options) { | ||
return new RubyEncodingConverter(getContext().getCoreLibrary().getEncodingConverterClass(), null); | ||
} | ||
|
||
} | ||
|
||
@RubiniusPrimitive(name = "encoding_converter_primitive_convert") | ||
public static abstract class EncodingConverterPrimitiveConvertNode extends RubiniusPrimitiveNode { | ||
|
||
public EncodingConverterPrimitiveConvertNode(RubyContext context, SourceSection sourceSection) { | ||
super(context, sourceSection); | ||
} | ||
|
||
public EncodingConverterPrimitiveConvertNode(EncodingConverterPrimitiveConvertNode prev) { | ||
super(prev); | ||
} | ||
|
||
@Specialization | ||
public Object encodingConverterPrimitiveConvert(RubyEncodingConverter encodingConverter, RubyString source, | ||
RubyString target, int offset, int size, RubyHash options) { | ||
throw new UnsupportedOperationException("not implemented"); | ||
} | ||
|
||
@Specialization | ||
public Object encodingConverterPrimitiveConvert(RubyEncodingConverter encodingConverter, RubyString source, | ||
RubyString target, int offset, int size, int options) { | ||
|
||
// Taken from org.jruby.RubyConverter#primitive_convert. | ||
|
||
source.modify(); | ||
source.clearCodeRange(); | ||
|
||
target.modify(); | ||
target.clearCodeRange(); | ||
|
||
final ByteList inBytes = source.getByteList(); | ||
final ByteList outBytes = target.getByteList(); | ||
|
||
final Ptr inPtr = new Ptr(); | ||
final Ptr outPtr = new Ptr(); | ||
|
||
final EConv ec = encodingConverter.getEConv(); | ||
|
||
final boolean changeOffset = (offset == 0); | ||
final boolean growOutputBuffer = (size == -1); | ||
|
||
if (size == -1) { | ||
size = 16; // in MRI, this is RSTRING_EMBED_LEN_MAX | ||
|
||
if (size < source.getByteList().getRealSize()) { | ||
size = source.getByteList().getRealSize(); | ||
} | ||
} | ||
|
||
while (true) { | ||
|
||
if (changeOffset) { | ||
offset = outBytes.getRealSize(); | ||
} | ||
|
||
if (outBytes.getRealSize() < offset) { | ||
throw new RaiseException( | ||
getContext().getCoreLibrary().argumentError("output offset too big", this) | ||
); | ||
} | ||
|
||
long outputByteEnd = offset + size; | ||
|
||
if (outputByteEnd > Integer.MAX_VALUE) { | ||
// overflow check | ||
throw new RaiseException( | ||
getContext().getCoreLibrary().argumentError("output offset + bytesize too big", this) | ||
); | ||
} | ||
|
||
outBytes.ensure((int)outputByteEnd); | ||
|
||
inPtr.p = inBytes.getBegin(); | ||
outPtr.p = outBytes.getBegin() + offset; | ||
int os = outPtr.p + size; | ||
EConvResult res = ec.convert(inBytes.getUnsafeBytes(), inPtr, inBytes.getRealSize() + inPtr.p, outBytes.getUnsafeBytes(), outPtr, os, options); | ||
|
||
outBytes.setRealSize(outPtr.p - outBytes.begin()); | ||
|
||
source.getByteList().setRealSize(inBytes.getRealSize() - (inPtr.p - inBytes.getBegin())); | ||
source.getByteList().setBegin(inPtr.p); | ||
|
||
if (growOutputBuffer && res == EConvResult.DestinationBufferFull) { | ||
if (Integer.MAX_VALUE / 2 < size) { | ||
throw new RaiseException( | ||
getContext().getCoreLibrary().argumentError("too long conversion result", this) | ||
); | ||
} | ||
size *= 2; | ||
continue; | ||
} | ||
|
||
if (ec.destinationEncoding != null) { | ||
outBytes.setEncoding(ec.destinationEncoding); | ||
} | ||
|
||
return getContext().newSymbol(res.symbolicName()); | ||
} | ||
} | ||
|
||
} | ||
|
||
@RubiniusPrimitive(name = "encoding_converter_putback") | ||
public static abstract class EncodingConverterPutbackNode extends RubiniusPrimitiveNode { | ||
|
||
public EncodingConverterPutbackNode(RubyContext context, SourceSection sourceSection) { | ||
super(context, sourceSection); | ||
} | ||
|
||
public EncodingConverterPutbackNode(EncodingConverterPutbackNode prev) { | ||
super(prev); | ||
} | ||
|
||
@Specialization | ||
public Object encodingConverterPutback(RubyBasicObject encodingConverter, int maxBytes) { | ||
throw new UnsupportedOperationException("not implemented"); | ||
} | ||
|
||
} | ||
|
||
@RubiniusPrimitive(name = "encoding_converter_last_error") | ||
public static abstract class EncodingConverterLastErrorNode extends RubiniusPrimitiveNode { | ||
|
||
public EncodingConverterLastErrorNode(RubyContext context, SourceSection sourceSection) { | ||
super(context, sourceSection); | ||
} | ||
|
||
public EncodingConverterLastErrorNode(EncodingConverterLastErrorNode prev) { | ||
super(prev); | ||
} | ||
|
||
@Specialization | ||
public Object encodingConverterLastError(RubyEncodingConverter encodingConverter) { | ||
notDesignedForCompilation(); | ||
|
||
final org.jruby.exceptions.RaiseException e = EncodingUtils.makeEconvException(getContext().getRuntime(), encodingConverter.getEConv()); | ||
|
||
if (e == null) { | ||
return nil(); | ||
} | ||
|
||
return getContext().toTruffle(e.getException()); | ||
} | ||
|
||
} | ||
|
||
@RubiniusPrimitive(name = "encoding_converter_primitive_errinfo") | ||
public static abstract class EncodingConverterErrinfoNode extends RubiniusPrimitiveNode { | ||
|
||
public EncodingConverterErrinfoNode(RubyContext context, SourceSection sourceSection) { | ||
super(context, sourceSection); | ||
} | ||
|
||
public EncodingConverterErrinfoNode(EncodingConverterErrinfoNode prev) { | ||
super(prev); | ||
} | ||
|
||
@Specialization | ||
public Object encodingConverterLastError(RubyEncodingConverter encodingConverter) { | ||
notDesignedForCompilation(); | ||
|
||
final EConv ec = encodingConverter.getEConv(); | ||
|
||
final Object[] ret = { getContext().newSymbol(ec.lastError.getResult().symbolicName()), nil(), nil(), nil(), nil() }; | ||
|
||
if (ec.lastError.getSource() != null) { | ||
ret[1] = getContext().makeString(new ByteList(ec.lastError.getSource())); | ||
} | ||
|
||
if (ec.lastError.getDestination() != null) { | ||
ret[2] = getContext().makeString(new ByteList(ec.lastError.getDestination())); | ||
} | ||
|
||
if (ec.lastError.getErrorBytes() != null) { | ||
ret[3] = getContext().makeString(new ByteList(ec.lastError.getErrorBytes(), ec.lastError.getErrorBytesP(), ec.lastError.getErrorBytesLength())); | ||
ret[4] = getContext().makeString(new ByteList(ec.lastError.getErrorBytes(), ec.lastError.getErrorBytesP() + ec.lastError.getErrorBytesLength(), ec.lastError.getReadAgainLength())); | ||
} | ||
|
||
return new RubyArray(getContext().getCoreLibrary().getArrayClass(), ret, ret.length); | ||
} | ||
|
||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
class Encoding | ||
TranscodingMap = Encoding::Converter.transcoding_map | ||
EncodingMap = Encoding.encoding_map | ||
EncodingList = Encoding.list | ||
|
||
@default_external = undefined | ||
@default_internal = undefined | ||
end | ||
|
||
Encoding::TranscodingMap[:'UTF-16BE'] = Rubinius::LookupTable.new | ||
Encoding::TranscodingMap[:'UTF-16BE'][:'UTF-8'] = nil | ||
|
||
Encoding::TranscodingMap[:'UTF-16LE'] = Rubinius::LookupTable.new | ||
Encoding::TranscodingMap[:'UTF-16LE'][:'UTF-8'] = nil | ||
|
||
Encoding::TranscodingMap[:'UTF-32BE'] = Rubinius::LookupTable.new | ||
Encoding::TranscodingMap[:'UTF-32BE'][:'UTF-8'] = nil | ||
|
||
Encoding::TranscodingMap[:'UTF-32LE'] = Rubinius::LookupTable.new | ||
Encoding::TranscodingMap[:'UTF-32LE'][:'UTF-8'] = nil | ||
|
||
Encoding::TranscodingMap[:'ISO-2022-JP'] = Rubinius::LookupTable.new | ||
Encoding::TranscodingMap[:'ISO-2022-JP'][:'STATELESS-ISO-2022-JP'] = nil |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
7,686 changes: 7,686 additions & 0 deletions
7,686
truffle/src/main/ruby/core/rubinius/delta/converter_paths.rb
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters