summaryrefslogtreecommitdiff
path: root/src/runtime/python/pypgf.c
diff options
context:
space:
mode:
authorkrasimir <krasimir@chalmers.se>2015-08-12 10:11:00 +0000
committerkrasimir <krasimir@chalmers.se>2015-08-12 10:11:00 +0000
commit6b90024d09f48e6f193c0a6a639ec893fa9c27d1 (patch)
treeb29eff47c9d7a6449fe3158904be41aa58619733 /src/runtime/python/pypgf.c
parentac6ce58777653c65cccd8b52502457eca3653a6e (diff)
pickling/unpickling for types
Diffstat (limited to 'src/runtime/python/pypgf.c')
-rw-r--r--src/runtime/python/pypgf.c33
1 files changed, 33 insertions, 0 deletions
diff --git a/src/runtime/python/pypgf.c b/src/runtime/python/pypgf.c
index 3f950683c..bf58fd6c7 100644
--- a/src/runtime/python/pypgf.c
+++ b/src/runtime/python/pypgf.c
@@ -955,10 +955,43 @@ fail:
return res;
}
+static PyObject*
+Type_reduce_ex(TypeObject* self, PyObject *args)
+{
+ int protocol;
+ if (!PyArg_ParseTuple(args, "i", &protocol))
+ return NULL;
+
+ PyObject* myModule = PyImport_ImportModule("pgf");
+ if (myModule == NULL)
+ return NULL;
+ PyObject* py_readType = PyObject_GetAttrString(myModule, "readType");
+ Py_DECREF(myModule);
+ if (py_readType == NULL)
+ return NULL;
+
+ PyObject* py_str = Type_repr(self);
+ if (py_str == NULL) {
+ Py_DECREF(py_readType);
+ return NULL;
+ }
+
+ PyObject* py_tuple =
+ Py_BuildValue("O(O)", py_readType, py_str);
+
+ Py_DECREF(py_str);
+ Py_DECREF(py_readType);
+
+ return py_tuple;
+}
+
static PyMethodDef Type_methods[] = {
{"unpack", (PyCFunction)Type_unpack, METH_VARARGS,
"Decomposes a type into its components"
},
+ {"__reduce_ex__", (PyCFunction)Type_reduce_ex, METH_VARARGS,
+ "This method allows for transparent pickling/unpickling of types."
+ },
{NULL} /* Sentinel */
};