PyMODINIT_FUNC initzbar (void) { /* initialize types */ zbarEnumItem_Type.tp_base = &PyInt_Type; zbarException_Type.tp_base = (PyTypeObject*)PyExc_Exception; if(PyType_Ready(&zbarException_Type) < 0 || PyType_Ready(&zbarEnumItem_Type) < 0 || PyType_Ready(&zbarEnum_Type) < 0 || PyType_Ready(&zbarImage_Type) < 0 || PyType_Ready(&zbarSymbol_Type) < 0 || PyType_Ready(&zbarSymbolSet_Type) < 0 || PyType_Ready(&zbarSymbolIter_Type) < 0 || PyType_Ready(&zbarProcessor_Type) < 0 || PyType_Ready(&zbarImageScanner_Type) < 0 || PyType_Ready(&zbarDecoder_Type) < 0 || PyType_Ready(&zbarScanner_Type) < 0) return; /* initialize constant containers */ config_enum = zbarEnum_New(); modifier_enum = zbarEnum_New(); symbol_enum = PyDict_New(); orient_enum = zbarEnum_New(); if(!config_enum || !modifier_enum || !symbol_enum || !orient_enum) return; zbar_exc[0] = (PyObject*)&zbarException_Type; zbar_exc[ZBAR_ERR_NOMEM] = NULL; zbar_error_t ei; for(ei = ZBAR_ERR_INTERNAL; ei < ZBAR_ERR_NUM; ei++) { zbar_exc[ei] = PyErr_NewException(exc_names[ei], zbar_exc[0], NULL); if(!zbar_exc[ei]) return; } /* internally created/read-only type overrides */ zbarEnum_Type.tp_new = NULL; zbarEnum_Type.tp_setattr = NULL; zbarEnum_Type.tp_setattro = NULL; /* initialize module */ PyObject *mod = Py_InitModule("zbar", zbar_functions); if(!mod) return; /* add types to module */ PyModule_AddObject(mod, "EnumItem", (PyObject*)&zbarEnumItem_Type); PyModule_AddObject(mod, "Image", (PyObject*)&zbarImage_Type); PyModule_AddObject(mod, "Config", (PyObject*)config_enum); PyModule_AddObject(mod, "Modifier", (PyObject*)modifier_enum); PyModule_AddObject(mod, "Orient", (PyObject*)orient_enum); PyModule_AddObject(mod, "Symbol", (PyObject*)&zbarSymbol_Type); PyModule_AddObject(mod, "SymbolSet", (PyObject*)&zbarSymbolSet_Type); PyModule_AddObject(mod, "SymbolIter", (PyObject*)&zbarSymbolIter_Type); PyModule_AddObject(mod, "Processor", (PyObject*)&zbarProcessor_Type); PyModule_AddObject(mod, "ImageScanner", (PyObject*)&zbarImageScanner_Type); PyModule_AddObject(mod, "Decoder", (PyObject*)&zbarDecoder_Type); PyModule_AddObject(mod, "Scanner", (PyObject*)&zbarScanner_Type); for(ei = 0; ei < ZBAR_ERR_NUM; ei++) if(zbar_exc[ei]) PyModule_AddObject(mod, exc_names[ei] + 5, zbar_exc[ei]); /* add constants */ PyObject *dict = PyModule_GetDict(mod); color_enum[ZBAR_SPACE] = zbarEnumItem_New(dict, NULL, ZBAR_SPACE, "SPACE"); color_enum[ZBAR_BAR] = zbarEnumItem_New(dict, NULL, ZBAR_BAR, "BAR"); const enumdef *item; for(item = config_defs; item->strval; item++) zbarEnum_Add(config_enum, item->intval, item->strval); for(item = modifier_defs; item->strval; item++) zbarEnum_Add(modifier_enum, item->intval, item->strval); for(item = orient_defs; item->strval; item++) zbarEnum_Add(orient_enum, item->intval, item->strval); PyObject *tp_dict = zbarSymbol_Type.tp_dict; for(item = symbol_defs; item->strval; item++) zbarEnumItem_New(tp_dict, symbol_enum, item->intval, item->strval); symbol_NONE = zbarSymbol_LookupEnum(ZBAR_NONE); }
PyMODINIT_FUNC initzbar () { /* initialize constant containers */ config_enum = zbarEnum_New(); symbol_enum = PyDict_New(); if(!config_enum || !symbol_enum) return; /* initialize types */ zbarEnumItem_Type.tp_base = &PyInt_Type; zbarException_Type.tp_base = (PyTypeObject*)PyExc_Exception; if(PyType_Ready(&zbarException_Type) < 0 || PyType_Ready(&zbarEnumItem_Type) < 0 || PyType_Ready(&zbarEnum_Type) < 0 || PyType_Ready(&zbarImage_Type) < 0 || PyType_Ready(&zbarSymbol_Type) < 0 || PyType_Ready(&zbarSymbolIter_Type) < 0 || PyType_Ready(&zbarProcessor_Type) < 0 || PyType_Ready(&zbarImageScanner_Type) < 0 || PyType_Ready(&zbarDecoder_Type) < 0 || PyType_Ready(&zbarScanner_Type) < 0) return; zbar_exc[0] = (PyObject*)&zbarException_Type; zbar_exc[ZBAR_ERR_NOMEM] = NULL; zbar_error_t ei; for(ei = ZBAR_ERR_INTERNAL; ei < ZBAR_ERR_NUM; ei++) { zbar_exc[ei] = PyErr_NewException(exc_names[ei], zbar_exc[0], NULL); if(!zbar_exc[ei]) return; } /* internally created/read-only type overrides */ zbarEnum_Type.tp_new = NULL; zbarEnum_Type.tp_setattr = NULL; zbarEnum_Type.tp_setattro = NULL; /* initialize module */ PyObject *mod = Py_InitModule("zbar", zbar_functions); if(!mod) return; /* add types to module */ PyModule_AddObject(mod, "EnumItem", (PyObject*)&zbarEnumItem_Type); PyModule_AddObject(mod, "Image", (PyObject*)&zbarImage_Type); PyModule_AddObject(mod, "Config", (PyObject*)config_enum); PyModule_AddObject(mod, "Symbol", (PyObject*)&zbarSymbol_Type); PyModule_AddObject(mod, "SymbolIter", (PyObject*)&zbarSymbolIter_Type); PyModule_AddObject(mod, "Processor", (PyObject*)&zbarProcessor_Type); PyModule_AddObject(mod, "ImageScanner", (PyObject*)&zbarImageScanner_Type); PyModule_AddObject(mod, "Decoder", (PyObject*)&zbarDecoder_Type); PyModule_AddObject(mod, "Scanner", (PyObject*)&zbarScanner_Type); for(ei = 0; ei < ZBAR_ERR_NUM; ei++) if(zbar_exc[ei]) PyModule_AddObject(mod, exc_names[ei] + 5, zbar_exc[ei]); /* add constants */ PyObject *dict = PyModule_GetDict(mod); color_enum[ZBAR_SPACE] = zbarEnumItem_New(dict, NULL, ZBAR_SPACE, "SPACE"); color_enum[ZBAR_BAR] = zbarEnumItem_New(dict, NULL, ZBAR_BAR, "BAR"); zbarEnum_Add(config_enum, ZBAR_CFG_ENABLE, "ENABLE"); zbarEnum_Add(config_enum, ZBAR_CFG_ADD_CHECK, "ADD_CHECK"); zbarEnum_Add(config_enum, ZBAR_CFG_EMIT_CHECK, "EMIT_CHECK"); zbarEnum_Add(config_enum, ZBAR_CFG_ASCII, "ASCII"); zbarEnum_Add(config_enum, ZBAR_CFG_MIN_LEN, "MIN_LEN"); zbarEnum_Add(config_enum, ZBAR_CFG_MAX_LEN, "MAX_LEN"); zbarEnum_Add(config_enum, ZBAR_CFG_X_DENSITY, "X_DENSITY"); zbarEnum_Add(config_enum, ZBAR_CFG_Y_DENSITY, "Y_DENSITY"); PyObject *tp_dict = zbarSymbol_Type.tp_dict; symbol_NONE = zbarEnumItem_New(tp_dict, symbol_enum, ZBAR_NONE, "NONE"); zbarEnumItem_New(tp_dict, symbol_enum, ZBAR_PARTIAL, "PARTIAL"); zbarEnumItem_New(tp_dict, symbol_enum, ZBAR_EAN8, "EAN8"); zbarEnumItem_New(tp_dict, symbol_enum, ZBAR_UPCE, "UPCE"); zbarEnumItem_New(tp_dict, symbol_enum, ZBAR_ISBN10, "ISBN10"); zbarEnumItem_New(tp_dict, symbol_enum, ZBAR_UPCA, "UPCA"); zbarEnumItem_New(tp_dict, symbol_enum, ZBAR_EAN13, "EAN13"); zbarEnumItem_New(tp_dict, symbol_enum, ZBAR_ISBN13, "ISBN13"); zbarEnumItem_New(tp_dict, symbol_enum, ZBAR_I25, "I25"); zbarEnumItem_New(tp_dict, symbol_enum, ZBAR_CODE39, "CODE39"); zbarEnumItem_New(tp_dict, symbol_enum, ZBAR_PDF417, "PDF417"); zbarEnumItem_New(tp_dict, symbol_enum, ZBAR_CODE128, "CODE128"); }