[pywin32-checkins] pywin32/com/win32com/src dllmain.cpp,1.12,1.13
OLD project page for the Python extensions for Windows
Brought to you by:
mhammond
From: Mark H. <mha...@us...> - 2006-02-13 01:14:42
|
Update of /cvsroot/pywin32/pywin32/com/win32com/src In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv13377 Modified Files: dllmain.cpp Log Message: Prevent a situation where we would try to re-init Python as it was tearing down! Index: dllmain.cpp =================================================================== RCS file: /cvsroot/pywin32/pywin32/com/win32com/src/dllmain.cpp,v retrieving revision 1.12 retrieving revision 1.13 diff -C2 -d -r1.12 -r1.13 *** dllmain.cpp 11 Nov 2005 02:37:38 -0000 1.12 --- dllmain.cpp 13 Feb 2006 01:14:33 -0000 1.13 *************** *** 39,42 **** --- 39,44 ---- } + static BOOL hasInitialized = FALSE; + void PyCom_DLLAddRef(void) { *************** *** 45,48 **** --- 47,62 ---- LONG cnt = InterlockedIncrement(&g_cLockCount); if (cnt==1) { // First call + // There is a situation where this code falls down. An IClassFactory destructor + // imcrements the DLL ref count, to make up for the decrement done by PyIUnknown + // (as we don't want class factories in the count). This works fine until the last + // reference is that IClassFactory - the g_cLockCount was zero, so transitions + // temporarily to 1 - leading us to this sad situation where we try and re-init + // Python as we tear down. + if (hasInitialized) { + return; + } + hasInitialized = TRUE; // must be set even if we didn't actually Py_Init. + + // the last COM object if (!Py_IsInitialized()) { Py_Initialize(); |