jnorwoo / shedskin

Automatically exported from code.google.com/p/shedskin
0 stars 0 forks source link

Using Pickle with a class defined in Shedskin will cause a segfault if the number of arguments in __init__ is different than 2 #182

Closed GoogleCodeExporter closed 8 years ago

GoogleCodeExporter commented 8 years ago
What steps will reproduce the problem?
1. Modify the class Blah located in tests/e1/blah.py to have a different number 
of arguments in __init__ (0, 1 or >2 arguments). main.py also has to be 
modified accordingly.
2. shedskin -e blah.py; make
3. python main.y

What is the expected output? What do you see instead?
Expected (I removed the second argument): 7
Actual: Segmentation fault

What version of the product are you using? On what operating system?
0.9.2 and I also tried with 0.9.3.
Linux Netbook 3.5.0-25-generic #39-Ubuntu SMP Mon Feb 25 19:02:34 UTC 2013 i686 
i686 i686 GNU/Linux

Please provide any additional information below.

main.py:

#blah
import blah as test
import pickle

blah = test.Blah(1)
print blah.__reduce__()
s = pickle.dumps(blah)
obj = pickle.loads(s)

Notice the line that has blah.__reduce__().
That line will print:

(<built-in function __newobj__>, (<type 'blah.Blah'>,), (1, <nil>))

and I would expect

(<built-in function __newobj__>, (<type 'blah.Blah'>,), (1,))

If I try to print that <nil> value doing this:
print blah.__reduce__()[2][1]
I also get Segmentation fault. I guess the real problem is there.

If I have 3 arguments in __init__ with the values 1, 2 and 3, that line prints:

(<built-in function __newobj__>, (<type 'blah.Blah'>,), (1, 3))

So 2 is missing. In general that tuple always has 2 elements.

Anyway, I hope this help and thank you very much for this wonderful project.

I'm submitting this issue because being able to pickle an object defined in 
Shedskin is a wonderful feature and I guess is almost done.
On top of that, having this would help me a lot but that's just me.

Original issue reported on code.google.com by ernestof...@gmail.com on 2 Mar 2013 at 6:16

Attachments:

GoogleCodeExporter commented 8 years ago
thanks for reporting! hmm, isn't this painful:

http://gitorious.org/shedskin/mainline/commit/aebb737e3c8a2138ac8cc5a6dea3ed8b6f
bb1a06

(also because nobody has bothered to report this over the last 5 years or so..)

please let me know if you run into anything else! thanks again.

Original comment by mark.duf...@gmail.com on 3 Mar 2013 at 5:58

GoogleCodeExporter commented 8 years ago
WOW! That was fast! Thank you very much.

Original comment by ernestof...@gmail.com on 3 Mar 2013 at 7:02