#include static PyObject* extractdict(PyObject* self, PyObject* arg) { PyObject *dict; PyObject **p = _PyObject_GetDictPtr(arg); if (p == NULL) { PyErr_Format(PyExc_TypeError, "'%.100s' object has no __dict__", arg->ob_type->tp_name); return NULL; } dict = *p; if (dict == NULL) { dict = PyDict_New(); if (dict == NULL) return NULL; *p = dict; } Py_INCREF(dict); return dict; } static PyMethodDef ExtractDictMethods[] = { {"extractdict", extractdict, METH_O, NULL}, {NULL, NULL} /* Sentinel */ }; PyMODINIT_FUNC initextractdict(void) { Py_InitModule("extractdict", ExtractDictMethods); }