[C++-sig] Pickle an enum from c++

Matthew Scouten (TT) Matthew.Scouten at tradingtechnologies.com
Fri Dec 12 16:55:32 CET 2008


Is there something I am supposed to do to the enum_ to make it work? If
I try to 'dumps()' my enum I still get the exception I included in my
earlier email.  Funny thing, dumps-ing it with cPickle just gets the
exception, while dumps-ing it with regular pickle also produces a crash
from within the bowels of Python25.dll.

-----Original Message-----
From:
cplusplus-sig-bounces+matthew.scouten=tradingtechnologies.com at python.org
[mailto:cplusplus-sig-bounces+matthew.scouten=tradingtechnologies.com at py
thon.org] On Behalf Of Ralf W. Grosse-Kunstleve
Sent: Tuesday, December 09, 2008 10:03 AM
To: Development of Python/C++ integration
Subject: Re: [C++-sig] Pickle an enum from c++

Indeed (I had forgotten this already...):

------------------------------------------------------------------------
r36256 | rwgk | 2006-12-03 12:43:48 -0800 (Sun, 03 Dec 2006) | 2 lines

fixes to support pickling of enums (by Shashank Bapat)

------------------------------------------------------------------------


And there is this test (boost/libs/python/test/enum.py):

# pickling of enums only works with Python 2.3 or higher
exercise_pickling = '''
>>> import pickle
>>> p = pickle.dumps(color.green, pickle.HIGHEST_PROTOCOL)
>>> l = pickle.loads(p)
>>> identity(l)
enum_ext.color.green
'''

So this is supposed to work.



----- Original Message ----
From: Hans Meine <meine at informatik.uni-hamburg.de>
To: Development of Python/C++ integration <cplusplus-sig at python.org>
Cc: Ralf W. Grosse-Kunstleve <rwgk at yahoo.com>
Sent: Tuesday, December 9, 2008 4:40:17 AM
Subject: Re: [C++-sig] Pickle an enum from c++

On Monday 08 December 2008 20:02:41 Roman Yakovenko wrote:
> 2008/12/8 Matthew Scouten (TT)
<Matthew.Scouten at tradingtechnologies.com>:
> > From the lack of response I assume that no one has any clever ideas
to
> > make an enum pickleable.  Thank you to anyone who put thought into
this.
> >
> :-).
>
> I thought about work around: you can define your enums in Python. May
> be youcan add this functionality from Python?
>
> Also did you see the following discussion?
>
http://mail.python.org/pipermail/cplusplus-sig/2006-November/011372.html

Oh, this is continued here:
http://mail.python.org/pipermail/cplusplus-sig/2006-November/011376.html

Looks like there was a solution in 2006; Ralf even wanted to have a test
case 
for check-in.  Ralf, did you receive stuff from Shashank back then?  (Or
did 
you wait until today with committing the fix?)

Greetings,
  Hans

_______________________________________________
Cplusplus-sig mailing list
Cplusplus-sig at python.org
http://mail.python.org/mailman/listinfo/cplusplus-sig


More information about the Cplusplus-sig mailing list