Update of /cvsroot/pywin32/pywin32/isapi/src
In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv24145
Modified Files:
PythonEng.cpp PythonEng.h pyISAPI.cpp
Log Message:
Fix one or 2 early exits which would have resulted in the thread lock not
being released correctly, which could lead to a deadlock! Bit the bullet
and moved to a class based scheme using the destructor to release, meaning
even ones I didn't notice get fixed and making these much less likely in
the future.
Index: pyISAPI.cpp
===================================================================
RCS file: /cvsroot/pywin32/pywin32/isapi/src/pyISAPI.cpp,v
retrieving revision 1.3
retrieving revision 1.4
diff -C2 -d -r1.3 -r1.4
*** pyISAPI.cpp 17 Mar 2006 01:05:34 -0000 1.3
--- pyISAPI.cpp 11 Oct 2006 07:55:10 -0000 1.4
***************
*** 73,77 ****
PyObject *resultobject = NULL;
bool bRetStatus = true;
! PyGILState_STATE state = PyGILState_Ensure();
// create the Python object
--- 73,77 ----
PyObject *resultobject = NULL;
bool bRetStatus = true;
! CEnterLeavePython celp;
// create the Python object
***************
*** 92,96 ****
}
Py_XDECREF(resultobject);
- PyGILState_Release(state);
return bRetStatus;
}
--- 92,95 ----
***************
*** 99,103 ****
{
DWORD result;
! PyGILState_STATE state = PyGILState_Ensure();
CControlBlock * pcb = new CControlBlock(pECB);
// PyECB takes ownership of pcb - so when it dies, so does pcb.
--- 98,102 ----
{
DWORD result;
! CEnterLeavePython celp;
CControlBlock * pcb = new CControlBlock(pECB);
// PyECB takes ownership of pcb - so when it dies, so does pcb.
***************
*** 123,127 ****
Py_DECREF(pyECB);
Py_XDECREF(resultobject);
- PyGILState_Release(state);
return result;
}
--- 122,125 ----
***************
*** 131,135 ****
// extension is being terminated
BOOL bRetStatus;
! PyGILState_STATE state = PyGILState_Ensure();
PyObject *resultobject = extensionHandler.Callback(HANDLER_TERM, "(i)", dwFlags);
if (! resultobject) {
--- 129,133 ----
// extension is being terminated
BOOL bRetStatus;
! CEnterLeavePython celp;
PyObject *resultobject = extensionHandler.Callback(HANDLER_TERM, "(i)", dwFlags);
if (! resultobject) {
***************
*** 147,151 ****
}
Py_XDECREF(resultobject);
- PyGILState_Release(state);
extensionHandler.Term();
return bRetStatus;
--- 145,148 ----
***************
*** 161,165 ****
return FALSE;
! PyGILState_STATE state = PyGILState_Ensure();
PyFILTER_VERSION *pyFV = new PyFILTER_VERSION(pVer);
PyObject *resultobject = filterHandler.Callback(HANDLER_INIT, "(N)", pyFV);
--- 158,162 ----
return FALSE;
! CEnterLeavePython celp;
PyFILTER_VERSION *pyFV = new PyFILTER_VERSION(pVer);
PyObject *resultobject = filterHandler.Callback(HANDLER_INIT, "(N)", pyFV);
***************
*** 179,183 ****
}
Py_XDECREF(resultobject);
- PyGILState_Release(state);
return bRetStatus;
}
--- 176,179 ----
***************
*** 186,190 ****
{
DWORD action;
! PyGILState_STATE state = PyGILState_Ensure();
PyObject *resultobject = NULL;
--- 182,186 ----
{
DWORD action;
! CEnterLeavePython celp;
PyObject *resultobject = NULL;
***************
*** 215,219 ****
Py_DECREF(pyHFC);
Py_XDECREF(resultobject);
- PyGILState_Release(state);
return action;
}
--- 211,214 ----
***************
*** 224,228 ****
{
BOOL bRetStatus;
! PyGILState_STATE state = PyGILState_Ensure();
PyObject *resultobject = filterHandler.Callback(HANDLER_TERM, "(i)", status);
if (! resultobject) {
--- 219,223 ----
{
BOOL bRetStatus;
! CEnterLeavePython celp;
PyObject *resultobject = filterHandler.Callback(HANDLER_TERM, "(i)", status);
if (! resultobject) {
***************
*** 240,244 ****
}
Py_XDECREF(resultobject);
- PyGILState_Release(state);
// filter is being terminated
filterHandler.Term();
--- 235,238 ----
Index: PythonEng.cpp
===================================================================
RCS file: /cvsroot/pywin32/pywin32/isapi/src/PythonEng.cpp,v
retrieving revision 1.3
retrieving revision 1.4
diff -C2 -d -r1.3 -r1.4
*** PythonEng.cpp 9 Sep 2006 03:32:00 -0000 1.3
--- PythonEng.cpp 11 Oct 2006 07:55:10 -0000 1.4
***************
*** 85,89 ****
if (isapi_package)
m_reload_exception = PyObject_GetAttrString(isapi_package,
! "InternalReloadException");
Py_XDECREF(isapi_package);
PyGILState_Release(old_state);
--- 85,89 ----
if (isapi_package)
m_reload_exception = PyObject_GetAttrString(isapi_package,
! "InternalReloadException");
Py_XDECREF(isapi_package);
PyGILState_Release(old_state);
***************
*** 190,194 ****
char szErrBuf[1024];
PyObject *m;
! PyGILState_STATE old_state = PyGILState_Ensure();
m = PyImport_ImportModule(m_engine->m_module_name);
if (m && reload) {
--- 190,194 ----
char szErrBuf[1024];
PyObject *m;
! CEnterLeavePython celp;
m = PyImport_ImportModule(m_engine->m_module_name);
if (m && reload) {
***************
*** 210,215 ****
}
Py_DECREF(m);
! }
! PyGILState_Release(old_state);
return m_handler != NULL;
}
--- 210,214 ----
}
Py_DECREF(m);
! }
return m_handler != NULL;
}
***************
*** 221,225 ****
return true; // already have the callback.
! PyGILState_STATE old_state = PyGILState_Ensure();
if (!m_handler) {
PyErr_SetString(PyExc_RuntimeError, "The handler failed to load");
--- 220,224 ----
return true; // already have the callback.
! CEnterLeavePython celp;
if (!m_handler) {
PyErr_SetString(PyExc_RuntimeError, "The handler failed to load");
***************
*** 229,233 ****
if (!*cb)
ExtensionError(NULL, "Failed to locate the callback");
- PyGILState_Release(old_state);
return (*cb) != NULL;
}
--- 228,231 ----
***************
*** 354,358 ****
char *windows_error = ::GetLastError() ?
::FormatSysError(::GetLastError()) : NULL;
! PyGILState_STATE s = PyGILState_Ensure();
PySys_WriteStderr("Internal Extension Error: %s\n", errmsg);
if (windows_error)
--- 352,357 ----
char *windows_error = ::GetLastError() ?
::FormatSysError(::GetLastError()) : NULL;
! { // temp scope to release python lock
! CEnterLeavePython celp;
PySys_WriteStderr("Internal Extension Error: %s\n", errmsg);
if (windows_error)
***************
*** 362,366 ****
PyErr_Clear();
}
! PyGILState_Release(s);
if (pcb) {
char *htmlStream = HTMLErrorResp(errmsg);
--- 361,365 ----
PyErr_Clear();
}
! } // end temp scope
if (pcb) {
char *htmlStream = HTMLErrorResp(errmsg);
***************
*** 382,386 ****
void FilterError(CFilterContext *pfc, LPCTSTR errmsg)
{
! PyGILState_STATE s = PyGILState_Ensure();
PySys_WriteStderr("Internal Filter Error: %s\n", errmsg);
if (PyErr_Occurred()) {
--- 381,385 ----
void FilterError(CFilterContext *pfc, LPCTSTR errmsg)
{
! CEnterLeavePython celp;
PySys_WriteStderr("Internal Filter Error: %s\n", errmsg);
if (PyErr_Occurred()) {
***************
*** 388,392 ****
PyErr_Clear();
}
- PyGILState_Release(s);
// what else to do here? AddResponseHeaders->WriteClient?
}
--- 387,390 ----
Index: PythonEng.h
===================================================================
RCS file: /cvsroot/pywin32/pywin32/isapi/src/PythonEng.h,v
retrieving revision 1.1
retrieving revision 1.2
diff -C2 -d -r1.1 -r1.2
*** PythonEng.h 6 Oct 2004 05:11:53 -0000 1.1
--- PythonEng.h 11 Oct 2006 07:55:10 -0000 1.2
***************
*** 94,96 ****
--- 94,106 ----
void ExtensionError(CControlBlock *pcb, LPCTSTR errmsg);
void FilterError(CFilterContext *pfc, LPCTSTR errmsg);
+
+ class CEnterLeavePython {
+ public:
+ CEnterLeavePython() : state(PyGILState_Ensure()) {;}
+ ~CEnterLeavePython() {PyGILState_Release(state);}
+ protected:
+ PyGILState_STATE state;
+
+ };
+
#endif // __PythonEngine_H
\ No newline at end of file
|