DL_EXPORT(void) initelemlist(void) /*******************************************************/ { /* Create the module and add the functions */ /******************************************************* Original code: PyObject *m = Py_InitModule("elemlist", elemlist_methods); The Python/C API is unfortunately not quite const-correct, so we need to add a cast here to make the compiler happy:*/ PyObject *m = Py_InitModule("elemlist", (PyMethodDef*)elemlist_methods); /*******************************************************/ /* Finish initializing the type-objects */ /******************************************************* Allocate storage for the type object, fill it in from the constant template and bind it to a name in the module namespace: */ PyTypeObject *consTypeObject=PyObject_New(PyTypeObject, &PyType_Type); *consTypeObject=cons_type_template; SPyAddGlobalString("consType", (PyObject *)consTypeObject); /*******************************************************/ cons_type.ob_type = &PyType_Type; }
TInt ConstructType(const PyTypeObject* aTypeTemplate, char* aClassName) { //// construct the type; //// sets object refcount to 1 PyTypeObject* typeObj = PyObject_New(PyTypeObject, &PyType_Type); *typeObj = *aTypeTemplate; // fill in from a template typeObj->ob_type = &PyType_Type; // fill in the missing bit //// store a reference to the type, for our own use TInt error = SPyAddGlobalString(aClassName, (PyObject*)typeObj); if (error < 0) { // the error codes for the above are not documented, // but have seen the code, and believe return -1 on failure return error; } //// a "global" hash now has a reference, too Py_INCREF(typeObj); return KErrNone; }