[pywin32-checkins] /hgroot/pywin32/pywin32: Remove 2-int conversion for currency va...
OLD project page for the Python extensions for Windows
Brought to you by:
mhammond
From: <pyw...@li...> - 2012-08-25 04:54:09
|
changeset b152e0e96498 in /hgroot/pywin32/pywin32 details: http://pywin32.hg.sourceforge.net/hgweb/pywin32/pywin32/hgroot/pywin32/pywin32?cmd=changeset;node=b152e0e96498 summary: Remove 2-int conversion for currency variants diffstat: com/win32com/src/PyComHelpers.cpp | 37 +++++++++++++------------------------ 1 files changed, 13 insertions(+), 24 deletions(-) diffs (48 lines): diff -r 196b2bf6a4ce -r b152e0e96498 com/win32com/src/PyComHelpers.cpp --- a/com/win32com/src/PyComHelpers.cpp Fri Aug 24 13:09:08 2012 -0400 +++ b/com/win32com/src/PyComHelpers.cpp Sat Aug 25 00:53:24 2012 -0400 @@ -72,31 +72,20 @@ PYCOM_EXPORT BOOL PyObject_AsCurrency(PyObject *ob, CURRENCY *pcy) { - if (!PyTuple_Check(ob) || PyTuple_Size(ob) != 2 || - !PyLong_Check(PyTuple_GET_ITEM(ob, 0)) || - !PyLong_Check(PyTuple_GET_ITEM(ob, 1))) - { - if (strcmp(ob->ob_type->tp_name, "Decimal")==0) { - PyObject *scaled = PyObject_CallMethod(ob, "__mul__", "l", 10000); - if (!scaled) return FALSE; - PyObject *longval = PyNumber_Long(scaled); - Py_DECREF(scaled); - pcy->int64 = PyLong_AsLongLong(longval); - Py_DECREF(longval); - if (pcy->int64 == -1 && PyErr_Occurred()) - return FALSE; - } else { - PyErr_Format( - PyExc_TypeError, - "Currency object must be either a tuple of 2 longs or a " - "Decimal instance (got %s).", - ob->ob_type->tp_name); - return FALSE; + if (strcmp(ob->ob_type->tp_name, "Decimal")!=0){ + PyErr_Format(PyExc_TypeError, + "Currency object must be a Decimal instance (got %s).",ob->ob_type->tp_name); + return FALSE; } - } else { - pcy->Hi = PyLong_AsLong(PyTuple_GET_ITEM(ob, 0)); - pcy->Lo = PyLong_AsLong(PyTuple_GET_ITEM(ob, 1)); - } + TmpPyObject scaled = PyObject_CallMethod(ob, "__mul__", "l", 10000); + if (scaled == NULL) + return FALSE; + TmpPyObject longval = PyNumber_Long(scaled); + if (longval == NULL) + return FALSE; + pcy->int64 = PyLong_AsLongLong(longval); + if (pcy->int64 == -1 && PyErr_Occurred()) + return FALSE; return TRUE; } |