[Python-checkins] r86495 - python/branches/py3k-cdecimal/Modules/cdecimal/cdecimal.c
stefan.krah
python-checkins at python.org
Wed Nov 17 20:10:35 CET 2010
Author: stefan.krah
Date: Wed Nov 17 20:10:29 2010
New Revision: 86495
Log:
#Issue7811: use ValueError for decimal.py compatibility.
Modified:
python/branches/py3k-cdecimal/Modules/cdecimal/cdecimal.c
Modified: python/branches/py3k-cdecimal/Modules/cdecimal/cdecimal.c
==============================================================================
--- python/branches/py3k-cdecimal/Modules/cdecimal/cdecimal.c (original)
+++ python/branches/py3k-cdecimal/Modules/cdecimal/cdecimal.c Wed Nov 17 20:10:29 2010
@@ -2020,12 +2020,13 @@
tmp = PyTuple_GET_ITEM(v, 0);
if (!PyLong_Check(tmp)) {
- PyErr_SetString(PyExc_TypeError, "sign must be 0 or 1.");
- return NULL;
+ return value_error_ptr(
+ "sign must be an integer with the value 0 or 1.");
}
sign = PyLong_AsLong(tmp);
if (sign != 0 && sign != 1) {
- return value_error_ptr("sign must be 0 or 1.");
+ return value_error_ptr(
+ "sign must be an integer with the value 0 or 1.");
}
sign_special[0] = sign ? '-' : '+';
sign_special[1] = '\0';
@@ -2048,17 +2049,20 @@
}
}
else {
+ if (!PyLong_Check(tmp)) {
+ return value_error_ptr(
+ "exponent must be an integer.");
+ }
exp = PyLong_AsMpdSsize(tmp);
if (PyErr_Occurred()) {
- return NULL;
+ return NULL; /* GCOV_UNLIKELY */
}
}
dtuple = PyTuple_GET_ITEM(v, 1);
if (!PyTuple_Check(dtuple)) {
- PyErr_SetString(PyExc_TypeError,
+ return value_error_ptr(
"coefficient must be a tuple of digits.");
- return NULL;
}
tsize = PyTuple_Size(dtuple);
@@ -2082,9 +2086,8 @@
tmp = PyTuple_GET_ITEM(dtuple, i);
if (!PyLong_Check(tmp)) {
PyMem_Free(decstring);
- PyErr_SetString(PyExc_TypeError,
+ return value_error_ptr(
"coefficient must be a tuple of digits.");
- return NULL;
}
l = PyLong_AsLong(tmp);
if (l < 0 || l > 9) {
More information about the Python-checkins
mailing list