Update of /cvsroot/pywin32/pywin32/com/win32com/src
In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv14371
Modified Files:
ErrorUtils.cpp PyFactory.cpp PyGatewayBase.cpp dllmain.cpp
univgw.cpp
Log Message:
Move towards clearer error handling using the logging module features.
Remove old deprecated methods, remove public declarations of private
methods and add new MAKE_PYCOM_GATEWAY_FAILURE_CODE which all gateways
should use.
Index: ErrorUtils.cpp
===================================================================
RCS file: /cvsroot/pywin32/pywin32/com/win32com/src/ErrorUtils.cpp,v
retrieving revision 1.22
retrieving revision 1.23
diff -C2 -d -r1.22 -r1.23
*** ErrorUtils.cpp 25 Jan 2005 11:11:40 -0000 1.22
--- ErrorUtils.cpp 25 Jan 2005 13:33:12 -0000 1.23
***************
*** 23,26 ****
--- 23,29 ----
static const char *traceback_prefix = "Traceback (most recent call last):\n";
+ // todo: nuke me!
+ PYCOM_EXPORT void PyCom_StreamMessage(const char *msg);
+
////////////////////////////////////////////////////////////////////////
//
***************
*** 326,329 ****
--- 329,337 ----
return S_OK;
+ // These errors are generally 'unexpected' (ie, errors converting args on
+ // the way into a gateway method. If not explicitly raised by the user,
+ // log it.
+ PyCom_LoggerNonServerException(NULL, "Unexpected gateway error");
+
EXCEPINFO einfo;
PyCom_ExcepInfoFromPyException(&einfo);
***************
*** 344,348 ****
// No error occurred
return S_OK;
! PyCom_LogNonServerError("Unexpected exception in gateway method '%s'", methodName);
return PyCom_SetCOMErrorFromPyException(riid);
}
--- 352,356 ----
// No error occurred
return S_OK;
! PyCom_LoggerNonServerException(NULL, "Unexpected exception in gateway method '%s'", methodName);
return PyCom_SetCOMErrorFromPyException(riid);
}
***************
*** 559,563 ****
}
! void _DoLogError(const char *fmt, va_list argptr)
{
PyCom_StreamMessage("pythoncom error: ");
--- 567,574 ----
}
! // XXX - _DoLogError() was a really bad name in retrospect, given
! // the "logger" module and my dumb choice of _DoLogger() for logger errors :)
! // Thankfully both are private.
! static void _DoLogError(const char *fmt, va_list argptr)
{
PyCom_StreamMessage("pythoncom error: ");
***************
*** 575,613 ****
}
! PYCOM_EXPORT
! void PyCom_LogError(const char *fmt, ...)
! {
! va_list marker;
! va_start(marker, fmt);
! _DoLogError(fmt, marker);
! }
!
! BOOL IsNonServerErrorCurrent() {
! BOOL rc = FALSE;
! PyObject *exc_typ = NULL, *exc_val = NULL, *exc_tb = NULL;
! PyErr_Fetch( &exc_typ, &exc_val, &exc_tb);
! if (exc_typ) {
! PyErr_NormalizeException( &exc_typ, &exc_val, &exc_tb);
! rc = (!PyErr_GivenExceptionMatches(exc_val, PyWinExc_COMError) ||
! ((PyInstance_Check(exc_val) &&
! (PyObject *)(((PyInstanceObject *)exc_val)->in_class)==PyWinExc_COMError)));
! }
! PyErr_Restore(exc_typ, exc_val, exc_tb);
! return rc;
! }
!
! PYCOM_EXPORT
! void PyCom_LogNonServerError(const char *fmt, ...)
! {
! // If any error other than our explicit 'com server error' is current,
! // assume it is unintended, and log it.
! if (IsNonServerErrorCurrent()) {
! va_list marker;
! va_start(marker, fmt);
! _DoLogError(fmt, marker);
! }
! }
!
! void _DoLogger(PyObject *logProvider, char *log_method, const char *fmt, va_list argptr)
{
PyObject *exc_typ = NULL, *exc_val = NULL, *exc_tb = NULL;
--- 586,590 ----
}
! static void _DoLogger(PyObject *logProvider, char *log_method, const char *fmt, va_list argptr)
{
PyObject *exc_typ = NULL, *exc_val = NULL, *exc_tb = NULL;
***************
*** 636,639 ****
--- 613,638 ----
}
+ PYCOM_EXPORT
+ void PyCom_LogError(const char *fmt, ...)
+ {
+ va_list marker;
+ va_start(marker, fmt);
+ _DoLogger(NULL, "error", fmt, marker);
+ }
+
+ BOOL IsNonServerErrorCurrent() {
+ BOOL rc = FALSE;
+ PyObject *exc_typ = NULL, *exc_val = NULL, *exc_tb = NULL;
+ PyErr_Fetch( &exc_typ, &exc_val, &exc_tb);
+ if (exc_typ) {
+ PyErr_NormalizeException( &exc_typ, &exc_val, &exc_tb);
+ rc = (!PyErr_GivenExceptionMatches(exc_val, PyWinExc_COMError) ||
+ ((PyInstance_Check(exc_val) &&
+ (PyObject *)(((PyInstanceObject *)exc_val)->in_class)==PyWinExc_COMError)));
+ }
+ PyErr_Restore(exc_typ, exc_val, exc_tb);
+ return rc;
+ }
+
PYCOM_EXPORT void PyCom_LoggerException(PyObject *logProvider, const char *fmt, ...)
{
Index: univgw.cpp
===================================================================
RCS file: /cvsroot/pywin32/pywin32/com/win32com/src/univgw.cpp,v
retrieving revision 1.10
retrieving revision 1.11
diff -C2 -d -r1.10 -r1.11
*** univgw.cpp 4 May 2004 06:46:24 -0000 1.10
--- univgw.cpp 25 Jan 2005 13:33:15 -0000 1.11
***************
*** 111,115 ****
if ( result == NULL ) {
! PyCom_LogError("Failed to call the universal dispatcher");
return PyCom_SetCOMErrorFromPyException(vtbl->iid);
}
--- 111,115 ----
if ( result == NULL ) {
! PyCom_LoggerException(NULL, "Failed to call the universal dispatcher");
return PyCom_SetCOMErrorFromPyException(vtbl->iid);
}
Index: PyGatewayBase.cpp
===================================================================
RCS file: /cvsroot/pywin32/pywin32/com/win32com/src/PyGatewayBase.cpp,v
retrieving revision 1.14
retrieving revision 1.15
diff -C2 -d -r1.14 -r1.15
*** PyGatewayBase.cpp 7 Sep 2004 02:19:27 -0000 1.14
--- PyGatewayBase.cpp 25 Jan 2005 13:33:15 -0000 1.15
***************
*** 15,18 ****
--- 15,23 ----
#define LogF PyCom_LogF
+ // Internal ErrorUtil helpers we reach in for.
+ // Free the strings from an excep-info.
+ extern void PyCom_CleanupExcepInfo(EXCEPINFO *pexcepinfo);
+ PYCOM_EXPORT BOOL PyCom_SetCOMErrorFromExcepInfo(const EXCEPINFO *pexcepinfo, REFIID riid);
+
// #define DEBUG_FULL
static LONG cGateways = 0;
Index: dllmain.cpp
===================================================================
RCS file: /cvsroot/pywin32/pywin32/com/win32com/src/dllmain.cpp,v
retrieving revision 1.10
retrieving revision 1.11
diff -C2 -d -r1.10 -r1.11
*** dllmain.cpp 31 Oct 2003 02:46:29 -0000 1.10
--- dllmain.cpp 25 Jan 2005 13:33:15 -0000 1.11
***************
*** 194,200 ****
if ( (hr != RPC_E_CHANGED_MODE) && FAILED(hr) )
{
! #ifdef _DEBUG
! PyCom_LogError(_T("OLE initialization failed! (0x%08lx)"), hr);
! #endif
return hr;
}
--- 194,198 ----
if ( (hr != RPC_E_CHANGED_MODE) && FAILED(hr) )
{
! PyCom_LoggerException(NULL, "OLE initialization failed! (0x%08lx)", hr);
return hr;
}
***************
*** 228,234 ****
if ( (hr != RPC_E_CHANGED_MODE) && FAILED(hr) )
{
! #ifdef _DEBUG
! PyCom_LogError(_T("OLE initialization failed! (0x%08lx)"), hr);
! #endif
return hr;
}
--- 226,230 ----
if ( (hr != RPC_E_CHANGED_MODE) && FAILED(hr) )
{
! PyCom_LoggerException(NULL, "OLE initialization failed! (0x%08lx)", hr);
return hr;
}
Index: PyFactory.cpp
===================================================================
RCS file: /cvsroot/pywin32/pywin32/com/win32com/src/PyFactory.cpp,v
retrieving revision 1.6
retrieving revision 1.7
diff -C2 -d -r1.6 -r1.7
*** PyFactory.cpp 31 Oct 2003 02:43:03 -0000 1.6
--- PyFactory.cpp 25 Jan 2005 13:33:15 -0000 1.7
***************
*** 83,87 ****
if ( FAILED(hr) )
{
! PyCom_LogError("CPyFactory::CreateInstance failed to create instance. (%lx)", hr);
}
else
--- 83,87 ----
if ( FAILED(hr) )
{
! PyCom_LoggerException(NULL, "CPyFactory::CreateInstance failed to create instance. (%lx)", hr);
}
else
***************
*** 90,94 ****
// up (giving more flexibility to the Python programmer.
if (!PyCom_InterfaceFromPyObject(pNewInstance, riid, ppv, FALSE)) {
! PyCom_LogError("CPyFactory::CreateInstance failed to get gateway to returned object");
hr = E_FAIL;
}
--- 90,94 ----
// up (giving more flexibility to the Python programmer.
if (!PyCom_InterfaceFromPyObject(pNewInstance, riid, ppv, FALSE)) {
! PyCom_LoggerException(NULL, "CPyFactory::CreateInstance failed to get gateway to returned object");
hr = E_FAIL;
}
***************
*** 142,146 ****
// change the error state.
if ( !*ppNewInstance )
! PyCom_LogError("ERROR: server.policy could not create an instance.");
HRESULT hr = PyCom_SetCOMErrorFromPyException(IID_IClassFactory);
Py_DECREF(obiid);
--- 142,146 ----
// change the error state.
if ( !*ppNewInstance )
! PyCom_LoggerException(NULL, "ERROR: server.policy could not create an instance.");
HRESULT hr = PyCom_SetCOMErrorFromPyException(IID_IClassFactory);
Py_DECREF(obiid);
***************
*** 162,166 ****
if ( !pPyModule )
{
! PyCom_LogError("PythonCOM Server - The 'win32com.server.policy' module could not be loaded.");
/* ### propagate the exception? */
PyErr_Clear();
--- 162,166 ----
if ( !pPyModule )
{
! PyCom_LoggerException(NULL, "PythonCOM Server - The 'win32com.server.policy' module could not be loaded.");
/* ### propagate the exception? */
PyErr_Clear();
|