[pywin32-checkins] pywin32/com/win32com/src oleargs.cpp,1.35,1.36
OLD project page for the Python extensions for Windows
Brought to you by:
mhammond
From: Mark H. <mha...@us...> - 2006-06-21 12:19:00
|
Update of /cvsroot/pywin32/pywin32/com/win32com/src In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv11442/win32com/src Modified Files: oleargs.cpp Log Message: Transfer Python longs as 64 bit integers if possible, other wish fall back to a double (which we previously did if we didn't fit into 32 bits) Index: oleargs.cpp =================================================================== RCS file: /cvsroot/pywin32/pywin32/com/win32com/src/oleargs.cpp,v retrieving revision 1.35 retrieving revision 1.36 diff -C2 -d -r1.35 -r1.36 *** oleargs.cpp 14 Mar 2006 12:12:44 -0000 1.35 --- oleargs.cpp 21 Jun 2006 12:18:51 -0000 1.36 *************** *** 66,85 **** else if (PyLong_Check(obj)) { ! double dval = PyLong_AsDouble(obj); ! BOOL isDword = FALSE; ! if (dval >= 0 && dval < (double)ULONG_MAX) ! { ! DWORD dwval = (DWORD)dval; ! if ((double)dwval == dval) ! { ! V_VT(var) = VT_UI4; ! V_UI4(var) = dwval; ! isDword = TRUE; ! } ! } ! if (!isDword) ! { V_VT(var) = VT_R8; V_R8(var) = dval; } } --- 66,91 ---- else if (PyLong_Check(obj)) { ! __int64 lval = PyLong_AsLongLong(obj); ! if (PyErr_Occurred() && !PyErr_ExceptionMatches(PyExc_OverflowError)) ! return FALSE; ! if (PyErr_Occurred()) { ! PyErr_Clear(); ! // too big for 64 bits! Use a double. ! double dval = PyLong_AsDouble(obj); V_VT(var) = VT_R8; V_R8(var) = dval; + } else { + // 64 bits is OK - but if it fits in 32 we will + // use that. + if (lval >= 0 && lval <= ULONG_MAX) { + V_VT(var) = VT_UI4; + V_UI4(var) = (unsigned long)lval; + } else if (lval >= LONG_MIN && lval <= LONG_MAX) { + V_VT(var) = VT_I4; + V_I4(var) = (long)lval; + } else { + V_VT(var) = VT_I8; + V_I8(var) = lval; + } } } |