diff Modules/_ctypes/callproc.c @ 45315:beea35b0ed50 legacy-trunk

Add pickle support to ctypes types.
author Thomas Heller <theller@ctypes.org>
date Wed, 13 Feb 2008 20:21:53 +0000
parents 5fb9b2f6bacb
children b3dca8f5535e
line wrap: on
line diff
--- a/Modules/_ctypes/callproc.c	Wed Feb 13 19:15:44 2008 +0000
+++ b/Modules/_ctypes/callproc.c	Wed Feb 13 20:21:53 2008 +0000
@@ -1578,7 +1578,30 @@
 	return Py_None;
 }
 
+static PyObject *
+unpickle(PyObject *self, PyObject *args)
+{
+	PyObject *typ;
+	PyObject *state;
+	PyObject *result;
+	PyObject *tmp;
+
+	if (!PyArg_ParseTuple(args, "OO", &typ, &state))
+		return NULL;
+	result = PyObject_CallMethod(typ, "__new__", "O", typ);
+	if (result == NULL)
+		return NULL;
+	tmp = PyObject_CallMethod(result, "__setstate__", "O", state);
+	if (tmp == NULL) {
+		Py_DECREF(result);
+		return NULL;
+	}
+	Py_DECREF(tmp);
+	return result;
+}
+
 PyMethodDef module_methods[] = {
+	{"_unpickle", unpickle, METH_VARARGS },
 	{"resize", resize, METH_VARARGS, "Resize the memory buffer of a ctypes instance"},
 #ifdef CTYPES_UNICODE
 	{"set_conversion_mode", set_conversion_mode, METH_VARARGS, set_conversion_mode_doc},