[pywin32-checkins] pywin32/com/win32com/src PythonCOM.cpp, 1.53, 1.54
OLD project page for the Python extensions for Windows
Brought to you by:
mhammond
From: Mark H. <mha...@us...> - 2008-12-08 13:16:42
|
Update of /cvsroot/pywin32/pywin32/com/win32com/src In directory ddv4jf1.ch3.sourceforge.com:/tmp/cvs-serv11284/com/win32com/src Modified Files: PythonCOM.cpp Log Message: py3k friendly: PYWIN_MODULE_* macros to help with module's init etc. Index: PythonCOM.cpp =================================================================== RCS file: /cvsroot/pywin32/pywin32/com/win32com/src/PythonCOM.cpp,v retrieving revision 1.53 retrieving revision 1.54 diff -C2 -d -r1.53 -r1.54 *** PythonCOM.cpp 13 Nov 2008 04:04:51 -0000 1.53 --- PythonCOM.cpp 8 Dec 2008 13:16:36 -0000 1.54 *************** *** 1973,1980 **** /* Module initialisation */ ! extern "C" __declspec(dllexport) void initpythoncom() { - PyObject *oModule; - // The DLL Load inited the module. // All we do here is init COM itself. Done here --- 1973,1978 ---- /* Module initialisation */ ! PYWIN_MODULE_INIT_FUNC(pythoncom) { // The DLL Load inited the module. // All we do here is init COM itself. Done here *************** *** 1998,2017 **** // manually CoInit() to see! // ensure the framework has valid state to work with. ! PyWinGlobals_Ensure(); PyCom_RegisterCoreSupport(); - // Create the module and add the functions - oModule = Py_InitModule(modName, pythoncom_methods); - if (!oModule) /* Eeek - some serious error! */ - return; - - PyObject *dict = PyModule_GetDict(oModule); - if (!dict) return; /* Another serious error!*/ - PyDict_SetItemString(dict, "TypeIIDs", g_obPyCom_MapIIDToType); PyDict_SetItemString(dict, "ServerInterfaces", g_obPyCom_MapGatewayIIDToName); PyDict_SetItemString(dict, "InterfaceNames", g_obPyCom_MapInterfaceNameToIID); g_obEmpty = new PyOleEmpty; PyDict_SetItemString(dict, "Empty", g_obEmpty); --- 1996,2014 ---- // manually CoInit() to see! + PYWIN_MODULE_INIT_PREPARE(pythoncom, pythoncom_methods, + "A module, encapsulating the OLE automation API"); + // ensure the framework has valid state to work with. ! // XXX - more error checking? PyCom_RegisterCoreSupport(); PyDict_SetItemString(dict, "TypeIIDs", g_obPyCom_MapIIDToType); PyDict_SetItemString(dict, "ServerInterfaces", g_obPyCom_MapGatewayIIDToName); PyDict_SetItemString(dict, "InterfaceNames", g_obPyCom_MapInterfaceNameToIID); + if (PyType_Ready(&PyOleEmptyType) == -1 + ||PyType_Ready(&PyOleMissingType) == -1 + ||PyType_Ready(&PyOleArgNotFoundType) == -1) + PYWIN_MODULE_INIT_RETURN_ERROR; g_obEmpty = new PyOleEmpty; PyDict_SetItemString(dict, "Empty", g_obEmpty); *************** *** 2025,2066 **** // Add some symbolic constants to the module // pycom_Error = PyString_FromString("pythoncom.error"); ! PyObject *pycom_Error = PyWinExc_COMError; ! if (pycom_Error == NULL || PyDict_SetItemString(dict, "error", pycom_Error) != 0) ! { ! PyErr_SetString(PyExc_MemoryError, "can't define error"); ! return; ! } ! if (PyWinExc_COMError==NULL || PyDict_SetItemString(dict, "ole_error", PyWinExc_COMError) != 0) { PyErr_SetString(PyExc_MemoryError, "can't define ole_error"); ! return; } // Add the same constant, but with a "new name" if (PyDict_SetItemString(dict, "com_error", PyWinExc_COMError) != 0) ! { ! PyErr_SetString(PyExc_MemoryError, "can't define com_error"); ! return; ! } PyCom_InternalError = PyErr_NewException("pythoncom.internal_error", NULL, NULL); if (PyDict_SetItemString(dict, "internal_error", PyCom_InternalError) != 0) ! { ! PyErr_SetString(PyExc_MemoryError, "can't define internal_error"); ! return; ! } // Add the IIDs if (PyCom_RegisterCoreIIDs(dict) != 0) ! return; // Setup our sub-modules if (!initunivgw(dict)) ! return; ! ! // Add a few types. ! // NOTE - We do not autoduck these types, as they are for b/w compat only ! // New code should use the functions in pywintypes. ! PyDict_SetItemString(dict, "PyTimeType", (PyObject *)&PyTimeType); ! PyDict_SetItemString(dict, "PyIIDType", (PyObject *)&PyIIDType); ! PyDict_SetItemString(dict, "PyUnicodeType", (PyObject *)&PyUnicode_Type); // Load function pointers. --- 2022,2059 ---- // Add some symbolic constants to the module // pycom_Error = PyString_FromString("pythoncom.error"); ! if (PyWinExc_COMError==NULL) { + // This is created by PyWin_Globals_Ensure PyErr_SetString(PyExc_MemoryError, "can't define ole_error"); ! PYWIN_MODULE_INIT_RETURN_ERROR; } + PyObject *pycom_Error = PyWinExc_COMError; + if (PyDict_SetItemString(dict, "ole_error", PyWinExc_COMError) != 0) + PYWIN_MODULE_INIT_RETURN_ERROR; + if (PyDict_SetItemString(dict, "error", pycom_Error) != 0) + PYWIN_MODULE_INIT_RETURN_ERROR; + // Add the same constant, but with a "new name" if (PyDict_SetItemString(dict, "com_error", PyWinExc_COMError) != 0) ! PYWIN_MODULE_INIT_RETURN_ERROR; ! PyCom_InternalError = PyErr_NewException("pythoncom.internal_error", NULL, NULL); if (PyDict_SetItemString(dict, "internal_error", PyCom_InternalError) != 0) ! PYWIN_MODULE_INIT_RETURN_ERROR; // Add the IIDs if (PyCom_RegisterCoreIIDs(dict) != 0) ! PYWIN_MODULE_INIT_RETURN_ERROR; ! ! // Initialize various non-interface types ! if (PyType_Ready(&PyFUNCDESC::Type) == -1 || ! PyType_Ready(&PySTGMEDIUM::Type) == -1 || ! PyType_Ready(&PyTYPEATTR::Type) == -1 || ! PyType_Ready(&PyVARDESC::Type) == -1) ! PYWIN_MODULE_INIT_RETURN_ERROR; // Setup our sub-modules if (!initunivgw(dict)) ! PYWIN_MODULE_INIT_RETURN_ERROR; // Load function pointers. *************** *** 2413,2416 **** // @property int|pythoncom|frozen|1 if the host is a frozen program, else 0 // @property int|pythoncom|dcom|1 if the system is DCOM aware, else 0. Only Win95 without DCOM extensions should return 0 - } --- 2406,2410 ---- // @property int|pythoncom|frozen|1 if the host is a frozen program, else 0 // @property int|pythoncom|dcom|1 if the system is DCOM aware, else 0. Only Win95 without DCOM extensions should return 0 + PYWIN_MODULE_INIT_RETURN_SUCCESS; + } |