forked from GitHub/gf-core
pickling/unpickling for types
This commit is contained in:
@@ -955,10 +955,43 @@ fail:
|
|||||||
return res;
|
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[] = {
|
static PyMethodDef Type_methods[] = {
|
||||||
{"unpack", (PyCFunction)Type_unpack, METH_VARARGS,
|
{"unpack", (PyCFunction)Type_unpack, METH_VARARGS,
|
||||||
"Decomposes a type into its components"
|
"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 */
|
{NULL} /* Sentinel */
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user