[Python-checkins] python/dist/src/Objects intobject.c,2.100,2.101
nnorwitz@users.sourceforge.net
nnorwitz@users.sourceforge.net
Sun, 09 Feb 2003 18:12:45 -0800
Update of /cvsroot/python/python/dist/src/Objects
In directory sc8-pr-cvs1:/tmp/cvs-serv13524/Objects
Modified Files:
intobject.c
Log Message:
Fix SF bug #683467, 'int' ability to generate longs not inherited
When subclassing from an int but not overriding __new__,
long values were not converted properly. Try to convert
longs into an int.
Index: intobject.c
===================================================================
RCS file: /cvsroot/python/python/dist/src/Objects/intobject.c,v
retrieving revision 2.100
retrieving revision 2.101
diff -C2 -d -r2.100 -r2.101
*** intobject.c 29 Jan 2003 17:58:45 -0000 2.100
--- intobject.c 10 Feb 2003 02:12:42 -0000 2.101
***************
*** 837,840 ****
--- 837,841 ----
{
PyObject *tmp, *new;
+ long ival;
assert(PyType_IsSubtype(type, &PyInt_Type));
***************
*** 842,850 ****
if (tmp == NULL)
return NULL;
! assert(PyInt_Check(tmp));
new = type->tp_alloc(type, 0);
if (new == NULL)
return NULL;
! ((PyIntObject *)new)->ob_ival = ((PyIntObject *)tmp)->ob_ival;
Py_DECREF(tmp);
return new;
--- 843,864 ----
if (tmp == NULL)
return NULL;
! if (!PyInt_Check(tmp)) {
! if (!PyLong_Check(tmp)) {
! PyErr_SetString(PyExc_ValueError,
! "value must convertable to an int");
! return NULL;
! }
! ival = PyLong_AsLong(tmp);
! if (ival == -1 && PyErr_Occurred())
! return NULL;
!
! } else {
! ival = ((PyIntObject *)tmp)->ob_ival;
! }
!
new = type->tp_alloc(type, 0);
if (new == NULL)
return NULL;
! ((PyIntObject *)new)->ob_ival = ival;
Py_DECREF(tmp);
return new;