[pywin32-checkins] /hgroot/pywin32/pywin32: Convert PROPVARIANT values outside the ...
OLD project page for the Python extensions for Windows
Brought to you by:
mhammond
From: <pyw...@li...> - 2012-08-23 02:58:25
|
changeset 4f51918ce379 in /hgroot/pywin32/pywin32 details: http://pywin32.hg.sourceforge.net/hgweb/pywin32/pywin32/hgroot/pywin32/pywin32?cmd=changeset;node=4f51918ce379 summary: Convert PROPVARIANT values outside the range of a long to VT_I8 or VT_UI8 diffstat: com/win32com/src/extensions/PyIPropertyStorage.cpp | 26 ++++++++++++++++++++++ 1 files changed, 26 insertions(+), 0 deletions(-) diffs (39 lines): diff -r acf52e97b876 -r 4f51918ce379 com/win32com/src/extensions/PyIPropertyStorage.cpp --- a/com/win32com/src/extensions/PyIPropertyStorage.cpp Wed Aug 22 07:35:18 2012 -0400 +++ b/com/win32com/src/extensions/PyIPropertyStorage.cpp Wed Aug 22 22:57:09 2012 -0400 @@ -322,9 +322,35 @@ } else if (ob==Py_False) { pVar->boolVal = 0; pVar->vt = VT_BOOL; + } else if (PyLong_Check(ob)) { + pVar->hVal.QuadPart = PyLong_AsLongLong(ob); + if (pVar->hVal.QuadPart == -1 && PyErr_Occurred()){ + // Could still fit in an unsigned long long + PyErr_Clear(); + pVar->uhVal.QuadPart = PyLong_AsUnsignedLongLong(ob); + if (pVar->uhVal.QuadPart == -1 && PyErr_Occurred()) + return FALSE; + pVar->vt = VT_UI8; + } + else{ + pVar->vt=VT_I8; + // Could still fit in a regular long + if (pVar->hVal.QuadPart >= LONG_MIN && pVar->hVal.QuadPart <= LONG_MAX){ + pVar->lVal = (long)pVar->hVal.QuadPart; + pVar->vt = VT_I4; + } + // ... or an unsigned long + else if (pVar->hVal.QuadPart >=0 && pVar->hVal.QuadPart <= ULONG_MAX){ + pVar->ulVal = (unsigned long)pVar->hVal.QuadPart; + pVar->vt = VT_UI4; + } + } +#if (PY_VERSION_HEX < 0x03000000) + // Not needed in Py3k, as PyInt_Check is defined to PyLong_Check } else if (PyInt_Check(ob)) { pVar->lVal = PyInt_AsLong(ob); pVar->vt = VT_I4; +#endif } else if (PyFloat_Check(ob)) { pVar->dblVal = PyFloat_AsDouble(ob); pVar->vt = VT_R8; |