Details

    • Type: Bug Bug
    • Status: Resolved Resolved
    • Priority: Minor Minor
    • Resolution: Fixed
    • Affects Version/s: JRuby 1.7.0.pre2
    • Fix Version/s: JRuby 1.7.0.RC1
    • Component/s: Extensions
    • Labels:
      None
    • Environment:
      jruby 1.7.0.preview2.dev (1.9.3p203) 2012-08-02 2c561b0 on OpenJDK 64-Bit Server VM 1.7.0_04-icedtea-b21 [linux-amd64]
    • Number of attachments :
      0

      Description

      $ ./bin/jruby -vr yaml -e 'p YAML.load(YAML.dump(lambda{}))'
      jruby 1.7.0.preview2.dev (1.9.3p203) 2012-08-02 2c561b0 on OpenJDK 64-Bit Server VM 1.7.0_04-icedtea-b21 [linux-amd64]
      #<Proc:0x68dfb29d@(null):0>
      

      Thanks!

        Activity

        Hide
        Hiro Asari added a comment -

        MRI behaves the same way. How did you come to the conclusion that this is a bug?

        $ ruby -vr yaml -e 'p YAML.dump(lambda{})'
        ruby 1.9.3p194 (2012-04-20 revision 35410) [x86_64-darwin11.3.0]
        "--- !ruby/object:Proc {}\n"
        
        Show
        Hiro Asari added a comment - MRI behaves the same way. How did you come to the conclusion that this is a bug? $ ruby -vr yaml -e 'p YAML.dump(lambda{})' ruby 1.9.3p194 (2012-04-20 revision 35410) [x86_64-darwin11.3.0] "--- !ruby/object:Proc {}\n"
        Hide
        Lin Jen-Shin added a comment -

        Doh. I am very sorry. The example is way too simplified.
        I should have checked that.

        $ ./bin/jruby -vr yaml -e 'p YAML.load(YAML.dump(lambda{}))'
        jruby 1.7.0.preview2.dev (1.9.3p203) 2012-08-02 2c561b0 on OpenJDK 64-Bit Server VM 1.7.0_04-icedtea-b21 [linux-amd64]
        #<Proc:0x26790be@(null):0>

        $ ruby -vr yaml -e 'p YAML.load(YAML.dump(lambda{}))'
        ruby 1.9.3p194 (2012-04-20 revision 35410) [x86_64-linux]
        /usr/lib/ruby/1.9.1/psych/visitors/to_ruby.rb:274:in `allocate': allocator undefined for Proc (TypeError)

        On the other hand, I guess the original example should be filed as a bug on MRI too.
        Sorry again.

        p.s. can I edit the title? It should be `YAML.load(YAML.dump(lambda{}))`

        Show
        Lin Jen-Shin added a comment - Doh. I am very sorry. The example is way too simplified. I should have checked that. $ ./bin/jruby -vr yaml -e 'p YAML.load(YAML.dump(lambda{}))' jruby 1.7.0.preview2.dev (1.9.3p203) 2012-08-02 2c561b0 on OpenJDK 64-Bit Server VM 1.7.0_04-icedtea-b21 [linux-amd64] #<Proc:0x26790be@(null):0> $ ruby -vr yaml -e 'p YAML.load(YAML.dump(lambda{}))' ruby 1.9.3p194 (2012-04-20 revision 35410) [x86_64-linux] /usr/lib/ruby/1.9.1/psych/visitors/to_ruby.rb:274:in `allocate': allocator undefined for Proc (TypeError) On the other hand, I guess the original example should be filed as a bug on MRI too. Sorry again. p.s. can I edit the title? It should be `YAML.load(YAML.dump(lambda{}))`
        Hide
        Lin Jen-Shin added a comment -

        This patch doesn't seem to work, it would cause a of places failed?
        p.s. I'm trying to help.

        diff --git a/src/org/jruby/RubyProc.java b/src/org/jruby/RubyProc.java
        index 8d831d3..945c523 100644
        --- a/src/org/jruby/RubyProc.java
        +++ b/src/org/jruby/RubyProc.java
        @@ -78,10 +78,13 @@ public class RubyProc extends RubyObject implements DataType {
             private static ObjectAllocator PROC_ALLOCATOR = new ObjectAllocator() {
                 public IRubyObject allocate(Ruby runtime, RubyClass klass) {
                     RubyProc instance = new RubyProc(runtime, runtime.getProc(), Block.Type.PROC);
        -
        -            instance.setMetaClass(klass);
        -
        -            return instance;
        +            if (instance.getBlock().isGiven()) {
        +                instance.setMetaClass(klass);
        +                return instance;
        +            }
        +            else {
        +                return ObjectAllocator.NOT_ALLOCATABLE_ALLOCATOR.allocate(runtime, klass);
        +            }
                 }
             };
        
        Show
        Lin Jen-Shin added a comment - This patch doesn't seem to work, it would cause a of places failed? p.s. I'm trying to help. diff --git a/src/org/jruby/RubyProc.java b/src/org/jruby/RubyProc.java index 8d831d3..945c523 100644 --- a/src/org/jruby/RubyProc.java +++ b/src/org/jruby/RubyProc.java @@ -78,10 +78,13 @@ public class RubyProc extends RubyObject implements DataType { private static ObjectAllocator PROC_ALLOCATOR = new ObjectAllocator() { public IRubyObject allocate(Ruby runtime, RubyClass klass) { RubyProc instance = new RubyProc(runtime, runtime.getProc(), Block.Type.PROC); - - instance.setMetaClass(klass); - - return instance; + if (instance.getBlock().isGiven()) { + instance.setMetaClass(klass); + return instance; + } + else { + return ObjectAllocator.NOT_ALLOCATABLE_ALLOCATOR.allocate(runtime, klass); + } } };
        Hide
        Charles Oliver Nutter added a comment -

        This is the crux of the problem...our Proc has an allocator:

        system ~/projects/jruby $ rvm 1.9.3 do ruby -ryaml -e "Proc.allocate"
        -e:1:in `allocate': allocator undefined for Proc (TypeError)
        	from -e:1:in `<main>'
        
        system ~/projects/jruby $ rvm 1.8.7 do ruby -ryaml -e "Proc.allocate"
        -e:1:in `allocate': allocator undefined for Proc (TypeError)
        	from -e:1
        
        system ~/projects/jruby $ jruby -ryaml -e "Proc.allocate"
        
        system ~/projects/jruby $
        
        Show
        Charles Oliver Nutter added a comment - This is the crux of the problem...our Proc has an allocator: system ~/projects/jruby $ rvm 1.9.3 do ruby -ryaml -e "Proc.allocate" -e:1:in `allocate': allocator undefined for Proc (TypeError) from -e:1:in `<main>' system ~/projects/jruby $ rvm 1.8.7 do ruby -ryaml -e "Proc.allocate" -e:1:in `allocate': allocator undefined for Proc (TypeError) from -e:1 system ~/projects/jruby $ jruby -ryaml -e "Proc.allocate" system ~/projects/jruby $
        Hide
        Charles Oliver Nutter added a comment -
        commit 4d66fd8dc44e4215332fcf61f19f99e17a131548
        Author: Charles Oliver Nutter <headius@headius.com>
        Date:   Tue Aug 21 19:25:46 2012 -0500
        
            Fix JRUBY-6810
            
            YAML.load(YAML.dump(lambda{})) should raise TypeError
            
            Proc should not define an allocator (#allocate should raise).
        
        :000000 100644 0000000... bcfcace... A	spec/regression/JRUBY-6810_proc_should_not_have_allocator_spec.rb
        :100644 100644 8d831d3... cf2a966... M	src/org/jruby/RubyProc.java
        
        Show
        Charles Oliver Nutter added a comment - commit 4d66fd8dc44e4215332fcf61f19f99e17a131548 Author: Charles Oliver Nutter <headius@headius.com> Date: Tue Aug 21 19:25:46 2012 -0500 Fix JRUBY-6810 YAML.load(YAML.dump(lambda{})) should raise TypeError Proc should not define an allocator (#allocate should raise). :000000 100644 0000000... bcfcace... A spec/regression/JRUBY-6810_proc_should_not_have_allocator_spec.rb :100644 100644 8d831d3... cf2a966... M src/org/jruby/RubyProc.java
        Hide
        Lin Jen-Shin added a comment -

        Thank you!

        Show
        Lin Jen-Shin added a comment - Thank you!

          People

          • Assignee:
            Charles Oliver Nutter
            Reporter:
            Lin Jen-Shin
          • Votes:
            0 Vote for this issue
            Watchers:
            4 Start watching this issue

            Dates

            • Created:
              Updated:
              Resolved: