Marshal.load weird issue

Hi guys

I can't get my head around this. Obj is a fairly big object, quite a bit
nested.

When I do

temp = Marshal.dump(Obj)
Marshal.load(temp)

I get an error on load (wrong character). Now when I do:

Marshal.dump(Obj)
temp = Marshal.dump(Obj)
Marshal.load(temp)

(just dumping twice the exact same thing) it works fine.

Ruby 1.9.2 and 1.9.3.

Do you know if I am missing something?

Thanks!
PJ

···

--
Posted via http://www.ruby-forum.com/.

Will be nice if you show the exactly error.

···

--
Posted via http://www.ruby-forum.com/.

The exact error I get is:

ArgumentError: dump format error for symbol(0x46)

Thanks a lot
PJ

···

--
Posted via http://www.ruby-forum.com/.

Just to be clear (the error message is a bit confusing): I get the error
when I do: Marshal.load(temp), not when I dump the object.

···

--
Posted via http://www.ruby-forum.com/.

Hi Robert

I am so sorry I made this confusing: Obj is not a constant. Not sure why
I had it capitalized.

This is really all I am doing in a console. Unfortunately, it will be
really difficult for me to share the object itself. It is a hash of
fairly nested ActiveRecord objects. I am not sure how to extract it from
the rest of my project.

Is there a way to "debug" Marshal? Could there be something that
explains the fact that it does not work properly the first time, and
correctly the second time? Could it be a memory allocation or something?

Thanks!
PJ

···

--
Posted via http://www.ruby-forum.com/.

You are right, they are not equal.

temp = Marshal.dump(ps)
temp2 = Marshal.dump(ps)
temp == temp2

=> false

It seems the difference is at the end of the string. The first one
finishes with:

"\x00\x1E\x19;\x160;\x17{\x00;\x18{\x00;\x19{\x00;\e{\x00;\x01\x80{\x00;\x01\x81F;\x01\x82F;\x01\x83F;\x01\x84F"

The second one (temp2) finishes with:

"\x00\x1E\x19;\x160;\x17{\x00;\x18{\x00;\x19{\x00;\e{\x00;+{\x00;,F;-F;.F;/F"

I have to say it does not mean much to me. I have tried to "unpack" them
but I am not sure what I am doing and the results seem always the same.

Thanks a lot for your help on this.

PJ

···

--
Posted via http://www.ruby-forum.com/\.

Thanks guys.
Unfortunately extracting ps from its context would be really
complicated. It is a hash of nested AR objects. I tried to reproduce
with simpler objects but it did not work.
I will have to try and find my way in the Marshal.dump code.

···

--
Posted via http://www.ruby-forum.com/.

What is Obj? Why do you store this object in a constant? Can you
show more of your code, ideally a simple example which reproduces the
error?

Kind regards

robert

···

On Mon, Oct 29, 2012 at 3:18 AM, Pierre J. <lists@ruby-forum.com> wrote:

Just to be clear (the error message is a bit confusing): I get the error
when I do: Marshal.load(temp), not when I dump the object.

--
remember.guy do |as, often| as.you_can - without end
http://blog.rubybestpractices.com/

Quoting Pierre J. (lists@ruby-forum.com):

Is there a way to "debug" Marshal? Could there be something that
explains the fact that it does not work properly the first time, and
correctly the second time? Could it be a memory allocation or something?

If you compile your own ruby (not a difficult task, but then again,
probably not your piece of cake if you dabble with complex
ActiveRecord stuff...) Marshal is neatly included in file marshal.c,
at the root of the distribution. 1971 lines of code. You can always
run the Ruby interpreter under gdb, and/or add any sort of printout to
follow what is happening.

Carlo

···

Subject: Re: Marshal.load weird issue
  Date: Mon 29 Oct 12 07:21:42PM +0900

--
  * Se la Strada e la sua Virtu' non fossero state messe da parte,
* K * Carlo E. Prelz - fluido@fluido.as che bisogno ci sarebbe
  * di parlare tanto di amore e di rettitudine? (Chuang-Tzu)

I think we need to know more about what ps actually is. This looks
like ps changes between invocations.

Kind regards

robert

···

On Mon, Oct 29, 2012 at 3:31 PM, Pierre J. <lists@ruby-forum.com> wrote:

You are right, they are not equal.

temp = Marshal.dump(ps)
temp2 = Marshal.dump(ps)
temp == temp2

=> false

It seems the difference is at the end of the string. The first one
finishes with:

"\x00\x1E\x19;\x160;\x17{\x00;\x18{\x00;\x19{\x00;\e{\x00;\x01\x80{\x00;\x01\x81F;\x01\x82F;\x01\x83F;\x01\x84F"

The second one (temp2) finishes with:

"\x00\x1E\x19;\x160;\x17{\x00;\x18{\x00;\x19{\x00;\e{\x00;+{\x00;,F;-F;.F;/F"

I have to say it does not mean much to me. I have tried to "unpack" them
but I am not sure what I am doing and the results seem always the same.

--
remember.guy do |as, often| as.you_can - without end
http://blog.rubybestpractices.com/

If AR means ActiveRecord then you may run into the situation that
those objects store state related to the current connection or
transaction which cannot be properly serialized and deserialized. It
may be necessary to copy the object tree or unlink them from the
database (no AR expert here, but others may explain better).

Kind regards

robert

···

On Tue, Oct 30, 2012 at 1:22 AM, Pierre J. <lists@ruby-forum.com> wrote:

Thanks guys.
Unfortunately extracting ps from its context would be really
complicated. It is a hash of nested AR objects. I tried to reproduce
with simpler objects but it did not work.
I will have to try and find my way in the Marshal.dump code.

--
remember.guy do |as, often| as.you_can - without end
http://blog.rubybestpractices.com/

Can you check if the value returned by Marshal.dump(Obj) on subsequent
calls is indeed the same? (It's a binary string, just assign to some
variable and compare with ==.)

-- Matma Rex