Skip to content
Permalink

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: jruby/jruby
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: 2a9bbb6c9dc4
Choose a base ref
...
head repository: jruby/jruby
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: c494ed33b7a2
Choose a head ref
  • 2 commits
  • 4 files changed
  • 1 contributor

Commits on Feb 17, 2015

  1. Copy the full SHA
    45adab4 View commit details
  2. [Truffle] Untagged String#{gsub,gsub\!} specs now that we're more com…

    …patible with Rubinius.
    nirvdrum committed Feb 17, 2015
    Copy the full SHA
    c494ed3 View commit details
27 changes: 0 additions & 27 deletions spec/truffle/tags/core/string/gsub_tags.txt
Original file line number Diff line number Diff line change
@@ -2,53 +2,26 @@ fails:String#gsub with pattern and replacement treats \+ as an empty string if t
fails:String#gsub with pattern and replacement replaces \k named backreferences with the regexp's corresponding capture
fails:String#gsub with pattern and replacement taints the result if the original string or replacement is tainted
fails:String#gsub with pattern and replacement untrusts the result if the original string or replacement is untrusted
fails:String#gsub with pattern and Hash returns a copy of self with all occurrences of pattern replaced with the value of the corresponding hash key
fails:String#gsub with pattern and Hash ignores keys that don't correspond to matches
fails:String#gsub with pattern and Hash returns an empty string if the pattern matches but the hash specifies no replacements
fails:String#gsub with pattern and Hash ignores non-String keys
fails:String#gsub with pattern and Hash uses a key's value as many times as needed
fails:String#gsub with pattern and Hash uses the hash's default value for missing keys
fails:String#gsub with pattern and Hash coerces the hash values with #to_s
fails:String#gsub with pattern and Hash uses the hash's value set from default_proc for missing keys
fails:String#gsub with pattern and Hash sets $~ to MatchData of last match and nil when there's none for access from outside
fails:String#gsub with pattern and Hash doesn't interpolate special sequences like \1 for the block's return value
fails:String#gsub with pattern and Hash untrusts the result if the original string is untrusted
fails:String#gsub with pattern and Hash untrusts the result if a hash value is untrusted
fails:String#gsub with pattern and Hash taints the result if the original string is tainted
fails:String#gsub with pattern and Hash taints the result if a hash value is tainted
fails:String#gsub! with pattern and Hash returns self with all occurrences of pattern replaced with the value of the corresponding hash key
fails:String#gsub! with pattern and Hash ignores keys that don't correspond to matches
fails:String#gsub! with pattern and Hash replaces self with an empty string if the pattern matches but the hash specifies no replacements
fails:String#gsub! with pattern and Hash ignores non-String keys
fails:String#gsub! with pattern and Hash uses a key's value as many times as needed
fails:String#gsub! with pattern and Hash uses the hash's default value for missing keys
fails:String#gsub! with pattern and Hash coerces the hash values with #to_s
fails:String#gsub! with pattern and Hash uses the hash's value set from default_proc for missing keys
fails:String#gsub! with pattern and Hash sets $~ to MatchData of last match and nil when there's none for access from outside
fails:String#gsub! with pattern and Hash doesn't interpolate special sequences like \1 for the block's return value
fails:String#gsub! with pattern and Hash keeps untrusted state
fails:String#gsub! with pattern and Hash untrusts self if a hash value is untrusted
fails:String#gsub! with pattern and Hash keeps tainted state
fails:String#gsub! with pattern and Hash taints self if a hash value is tainted
fails:String#gsub with pattern and block sets $~ for access from the block
fails:String#gsub with pattern and block restores $~ after leaving the block
fails:String#gsub with pattern and block sets $~ to MatchData of last match and nil when there's none for access from outside
passes:String#gsub with pattern and block converts the block's return value to a string using to_s
fails:String#gsub with pattern and block untrusts the result if the original string or replacement is untrusted
fails:String#gsub with pattern and block uses the compatible encoding if they are compatible
fails:String#gsub with pattern and block raises an Encoding::CompatibilityError if the encodings are not compatible
fails:String#gsub with pattern and block replaces the incompatible part properly even if the encodings are not compatible
fails:String#gsub! with pattern and replacement taints self if replacement is tainted
fails:String#gsub! with pattern and replacement untrusts self if replacement is untrusted
fails:String#gsub! with pattern and block modifies self in place and returns self
fails:String#gsub! with pattern and block taints self if block's result is tainted
fails:String#gsub! with pattern and block untrusts self if block's result is untrusted
fails:String#gsub! with pattern and block uses the compatible encoding if they are compatible
fails:String#gsub! with pattern and block raises an Encoding::CompatibilityError if the encodings are not compatible
fails:String#gsub! with pattern and block replaces the incompatible part properly even if the encodings are not compatible
fails:String#gsub with pattern and replacement respects $KCODE when the pattern collapses
fails:String#gsub with pattern and replacement handles pattern collapse without $KCODE
fails:String#gsub with pattern and block returns a copy of self with all occurrences of pattern replaced with the block's return value
fails:String#gsub with pattern and block doesn't interpolate special sequences like \1 for the block's return value
fails:String#gsub with pattern and block converts the block's return value to a string using to_s
fails:String#gsub with pattern and replacement returns subclass instances when called on a subclass
Original file line number Diff line number Diff line change
@@ -92,6 +92,7 @@ public class CoreLibrary {
private final RubyClass runtimeErrorClass;
private final RubyClass standardErrorClass;
private final RubyClass stringClass;
private final RubyClass stringDataClass;
private final RubyClass symbolClass;
private final RubyClass syntaxErrorClass;
private final RubyClass systemCallErrorClass;
@@ -287,6 +288,7 @@ public CoreLibrary(RubyContext context) {

rubiniusModule = defineModule("Rubinius");
byteArrayClass = new RubyClass(context, rubiniusModule, objectClass, "ByteArray");
stringDataClass = new RubyClass(context, rubiniusModule, objectClass, "StringData");

// Include the core modules

@@ -1098,6 +1100,10 @@ public RubyClass getByteArrayClass() {
return byteArrayClass;
}

public RubyClass getStringDataClass() {
return stringDataClass;
}

public RubyBasicObject getRubiniusUndefined() {
return rubiniusUndefined;
}
Original file line number Diff line number Diff line change
@@ -1564,11 +1564,12 @@ public RubyNode visitInstVarNode(org.jruby.ast.InstVarNode node) {
null,
false);
} else if (nameWithoutSigil.equals("@data")) {
return new RubyCallNode(context, sourceSection,
"bytes",
new SelfNode(context, sourceSection),
null,
false);
final RubyNode bytes = new RubyCallNode(context, sourceSection, "bytes",
new SelfNode(context, sourceSection), null, false);

return new RubyCallNode(context, sourceSection, "new",
new ObjectLiteralNode(context, sourceSection, context.getCoreLibrary().getStringDataClass()),
null, false, bytes);
}
}

29 changes: 29 additions & 0 deletions truffle/src/main/ruby/core/shims.rb
Original file line number Diff line number Diff line change
@@ -220,4 +220,33 @@ def full
tuple
end
end
end

# Wrapper class for Rubinius's exposure of @data within String.
#
# We can't use Array directly because we don't currently guarantee that we'll always return the same
# exact underlying byte array. Rubinius calls #equal? rather than #== throughout its code, making a tighter
# assumption than we provide. This wrapper provides the semantics we need in the interim.
module Rubinius
class StringData
attr_accessor :array

def initialize(array)
@array = array
end

def equal?(other)
@array == other.array
end

alias_method :==, :equal?

def size
@array.size
end

def [](index)
@array[index]
end
end
end