YARV issues

Hi all,
  I have downloaded the latest version of YARV and built it from source on
my gentoo box. I tried running 'ruby-yarv script/server' it doesn seem to be
able to 'require gems'.

This is the error it is throwing
/usr/local/lib/ruby/1.9/net/protocol.rb:21:in `require': no such file to
load -- socket (LoadError)
        from /usr/local/lib/ruby/1.9/net/protocol.rb:21:in `<top
(required)>'
        from /usr/local/lib/ruby/1.9/net/http.rb:28:in `require'
        from /usr/local/lib/ruby/1.9/net/http.rb:28:in `<top (required)>'
        from
/usr/local/lib/ruby/site_ruby/1.9/rubygems/remote_fetcher.rb:1:in `require'
        from
/usr/local/lib/ruby/site_ruby/1.9/rubygems/remote_fetcher.rb:1:in `<top
(required)>'
        from /usr/local/lib/ruby/site_ruby/1.9/rubygems/source_index.rb:8:in
`require'
        from /usr/local/lib/ruby/site_ruby/1.9/rubygems/source_index.rb:8:in
`<top (required)>'
        from /usr/local/lib/ruby/site_ruby/1.9/rubygems.rb:504:in `require'
        from /usr/local/lib/ruby/site_ruby/1.9/rubygems.rb:504:in `<top
(required)>'
        from /home/abhijithg/projects/chat/config/boot.rb:20:in `require'
        from /home/abhijithg/projects/chat/config/boot.rb:20:in `<top
(required)>'
        from script/server:2:in `require'
        from script/server:2:in `<main>'

···

--
Regards
Abhijith.G

I have a fairly large and complex object graph of Value Objects created
by soap4r and used in a Rails application. The app, which used to work,
now gets
Exception `TypeError' at
/usr/local/lib/ruby/gems/1.8/gems/activerecord-1.14.4/lib/active_record/transactions.rb:97
- singleton can't be dumped
all over the place and I have narrowed it down to Marshal.dump being
used by Rails.

I have aliased Marshal.dump so that I can inspect the objects passed
first, I thought that would be the fastest way to locate the problematic
object. My question is, how do I detect that an object is a singleton?
Should I test with "responds_to?" if the "new" method lacking or that
the "instance" method is there? Or is there an easier way?

Thanks in advance,
Lars

(first post to this list, so get some salt)

Singleton in this case probably means that the object you're trying to
marshal has a singleton method defined on it (maybe the wrong term.
whatever it's called when you do stuff like "def object.foo;
some_foo(); end".)

The reason it can't be dumped is likely that dumping the 'data' bits
of the object won't save the singleton method(s), so unmarshalling
would be incomplete.

···

On 25/07/07, Lars Westergren <lars.westergren@ki.se> wrote:

I have a fairly large and complex object graph of Value Objects created
by soap4r and used in a Rails application. The app, which used to work,
now gets
Exception `TypeError' at
/usr/local/lib/ruby/gems/1.8/gems/activerecord-1.14.4/lib/active_record/transactions.rb:97
- singleton can't be dumped
all over the place and I have narrowed it down to Marshal.dump being
used by Rails.

I have aliased Marshal.dump so that I can inspect the objects passed
first, I thought that would be the fastest way to locate the problematic
object. My question is, how do I detect that an object is a singleton?
Should I test with "responds_to?" if the "new" method lacking or that
the "instance" method is there? Or is there an easier way?

--
noodl

If Singleton === obj
  puts "it's a singleton!"
end

Kind regards

robert

···

2007/7/25, Lars Westergren <lars.westergren@ki.se>:

I have a fairly large and complex object graph of Value Objects created
by soap4r and used in a Rails application. The app, which used to work,
now gets
Exception `TypeError' at
/usr/local/lib/ruby/gems/1.8/gems/activerecord-1.14.4/lib/active_record/transactions.rb:97
- singleton can't be dumped
all over the place and I have narrowed it down to Marshal.dump being
used by Rails.

I have aliased Marshal.dump so that I can inspect the objects passed
first, I thought that would be the fastest way to locate the problematic
object. My question is, how do I detect that an object is a singleton?
Should I test with "responds_to?" if the "new" method lacking or that
the "instance" method is there? Or is there an easier way?

The following should do the trick -- alas :frowning:

class Class
   def is_singleton?
       ! ancestors.include?( self ) rescue false
   end
end

HTH
Robert

···

On 7/25/07, Lars Westergren <lars.westergren@ki.se> wrote:

I have a fairly large and complex object graph of Value Objects created
by soap4r and used in a Rails application. The app, which used to work,
now gets
Exception `TypeError' at
/usr/local/lib/ruby/gems/1.8/gems/activerecord-1.14.4/lib/active_record/transactions.rb:97
- singleton can't be dumped
all over the place and I have narrowed it down to Marshal.dump being
used by Rails.

I have aliased Marshal.dump so that I can inspect the objects passed
first, I thought that would be the fastest way to locate the problematic
object. My question is, how do I detect that an object is a singleton?
Should I test with "responds_to?" if the "new" method lacking or that
the "instance" method is there? Or is there an easier way?

Thanks in advance,
Lars

--
I always knew that one day Smalltalk would replace Java.
I just didn't know it would be called Ruby
-- Kent Beck

gsub( "Class", "Object")

require 'singleton'

If Singleton === obj
  puts "it's a singleton!"
end

Kind regards

robert

Excellent, did not know about this 1!

Robert

···

--
I always knew that one day Smalltalk would replace Java.
I just didn't know it would be called Ruby
-- Kent Beck

Did I do something stupid?

694/194 > irb
irb(main):001:0> require 'singleton'
=> true
irb(main):002:0> s = "abc"
=> "abc"
irb(main):003:0> sing = class << s; self end
=> #<Class:#<String:0xb7d9eaec>>
irb(main):004:0> Singleton === s
=> false
irb(main):005:0> Singleton === sing

···

On 7/25/07, Robert Dober <robert.dober@gmail.com> wrote:
**********
=> false
**********
irb(main):006:0> puts "???"
???
=> nil
irb(main):007:0>
R.

Did I do something stupid?

No, you seem to be dragged into the confusion between singleton and
singleton. :slight_smile:

694/194 > irb
irb(main):001:0> require 'singleton'
=> true
irb(main):002:0> s = "abc"
=> "abc"
irb(main):003:0> sing = class << s; self end
=> #<Class:#<String:0xb7d9eaec>>
irb(main):004:0> Singleton === s
=> false
irb(main):005:0> Singleton === sing
**********
=> false
**********
irb(main):006:0> puts "???"
???
=> nil
irb(main):007:0>

The "singleton" you are referring to is the singleton class (btw, now
I understand your code suggestion). I believe the OP wanted to know
about Singleton as in

class Foo
include Singleton
end

Kind regards

robert

···

2007/7/25, Robert Dober <robert.dober@gmail.com>:

On 7/25/07, Robert Dober <robert.dober@gmail.com> wrote:

Robert Dober skrev:

Did I do something stupid?

Oh, good, so it wasn't just me then.
:slight_smile:

It doesn't seem to work for me either. I get false, and then the
exception anyway.

I think that test only works if the class in question used the Singleton
module mixin, I believe the problematic class probably uses some form of
  sing = class << self; self end
magic.

I tried looking at the code for marshalling, but alas, it was C, and
therefore not much help to me...

if (FL_TEST(klass, FL_SINGLETON)) {
        if (check && RCLASS(klass)->m_tbl->num_entries ||
            (RCLASS(klass)->iv_tbl && RCLASS(klass)->iv_tbl->num_entries

1)) {

            rb_raise(rb_eTypeError, "singleton can't be dumped");
        }

Thanks,
Lars

···

On 7/25/07, Robert Dober <robert.dober@gmail.com> wrote:

No, *I* confused them. Just forget all the rest of what I wrote.

Sorry for the noise. I should have checked.

Cheers

robert

···

2007/7/25, Robert Klemme <shortcutter@googlemail.com>:

2007/7/25, Robert Dober <robert.dober@gmail.com>:
> On 7/25/07, Robert Dober <robert.dober@gmail.com> wrote:
> Did I do something stupid?

No, you seem to be dragged into the confusion between singleton and
singleton. :slight_smile:

well seems you have to use my code then, it depends on a "feature"
Matz has put deliberately into the implementation of ancestor,
singletons are not included.
Does this fit your definition of singleton?
Robert

···

On 7/25/07, Lars Westergren <lars.westergren@ki.se> wrote:

--
I always knew that one day Smalltalk would replace Java.
I just didn't know it would be called Ruby
-- Kent Beck

Robert Dober skrev:

well seems you have to use my code then, it depends on a "feature"
Matz has put deliberately into the implementation of ancestor,
singletons are not included.
Does this fit your definition of singleton?

Not sure.... Your code works good in irb and catches singletons
created as
class << self;self;end;

there. However, I still got the bug in Rails. I have done this-

marsh = class << Marshal; self; end
marsh.send :alias_method, "old_dump", "dump"
marsh.class_eval<<ENDOFSTRING
def dump(o);
  STDERR.puts \"Problem class is a \" + o.class.name;
  STDERR.puts o.inspect;
  if o.class.is_singleton?;
    puts \"it's a singleton!\";
  else
     puts \"not a singleton...\";
  end;
  old_dump(o);
end
ENDOFSTRING

And I get "not a singleton..." immediately followed by the exception.
The "problematic" object I think is the :session hash object, or rather
an object stored inside it. Either I'm looking in the wrong place, or I
need to traverse the object graph examening each object in array/hash.

Is there a library available for that?

I wish I could paste the inspect string for you people, but it is
several pages long and contains personal information.

Thanks again,
Lars

···

On 7/25/07, Lars Westergren <lars.westergren@ki.se> wrote:

Robert Dober skrev:
> well seems you have to use my code then, it depends on a "feature"
> Matz has put deliberately into the implementation of ancestor,
> singletons are not included.
> Does this fit your definition of singleton?

Not sure.... Your code works good in irb and catches singletons
created as
class << self;self;end;

there. However, I still got the bug in Rails.

OMG Rails, what do they do my Ruby? :wink:
But I think it is Marshal, are you sure that it is the singleton which
causes problems?
AFAIK there are other things which make objects not serializable,
gotta find some time to look into this...

I have done this-

marsh = class << Marshal; self; end
marsh.send :alias_method, "old_dump", "dump"
marsh.class_eval<<ENDOFSTRING
def dump(o);
  STDERR.puts \"Problem class is a \" + o.class.name;
  STDERR.puts o.inspect;
  if o.class.is_singleton?;
    puts \"it's a singleton!\";
  else
     puts \"not a singleton...\";
  end;
  old_dump(o);
end
ENDOFSTRING

And I get "not a singleton..." immediately followed by the exception.
The "problematic" object I think is the :session hash object, or rather
an object stored inside it. Either I'm looking in the wrong place, or I
need to traverse the object graph examening each object in array/hash.

Is there a library available for that?

I wish I could paste the inspect string for you people, but it is
several pages long and contains personal information.

hmm maybe you can get us some condensed info, but did you check the
RDoc for what could raise the TypeError in dump?

Cheers
Robert

···

On 7/25/07, Lars Westergren <lars.westergren@ki.se> wrote:

> On 7/25/07, Lars Westergren <lars.westergren@ki.se> wrote:

Thanks again,
Lars

--
I always knew that one day Smalltalk would replace Java.
I just didn't know it would be called Ruby
-- Kent Beck