[Python-checkins] r46119 - sandbox/trunk/decimal-c/_decimal.c
georg.brandl
python-checkins at python.org
Tue May 23 18:22:56 CEST 2006
Author: georg.brandl
Date: Tue May 23 18:22:55 2006
New Revision: 46119
Modified:
sandbox/trunk/decimal-c/_decimal.c
Log:
Fix off-by-one errors.
Modified: sandbox/trunk/decimal-c/_decimal.c
==============================================================================
--- sandbox/trunk/decimal-c/_decimal.c (original)
+++ sandbox/trunk/decimal-c/_decimal.c Tue May 23 18:22:55 2006
@@ -181,6 +181,7 @@
static decimalobject *_decimal_from_pylong(PyTypeObject *, PyObject *, contextobject *);
static PyObject * py_context_shallow_copy(PyObject *, PyObject *, PyObject *);
static contextobject * context_shallow_copy(contextobject *);
+static PyObject *decimal_from_long(PyTypeObject *, long);
/* Decimal methods ***********************************************************/
@@ -1003,13 +1004,13 @@
decimal_copy(decimalobject *self)
{
decimalobject *new;
- long size = self->ob_size;
+ long i;
- new = _NEW_decimalobj(size, self->sign, self->exp);
+ new = _NEW_decimalobj(self->ob_size, self->sign, self->exp);
if (!new)
return NULL;
- while (--size)
- new->digits[size] = self->digits[size];
+ for (i = 0; i < self->ob_size; i++)
+ new->digits[i] = self->digits[i];
return new;
}
@@ -1364,7 +1365,7 @@
/* If it's not a zero, strip leading 0s */
for (p = str+ipos; p-str < dend; ++p) {
- if (*p != '0' && *p != '.') {
+ if (*p != '0') {
/* first nonzero digit */
ipos = (p-str);
goto finish;
@@ -1415,7 +1416,7 @@
}
PyObject *
-_decimal_from_long(PyTypeObject *type, long value)
+decimal_from_long(PyTypeObject *type, long value)
{
decimalobject *new;
long v = value;
@@ -1449,7 +1450,7 @@
PyObject *
PyDecimal_FromLong(long value)
{
- return _decimal_from_long(&PyDecimal_DecimalType, value);
+ return decimal_from_long(&PyDecimal_DecimalType, value);
}
/* convert from a 3-tuple of (sign, digits, exp) */
More information about the Python-checkins
mailing list