static int pickle_setup(void) { PyObject *copy_reg; int r = -1; #define DEFINE_STRING(S) \ if(! (str ## S = PyString_FromString(# S))) return -1 DEFINE_STRING(__slotnames__); DEFINE_STRING(__getnewargs__); DEFINE_STRING(__getstate__); #undef DEFINE_STRING copy_reg = PyImport_ImportModule("copy_reg"); if (copy_reg == NULL) return -1; copy_reg_slotnames = PyObject_GetAttrString(copy_reg, "_slotnames"); if (copy_reg_slotnames == NULL) goto end; __newobj__ = PyObject_GetAttrString(copy_reg, "__newobj__"); if (__newobj__ == NULL) goto end; r = 0; end: Py_DECREF(copy_reg); return r; }
PyMODINIT_FUNC init_ExtensionClass(void) { PyObject *m, *s; if (pickle_setup() < 0) return; #define DEFINE_STRING(S) \ if(! (str ## S = PyString_FromString(# S))) return DEFINE_STRING(__of__); DEFINE_STRING(__get__); DEFINE_STRING(__class_init__); DEFINE_STRING(__init__); DEFINE_STRING(__bases__); DEFINE_STRING(__mro__); DEFINE_STRING(__new__); #undef DEFINE_STRING PyExtensionClassCAPI = &TrueExtensionClassCAPI; ExtensionClassType.ob_type = &PyType_Type; ExtensionClassType.tp_base = &PyType_Type; ExtensionClassType.tp_basicsize = PyType_Type.tp_basicsize; ExtensionClassType.tp_traverse = PyType_Type.tp_traverse; ExtensionClassType.tp_clear = PyType_Type.tp_clear; /* Initialize types: */ if (PyType_Ready(&ExtensionClassType) < 0) return; BaseType.ob_type = &ExtensionClassType; BaseType.tp_base = &PyBaseObject_Type; BaseType.tp_basicsize = PyBaseObject_Type.tp_basicsize; BaseType.tp_new = PyType_GenericNew; if (PyType_Ready(&BaseType) < 0) return; NoInstanceDictionaryBaseType.ob_type = &ExtensionClassType; NoInstanceDictionaryBaseType.tp_base = &BaseType; NoInstanceDictionaryBaseType.tp_basicsize = BaseType.tp_basicsize; NoInstanceDictionaryBaseType.tp_new = PyType_GenericNew; if (PyType_Ready(&NoInstanceDictionaryBaseType) < 0) return; /* Create the module and add the functions */ m = Py_InitModule3("_ExtensionClass", ec_methods, _extensionclass_module_documentation); if (m == NULL) return; s = PyCObject_FromVoidPtr(PyExtensionClassCAPI, NULL); if (PyModule_AddObject(m, "CAPI2", s) < 0) return; /* Add types: */ if (PyModule_AddObject(m, "ExtensionClass", (PyObject *)&ExtensionClassType) < 0) return; if (PyModule_AddObject(m, "Base", (PyObject *)&BaseType) < 0) return; if (PyModule_AddObject(m, "NoInstanceDictionaryBase", (PyObject *)&NoInstanceDictionaryBaseType) < 0) return; }
static PyObject * init(void) { PyObject *m; #if PY_MAJOR_VERSION < 3 #define DEFINE_STRING(S) \ if(! (str ## S = PyString_FromString(# S))) return NULL #else #define DEFINE_STRING(S) \ if(! (str ## S = PyUnicode_FromString(# S))) return NULL #endif DEFINE_STRING(__dict__); DEFINE_STRING(__implemented__); DEFINE_STRING(__provides__); DEFINE_STRING(__class__); DEFINE_STRING(__providedBy__); DEFINE_STRING(extends); DEFINE_STRING(_implied); DEFINE_STRING(_implements); DEFINE_STRING(_cls); DEFINE_STRING(__conform__); DEFINE_STRING(_call_conform); DEFINE_STRING(_uncached_lookup); DEFINE_STRING(_uncached_lookupAll); DEFINE_STRING(_uncached_subscriptions); DEFINE_STRING(_registry); DEFINE_STRING(_generation); DEFINE_STRING(ro); DEFINE_STRING(changed); #undef DEFINE_STRING adapter_hooks = PyList_New(0); if (adapter_hooks == NULL) return NULL; /* Initialize types: */ SpecType.tp_new = PyBaseObject_Type.tp_new; if (PyType_Ready(&SpecType) < 0) return NULL; OSDType.tp_new = PyBaseObject_Type.tp_new; if (PyType_Ready(&OSDType) < 0) return NULL; CPBType.tp_new = PyBaseObject_Type.tp_new; if (PyType_Ready(&CPBType) < 0) return NULL; InterfaceBase.tp_new = PyBaseObject_Type.tp_new; if (PyType_Ready(&InterfaceBase) < 0) return NULL; LookupBase.tp_new = PyBaseObject_Type.tp_new; if (PyType_Ready(&LookupBase) < 0) return NULL; VerifyingBase.tp_new = PyBaseObject_Type.tp_new; if (PyType_Ready(&VerifyingBase) < 0) return NULL; #if PY_MAJOR_VERSION < 3 /* Create the module and add the functions */ m = Py_InitModule3("_zope_interface_coptimizations", m_methods, "C optimizations for zope.interface\n\n"); #else m = PyModule_Create(&_zic_module); #endif if (m == NULL) return NULL; /* Add types: */ if (PyModule_AddObject(m, "SpecificationBase", OBJECT(&SpecType)) < 0) return NULL; if (PyModule_AddObject(m, "ObjectSpecificationDescriptor", (PyObject *)&OSDType) < 0) return NULL; if (PyModule_AddObject(m, "ClassProvidesBase", OBJECT(&CPBType)) < 0) return NULL; if (PyModule_AddObject(m, "InterfaceBase", OBJECT(&InterfaceBase)) < 0) return NULL; if (PyModule_AddObject(m, "LookupBase", OBJECT(&LookupBase)) < 0) return NULL; if (PyModule_AddObject(m, "VerifyingBase", OBJECT(&VerifyingBase)) < 0) return NULL; if (PyModule_AddObject(m, "adapter_hooks", adapter_hooks) < 0) return NULL; return m; }
PyMODINIT_FUNC init_zope_interface_coptimizations(void) { PyObject *m; #define DEFINE_STRING(S) \ if(! (str ## S = PyString_FromString(# S))) return DEFINE_STRING(__dict__); DEFINE_STRING(__implemented__); DEFINE_STRING(__provides__); DEFINE_STRING(__class__); DEFINE_STRING(__providedBy__); DEFINE_STRING(extends); DEFINE_STRING(_implied); DEFINE_STRING(_implements); DEFINE_STRING(_cls); DEFINE_STRING(__conform__); DEFINE_STRING(_call_conform); DEFINE_STRING(_uncached_lookup); DEFINE_STRING(_uncached_lookupAll); DEFINE_STRING(_uncached_subscriptions); DEFINE_STRING(_registry); DEFINE_STRING(_generation); DEFINE_STRING(ro); DEFINE_STRING(changed); #undef DEFINE_STRING adapter_hooks = PyList_New(0); if (adapter_hooks == NULL) return; /* Initialize types: */ SpecType.tp_new = PyBaseObject_Type.tp_new; if (PyType_Ready(&SpecType) < 0) return; OSDType.tp_new = PyBaseObject_Type.tp_new; if (PyType_Ready(&OSDType) < 0) return; CPBType.tp_new = PyBaseObject_Type.tp_new; if (PyType_Ready(&CPBType) < 0) return; InterfaceBase.tp_new = PyBaseObject_Type.tp_new; if (PyType_Ready(&InterfaceBase) < 0) return; LookupBase.tp_new = PyBaseObject_Type.tp_new; if (PyType_Ready(&LookupBase) < 0) return; VerifyingBase.tp_new = PyBaseObject_Type.tp_new; if (PyType_Ready(&VerifyingBase) < 0) return; /* Create the module and add the functions */ m = Py_InitModule3("_zope_interface_coptimizations", m_methods, "C optimizations for zope.interface\n\n" "$Id: _zope_interface_coptimizations.c 106268 2009-12-08 08:29:06Z wosc $"); if (m == NULL) return; /* Add types: */ if (PyModule_AddObject(m, "SpecificationBase", OBJECT(&SpecType)) < 0) return; if (PyModule_AddObject(m, "ObjectSpecificationDescriptor", (PyObject *)&OSDType) < 0) return; if (PyModule_AddObject(m, "ClassProvidesBase", OBJECT(&CPBType)) < 0) return; if (PyModule_AddObject(m, "InterfaceBase", OBJECT(&InterfaceBase)) < 0) return; if (PyModule_AddObject(m, "LookupBase", OBJECT(&LookupBase)) < 0) return; if (PyModule_AddObject(m, "VerifyingBase", OBJECT(&VerifyingBase)) < 0) return; if (PyModule_AddObject(m, "adapter_hooks", adapter_hooks) < 0) return; }