Details

    • Type: Bug Bug
    • Status: Resolved Resolved
    • Priority: Major Major
    • Resolution: Fixed
    • Affects Version/s: JRuby 1.7.0.pre1
    • Fix Version/s: JRuby 1.7.0.pre1
    • Component/s: Core Classes/Modules
    • Labels:
      None
    • Environment:
      $ jruby --1.9 -v
      jruby 1.7.0.dev (ruby-1.9.3-p6) (2012-01-21 0d0c764) (Java HotSpot(TM) 64-Bit Server VM 1.7.0_02) [linux-amd64-java]
    • Number of attachments :
      0

      Description

      Steps to reproduce:

      s = "test"
      t = String.new(s)
      t.setbyte(0, "r".ord)
      p s #=> rest
      p t #=> rest
      puts s == "rest" #=> true
      puts s == "test" #=> false

      I was under the impression that s should still be equal to "test", that is t should be a copy of the contents of s. That's at least what I get in CRuby(1.9.3)?

        Activity

        Hide
        Charles Oliver Nutter added a comment -

        How very peculiar! We seem to be setting the right flags in both initialize and setbyte, but I'll look deeper.

        Show
        Charles Oliver Nutter added a comment - How very peculiar! We seem to be setting the right flags in both initialize and setbyte, but I'll look deeper.
        Hide
        Charles Oliver Nutter added a comment -

        The problem was actually not in the sharing but in the unsharing. setbyte did not actually force copying of a shared backing store before making modifications. This didn't just affect the "s" string...it actually affected the cached backing store (ByteList) in the runtime, so all "test" literal strings would see the modification.

        I have a fix in progress.

        Show
        Charles Oliver Nutter added a comment - The problem was actually not in the sharing but in the unsharing. setbyte did not actually force copying of a shared backing store before making modifications. This didn't just affect the "s" string...it actually affected the cached backing store (ByteList) in the runtime, so all "test" literal strings would see the modification. I have a fix in progress.
        Hide
        Charles Oliver Nutter added a comment -

        Fixed on master@8768b8f. Good find!

        Show
        Charles Oliver Nutter added a comment - Fixed on master@8768b8f. Good find!
        Hide
        Martin Bo▀let added a comment -

        > Fixed on master@8768b8f. Good find!

        Thanks, but it was pure luck - I just stumbled over it while doing the ByteString spec Thanks for the quick fix!

        Show
        Martin Bo▀let added a comment - > Fixed on master@8768b8f. Good find! Thanks, but it was pure luck - I just stumbled over it while doing the ByteString spec Thanks for the quick fix!

          People

          • Assignee:
            Charles Oliver Nutter
            Reporter:
            Martin Bo▀let
          • Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

            Dates

            • Created:
              Updated:
              Resolved: