Fix Python pickling and metaclass for builtin wrappers

The metaclass (SwigPyObjectType) for SWIG objects was not defined in
a way that let importlib successfully import the Python wrappers.
The pickle module failed because it couldn't determine what module the
SWIG wrapped objects are in.

I've changed the definition of SwigPyObjectType using more normal
builtin type definitions. There are still some open questions:
- None of the builtin types, like swig_static_var_getset_descriptor and
  SwigPyObject are added into any module. No call to PyModule_AddObject
  is made, so isinstance cannot be used for any wrapped type, all of
  which are derived from SwigPyObject.

Closes #808
This commit is contained in:
William S Fulton 2016-10-13 08:08:27 +01:00
commit 96fae38be2
5 changed files with 167 additions and 9 deletions

View file

@ -0,0 +1,20 @@
import python_pickle
import pickle
def check(p):
msg = p.msg
if msg != "hi there":
raise RuntimeError("Bad, got: " + msg)
python_pickle.cvar.debug = False
p = python_pickle.PickleMe("hi there")
check(p)
r = p.__reduce__()
if python_pickle.cvar.debug:
print "__reduce__ returned:", r
pickle_string = pickle.dumps(p)
newp = pickle.loads(pickle_string)
check(newp)