Update of /cvsroot/pywin32/pywin32/win32/src
In directory sc8-pr-cvs1:/tmp/cvs-serv5403
Modified Files:
PyHANDLE.cpp
Log Message:
Fix up handle error semantics when destructing. This makes the handles.py
test case work again.
Index: PyHANDLE.cpp
===================================================================
RCS file: /cvsroot/pywin32/pywin32/win32/src/PyHANDLE.cpp,v
retrieving revision 1.6
retrieving revision 1.7
diff -C2 -d -r1.6 -r1.7
*** PyHANDLE.cpp 2 May 2003 00:07:38 -0000 1.6
--- PyHANDLE.cpp 23 Oct 2003 04:11:39 -0000 1.7
***************
*** 53,57 ****
PyWin_SetAPIError("CloseHandle");
} else {
! PyErr_SetString(PyExc_TypeError, "A handle must be a HANDLE object or an integer");
return FALSE;
}
--- 53,57 ----
PyWin_SetAPIError("CloseHandle");
} else {
! PyErr_Format(PyExc_TypeError, "A handle must be a HANDLE object or an integer (got %s)", obHandle->ob_type->tp_name);
return FALSE;
}
***************
*** 350,359 ****
/*static*/ void PyHANDLE::deallocFunc(PyObject *ob)
{
! // Python will print a strange message if we leave pending exceptions in destructors,
! // but we don't want to supress exceptions as generally that is evil (supressing
! // ours is bad enough, but supressing existing ones is nasty).
! // For now, we call it a Python bug that the message is printed.
((PyHANDLE *)ob)->Close();
delete (PyHANDLE *)ob;
}
--- 350,365 ----
/*static*/ void PyHANDLE::deallocFunc(PyObject *ob)
{
! // This can be delicate. Setting an exception in a destructor is evil
! // (as it will cause gc to die with a fatal error, and if that doesn't
! // happen, make unrelated code appear to fail with the exception.)
! // Clearing any existing exceptions that may be set is also evil, as
! // we may be destructing as part of unwinding the stack handling an
! // existing exception. Therefore, we "push" any existing exception
! // contexts, and restoring it clobbers any we raise.
! PyObject *typ, *val, *tb;
! PyErr_Fetch(&typ, &val, &tb);
((PyHANDLE *)ob)->Close();
delete (PyHANDLE *)ob;
+ PyErr_Restore(typ, val, tb);
}
|