Update of /cvsroot/pywin32/pywin32/win32/src
In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv9412
Modified Files:
PyWinTypesmodule.cpp
Log Message:
Report the type of the object that couldn't be converted to a WPARAM, and
add some comments about the current impl.
Index: PyWinTypesmodule.cpp
===================================================================
RCS file: /cvsroot/pywin32/pywin32/win32/src/PyWinTypesmodule.cpp,v
retrieving revision 1.30
retrieving revision 1.31
diff -C2 -d -r1.30 -r1.31
*** PyWinTypesmodule.cpp 3 Jun 2007 12:32:09 -0000 1.30
--- PyWinTypesmodule.cpp 13 Jul 2007 03:00:57 -0000 1.31
***************
*** 545,548 ****
--- 545,549 ----
BOOL PyWinLong_AsVoidPtr(PyObject *ob, void **pptr)
{
+ assert(!PyErr_Occurred()); // lingering exception?
#ifdef _WIN64
*pptr=(void *)PyLong_AsLongLong(ob);
***************
*** 615,626 ****
// Conversion for WPARAM and LPARAM
! /* ??? WPARAM is defined as UINT_PTR, and LPARAM is defined as LONG_PTR.
! Make separate functions to avoid cast ??? */
BOOL PyWinObject_AsPARAM(PyObject *ob, WPARAM *pparam)
{
if (ob==NULL || ob==Py_None){
*pparam=NULL;
return TRUE;
}
#ifdef UNICODE
#define TCHAR_DESC "Unicode"
--- 616,630 ----
// Conversion for WPARAM and LPARAM
! // (WPARAM is defined as UINT_PTR, and LPARAM is defined as LONG_PTR - see
! // pywintypes.h for inline functions to resolve this)
BOOL PyWinObject_AsPARAM(PyObject *ob, WPARAM *pparam)
{
+ assert(!PyErr_Occurred()); // lingering exception?
if (ob==NULL || ob==Py_None){
*pparam=NULL;
return TRUE;
}
+ // XXX - why this UNICODE block? Can't we just do both anyway? Maybe
+ // just via the buffer interface?
#ifdef UNICODE
#define TCHAR_DESC "Unicode"
***************
*** 630,634 ****
}
#else
! #define TCHAR_DESC "String"
if (PyString_Check(ob)){
*pparam = (WPARAM)PyString_AS_STRING(ob);
--- 634,638 ----
}
#else
! #define TCHAR_DESC "String"
if (PyString_Check(ob)){
*pparam = (WPARAM)PyString_AS_STRING(ob);
***************
*** 636,647 ****
}
#endif
- if (PyWinLong_AsVoidPtr(ob, (void **)pparam))
- return TRUE;
-
- PyErr_Clear();
PyBufferProcs *pb = ob->ob_type->tp_as_buffer;
if (pb != NULL && pb->bf_getreadbuffer)
return pb->bf_getreadbuffer(ob,0,(VOID **)pparam)!=-1;
! PyErr_SetString(PyExc_TypeError, "WPARAM must be a " TCHAR_DESC ", int, or buffer object");
return FALSE;
}
--- 640,654 ----
}
#endif
PyBufferProcs *pb = ob->ob_type->tp_as_buffer;
if (pb != NULL && pb->bf_getreadbuffer)
return pb->bf_getreadbuffer(ob,0,(VOID **)pparam)!=-1;
!
! if (PyWinLong_AsVoidPtr(ob, (void **)pparam))
! return TRUE;
!
! if (!PyErr_Occurred())
! PyErr_Format(PyExc_TypeError,
! "WPARAM must be a " TCHAR_DESC ", int, or buffer object (got %s)",
! ob->ob_type->tp_name);
return FALSE;
}
|