summaryrefslogtreecommitdiffstats
path: root/Objects/intobject.c
diff options
context:
space:
mode:
authorNeal Norwitz <nnorwitz@gmail.com>2003-02-10 02:12:43 (GMT)
committerNeal Norwitz <nnorwitz@gmail.com>2003-02-10 02:12:43 (GMT)
commitde8b94c3e1154eb7778a6d5729129b6a57c365fb (patch)
tree2effb80775d5abf238626f99d062acae6ceb5438 /Objects/intobject.c
parent9caf9c040e4cf176eb926a077ae7bcdb6550160b (diff)
downloadcpython-de8b94c3e1154eb7778a6d5729129b6a57c365fb.zip
cpython-de8b94c3e1154eb7778a6d5729129b6a57c365fb.tar.gz
cpython-de8b94c3e1154eb7778a6d5729129b6a57c365fb.tar.bz2
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.
Diffstat (limited to 'Objects/intobject.c')
-rw-r--r--Objects/intobject.c18
1 files changed, 16 insertions, 2 deletions
diff --git a/Objects/intobject.c b/Objects/intobject.c
index 915ef21..544e663 100644
--- a/Objects/intobject.c
+++ b/Objects/intobject.c
@@ -836,16 +836,30 @@ static PyObject *
int_subtype_new(PyTypeObject *type, PyObject *args, PyObject *kwds)
{
PyObject *tmp, *new;
+ long ival;
assert(PyType_IsSubtype(type, &PyInt_Type));
tmp = int_new(&PyInt_Type, args, kwds);
if (tmp == NULL)
return NULL;
- assert(PyInt_Check(tmp));
+ 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 = ((PyIntObject *)tmp)->ob_ival;
+ ((PyIntObject *)new)->ob_ival = ival;
Py_DECREF(tmp);
return new;
}