Update of /cvsroot/pywin32/pywin32/win32/src
In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv16738/src
Modified Files:
PyWinTypesmodule.cpp
Log Message:
ensure longs that can fit in 32 unsigned bits can be used as a handle
Index: PyWinTypesmodule.cpp
===================================================================
RCS file: /cvsroot/pywin32/pywin32/win32/src/PyWinTypesmodule.cpp,v
retrieving revision 1.35
retrieving revision 1.36
diff -C2 -d -r1.35 -r1.36
*** PyWinTypesmodule.cpp 17 Oct 2007 04:16:16 -0000 1.35
--- PyWinTypesmodule.cpp 30 Oct 2007 09:53:32 -0000 1.36
***************
*** 545,557 ****
{
assert(!PyErr_Occurred()); // lingering exception?
#ifdef _WIN64
! *pptr=(void *)PyLong_AsLongLong(ob);
#else
! *pptr=(void *)PyInt_AsLong(ob);
#endif
! if (*pptr==(void *)-1 && PyErr_Occurred()){
! PyErr_Format(PyExc_TypeError,"Unable to convert %s to pointer-sized value", ob->ob_type->tp_name);
! return FALSE;
}
return TRUE;
}
--- 545,570 ----
{
assert(!PyErr_Occurred()); // lingering exception?
+ // PyInt_AsLong (and PyLong_AsLongLong on x64) handle objects
+ // with tp_number slots, and longs that fit in 32bits - but *not*
+ // longs that fit in 32bits if they are treated as unsigned - eg,
+ // eg, the result of:
+ // struct.unpack("P", struct.pack("P", -1)) -> (4294967295L,)
+ // So, we do the PyInt_AsLong thing first, then fall back to the
+ // *_AsUnsignedLong[Long] versions.
#ifdef _WIN64
! # define SIGNED_CONVERTER PyLong_AsLongLong
! # define UNSIGNED_CONVERTER PyLong_AsUnsignedLongLong
#else
! # define SIGNED_CONVERTER PyInt_AsLong
! # define UNSIGNED_CONVERTER PyLong_AsUnsignedLong
#endif
! *pptr=(void *)SIGNED_CONVERTER(ob);
! if (*pptr==(void *)-1 && PyErr_Occurred()) {
! *pptr=(void *)UNSIGNED_CONVERTER(ob);
! if (*pptr==(void *)-1 && PyErr_Occurred()) {
! PyErr_Format(PyExc_TypeError,"Unable to convert %s to pointer-sized value", ob->ob_type->tp_name);
! return FALSE;
}
+ }
return TRUE;
}
|