Update of /cvsroot/pywin32/pywin32/Pythonwin
In directory ddv4jf1.ch3.sourceforge.com:/tmp/cvs-serv14086/Pythonwin
Modified Files:
ddemodule.cpp win32uimodule.cpp win32uiole.cpp
Log Message:
More modules use the PYWIN_MODULE_* macros
Index: win32uiole.cpp
===================================================================
RCS file: /cvsroot/pywin32/pywin32/Pythonwin/win32uiole.cpp,v
retrieving revision 1.9
retrieving revision 1.10
diff -C2 -d -r1.9 -r1.10
*** win32uiole.cpp 13 Nov 2008 04:04:50 -0000 1.9
--- win32uiole.cpp 9 Dec 2008 07:21:06 -0000 1.10
***************
*** 188,199 ****
}
! extern "C" __declspec(dllexport) void
! initwin32uiole(void)
{
! PyObject *module = Py_InitModule("win32uiole", win32uiole_functions);
! if (!module) /* Eeek - some serious error! */
! return;
! PyObject *dict = PyModule_GetDict(module);
! if (!dict) return; /* Another serious error!*/
! AddConstants(module);
}
--- 188,206 ----
}
! PYWIN_MODULE_INIT_FUNC(win32uiole)
{
! PYWIN_MODULE_INIT_PREPARE(win32uiole, win32uiole_functions,
! "A module, encapsulating the Microsoft Foundation Classes OLE functionality.");
!
! if (AddConstants(module))
! PYWIN_MODULE_INIT_RETURN_ERROR;
!
! if (PyType_Ready(&PyCCommonDialog::type) == - 1 ||
! PyType_Ready(&PyCOleDialog::type) == -1 ||
! PyType_Ready(&PyCOleInsertDialog::type) == -1 ||
! PyType_Ready(&PyCOleDocument::type) == -1 ||
! PyType_Ready(&PyCOleClientItem::type) == -1)
! PYWIN_MODULE_INIT_RETURN_ERROR;
!
! PYWIN_MODULE_INIT_RETURN_SUCCESS;
}
Index: ddemodule.cpp
===================================================================
RCS file: /cvsroot/pywin32/pywin32/Pythonwin/ddemodule.cpp,v
retrieving revision 1.2
retrieving revision 1.3
diff -C2 -d -r1.2 -r1.3
*** ddemodule.cpp 13 Nov 2008 04:04:50 -0000 1.2
--- ddemodule.cpp 9 Dec 2008 07:21:06 -0000 1.3
***************
*** 161,211 ****
! #if (PY_VERSION_HEX < 0x03000000)
! #define ADD_CONSTANT(tok) if (PyModule_AddIntConstant(module, #tok, tok)) return;
! #else
! #define ADD_CONSTANT(tok) if (PyModule_AddIntConstant(module, #tok, tok)) return NULL;
! #endif
! extern "C" __declspec(dllexport)
! #if (PY_VERSION_HEX < 0x03000000)
! void initdde(void)
! #else
! PyObject *PyInit_dde(void)
! #endif
{
if (AfxGetApp()==NULL) {
PyErr_SetString(PyExc_ImportError, "This must be an MFC application - try loading win32ui first");
! #if (PY_VERSION_HEX < 0x03000000)
! return;
! #else
! return NULL;
! #endif
}
!
! PyObject *dict, *module;
! PyWinGlobals_Ensure();
!
! #if (PY_VERSION_HEX < 0x03000000)
! module = Py_InitModule("dde", dde_functions);
! if (!module)
! return;
! dict = PyModule_GetDict(module);
! if (!dict)
! return;
! #else
! static PyModuleDef dde_def = {
! PyModuleDef_HEAD_INIT,
! "dde",
! "A module for Dynamic Data Exchange support",
! -1,
! dde_functions
! };
! module = PyModule_Create(&dde_def);
! if (!module)
! return NULL;
! dict = PyModule_GetDict(module);
! if (!dict)
! return NULL;
! #endif
dde_module_error = PyErr_NewException("dde.error", NULL, NULL);
--- 161,174 ----
! #define ADD_CONSTANT(tok) if (PyModule_AddIntConstant(module, #tok, tok)) PYWIN_MODULE_INIT_RETURN_ERROR;
! PYWIN_MODULE_INIT_FUNC(dde)
{
if (AfxGetApp()==NULL) {
PyErr_SetString(PyExc_ImportError, "This must be an MFC application - try loading win32ui first");
! PYWIN_MODULE_INIT_RETURN_ERROR;
}
! PYWIN_MODULE_INIT_PREPARE(dde, dde_functions,
! "A module for Dynamic Data Exchange support");
dde_module_error = PyErr_NewException("dde.error", NULL, NULL);
***************
*** 236,241 ****
ADD_CONSTANT(MF_SENDMSGS); // Notifies the callback function whenever the system or an application sends a DDE message.
! #if (PY_VERSION_HEX >= 0x03000000)
! return module;
! #endif
}
--- 199,202 ----
ADD_CONSTANT(MF_SENDMSGS); // Notifies the callback function whenever the system or an application sends a DDE message.
! PYWIN_MODULE_INIT_RETURN_SUCCESS;
}
Index: win32uimodule.cpp
===================================================================
RCS file: /cvsroot/pywin32/pywin32/Pythonwin/win32uimodule.cpp,v
retrieving revision 1.44
retrieving revision 1.45
diff -C2 -d -r1.44 -r1.45
*** win32uimodule.cpp 6 Dec 2008 01:50:53 -0000 1.44
--- win32uimodule.cpp 9 Dec 2008 07:21:06 -0000 1.45
***************
*** 47,52 ****
extern DWORD DebuggerThreadFunc( LPDWORD lpdwWhatever );
- static char BASED_CODE uiModName[] = "win32ui";
-
// We can't init exceptionHandler in initwin32ui because the application using
// us could have called SetExceptionHandler earlier. We do a forward declaration
--- 47,50 ----
***************
*** 2248,2292 ****
}
extern bool CheckGoodWinApp();
extern HINSTANCE hWin32uiDll; // Handle to this DLL, from dllmain.cpp
/* Initialize this module. */
! extern "C" __declspec(dllexport) void
! initwin32ui(void)
{
! // XXX - hack alert!
! // Win9x manages to wind up in here twice when used from a console -
! // CheckGoodWinApp() winds up re-initializing - so when we return
! // we see if we already did init, and get out.
! // Would be nice to solve this properly, but Win9x is a bitch to debug :(
! static bool bInitialized = false;
! if (!CheckGoodWinApp()) {
! PyErr_SetString(PyExc_RuntimeError, "The win32ui module could not initialize the application object.");
! return;
! }
! if (bInitialized)
! return;
! PyWinGlobals_Ensure();
! PyObject *dict, *module;
!
! #define RETURN_ERROR return; // path to py3k...
! module = Py_InitModule(uiModName, ui_functions);
! if (!module) /* Eeek - some serious error! */
! return;
! dict = PyModule_GetDict(module);
! if (!dict)
! RETURN_ERROR;
! ui_module_error = PyErr_NewException("win32ui.error", NULL, NULL);
! if ((ui_module_error == NULL) || PyDict_SetItemString(dict, "error", ui_module_error) == -1)
! RETURN_ERROR;
! // drop email addy - too many ppl use it for support requests for other
! // tools that simply embed Pythonwin...
! PyObject *copyright = PyWinCoreString_FromString("Copyright 1994-2008 Mark Hammond");
! if ((copyright == NULL) || PyDict_SetItemString(dict, "copyright", copyright) == -1)
! RETURN_ERROR;
! Py_XDECREF(copyright);
PyObject *dllhandle = PyWinLong_FromHANDLE(hWin32uiDll);
--- 2246,2306 ----
}
+
+ /* PyType_Ready assures that the type's tp_base is ready, but it does *not* call
+ itself for entries in tp_bases, leading to a crash or indecipherable errors
+ if one of multiple bases is not itself ready.
+ This should probably be reported as a bug.
+ */
+ int PyWinType_Ready(PyTypeObject *pT)
+ {
+ if (pT->tp_flags & Py_TPFLAGS_READY)
+ return 0;
+ if (pT->tp_bases == NULL)
+ return 0;
+ Py_ssize_t base_cnt=PyTuple_GET_SIZE(pT->tp_bases);
+ for (Py_ssize_t b=0; b<base_cnt; b++){
+ PyTypeObject *base_type = (PyTypeObject *)PyTuple_GET_ITEM(pT->tp_bases, b);
+ if (PyWinType_Ready(base_type) == -1)
+ return -1;
+ if (PyType_Ready(base_type) == -1)
+ return -1;
+ }
+ return 0;
+ }
+
extern bool CheckGoodWinApp();
extern HINSTANCE hWin32uiDll; // Handle to this DLL, from dllmain.cpp
/* Initialize this module. */
! PYWIN_MODULE_INIT_FUNC(win32ui)
{
! // For various hysterical reasons, Win32uiApplicationInit also calls
! // initwin32ui, meaning we need to deal with being called multiple
! // times.
! static PyObject *existing_module = NULL;
! if (!CheckGoodWinApp()) {
! PyErr_SetString(PyExc_RuntimeError, "The win32ui module could not initialize the application object.");
! PYWIN_MODULE_INIT_RETURN_ERROR;
! }
! if (existing_module)
! #if (PY_VERSION_HEX < 0x03000000)
! return;
! #else
! return existing_module;
! #endif
! PYWIN_MODULE_INIT_PREPARE(win32ui, ui_functions,
! "A module, encapsulating the Microsoft Foundation Classes.");
! ui_module_error = PyErr_NewException("win32ui.error", NULL, NULL);
! if ((ui_module_error == NULL) || PyDict_SetItemString(dict, "error", ui_module_error) == -1)
! PYWIN_MODULE_INIT_RETURN_ERROR;
! // drop email addy - too many ppl use it for support requests for other
! // tools that simply embed Pythonwin...
! PyObject *copyright = PyWinCoreString_FromString("Copyright 1994-2008 Mark Hammond");
! if ((copyright == NULL) || PyDict_SetItemString(dict, "copyright", copyright) == -1)
! PYWIN_MODULE_INIT_RETURN_ERROR;
! Py_XDECREF(copyright);
PyObject *dllhandle = PyWinLong_FromHANDLE(hWin32uiDll);
***************
*** 2304,2308 ****
HookWindowsMessages(); // need to be notified of certain events...
if (AddConstants(module) == -1)
! RETURN_ERROR;
// Add all the types.
--- 2318,2322 ----
HookWindowsMessages(); // need to be notified of certain events...
if (AddConstants(module) == -1)
! PYWIN_MODULE_INIT_RETURN_ERROR;
// Add all the types.
***************
*** 2313,2324 ****
ui_type_CObject *pT;
ui_type_CObject::typemap->GetNextAssoc(pos, pRT, pT);
! PyObject *typeName = PyString_FromString(pT->tp_name);
! PyDict_SetItem(typeDict, typeName, (PyObject *)pT);
! Py_XDECREF(typeName);
}
PyDict_SetItemString(dict, "types", typeDict);
Py_XDECREF(typeDict);
! bInitialized = true;
}
--- 2327,2345 ----
ui_type_CObject *pT;
ui_type_CObject::typemap->GetNextAssoc(pos, pRT, pT);
!
! PyObject *typeName = PyWinCoreString_FromString(pT->tp_name);
! // PyType_Ready sets tp_mro for inheritance to work, so it *must* be called on the type objects now.
! if ((typeName==NULL)
! ||(PyWinType_Ready(pT)==-1)
! ||(PyDict_SetItem(typeDict, typeName, (PyObject *)pT)==-1))
! PYWIN_MODULE_INIT_RETURN_ERROR;
! Py_XDECREF(typeName);
}
PyDict_SetItemString(dict, "types", typeDict);
Py_XDECREF(typeDict);
! existing_module = module;
!
! PYWIN_MODULE_INIT_RETURN_SUCCESS;
}
***************
*** 2423,2432 ****
// a risk that when Python does "import win32ui", it
// will locate a different one, causing obvious grief!
initwin32ui();
-
// Set sys.argv if not already done!
! PyObject *argv = PySys_GetObject("argv");
! if (argv==NULL && __argv!=NULL && __argc > 0)
! PySys_SetArgv(__argc-1, __argv+1);
// If the versions of the .h file are not in synch, then we are in trouble!
if (pGlue->versionNo != WIN32UIHOSTGLUE_VERSION) {
--- 2444,2464 ----
// a risk that when Python does "import win32ui", it
// will locate a different one, causing obvious grief!
+ PyObject *argv = PySys_GetObject("argv");
+ #if (PY_VERSION_HEX < 0x03000000)
initwin32ui();
// Set sys.argv if not already done!
! if (argv==NULL && __targv!=NULL && __argc > 0)
! PySys_SetArgv(__argc-1, __targv+1);
! #else
! PyInit_win32ui();
! if (argv==NULL) {
! int myargc;
! LPWSTR *myargv = CommandLineToArgvW(GetCommandLineW(), &myargc);
! if (myargv) {
! PySys_SetArgv(myargc-1, myargv+1);
! LocalFree(myargv);
! }
! }
! #endif
// If the versions of the .h file are not in synch, then we are in trouble!
if (pGlue->versionNo != WIN32UIHOSTGLUE_VERSION) {
|