[Python-checkins] r46106 - sandbox/trunk/decimal-c/_decimal.c
georg.brandl
python-checkins at python.org
Tue May 23 14:15:15 CEST 2006
Author: georg.brandl
Date: Tue May 23 14:15:14 2006
New Revision: 46106
Modified:
sandbox/trunk/decimal-c/_decimal.c
Log:
Add accessor for self._int.
Modified: sandbox/trunk/decimal-c/_decimal.c
==============================================================================
--- sandbox/trunk/decimal-c/_decimal.c (original)
+++ sandbox/trunk/decimal-c/_decimal.c Tue May 23 14:15:14 2006
@@ -1547,6 +1547,44 @@
return tup;
}
+static int
+_decimal_set_int(decimalobject *self, PyObject *value)
+{
+ long i, size, val;
+ char *arr;
+ PyObject *item;
+ if (!PyTuple_Check(value)) {
+ PyErr_SetString(PyExc_TypeError, "_int must be a tuple");
+ return -1;
+ }
+ size = PyTuple_GET_SIZE(value);
+ arr = PyObject_MALLOC(size);
+ if (!arr) {
+ PyErr_NoMemory();
+ return -1;
+ }
+ for (i = 0; i < PyTuple_GET_SIZE(value); i++) {
+ item = PyTuple_GET_ITEM(value, i);
+ if (!PyInt_Check(item)) {
+ PyObject_FREE(arr);
+ PyErr_SetString(PyExc_TypeError, "_int must consist of ints");
+ return -1;
+ }
+ val = PyInt_AsLong(item);
+ if (val < 0 || val > 9) {
+ PyObject_FREE(arr);
+ PyErr_SetString(PyExc_TypeError, "_int digits must be 0-9");
+ return NULL;
+ }
+ arr[i] = val;
+ }
+
+ PyObject_FREE(self->digits);
+ self->ob_size = size;
+ self->digits = arr;
+ return 0;
+}
+
static PyObject *
_decimal_is_special(decimalobject *self)
{
@@ -1557,7 +1595,7 @@
}
static PyGetSetDef _decimal_getset[] = {
- {"_int", (getter)_decimal_get_int, 0},
+ {"_int", (getter)_decimal_get_int, (setter)_decimal_set_int},
{"_is_special", (getter)_decimal_is_special, 0},
{NULL}
};
More information about the Python-checkins
mailing list