summaryrefslogtreecommitdiffstats
path: root/Objects
diff options
context:
space:
mode:
authorRaymond Hettinger <python@rcn.com>2009-06-12 18:40:16 (GMT)
committerRaymond Hettinger <python@rcn.com>2009-06-12 18:40:16 (GMT)
commit94f55837775f00eade742fa015d818633ab68318 (patch)
treef61f92b50485609d21e7c9c7912cccf065873387 /Objects
parent83eacca7a601df925a36455119633167a9093cdb (diff)
downloadcpython-94f55837775f00eade742fa015d818633ab68318.zip
cpython-94f55837775f00eade742fa015d818633ab68318.tar.gz
cpython-94f55837775f00eade742fa015d818633ab68318.tar.bz2
Fix SystemError and a wasps nest of ref counting issues.
Diffstat (limited to 'Objects')
-rw-r--r--Objects/rangeobject.c32
1 files changed, 24 insertions, 8 deletions
diff --git a/Objects/rangeobject.c b/Objects/rangeobject.c
index 01114bb..f8174ca 100644
--- a/Objects/rangeobject.c
+++ b/Objects/rangeobject.c
@@ -59,26 +59,42 @@ range_new(PyTypeObject *type, PyObject *args, PyObject *kw)
if (PyTuple_Size(args) <= 1) {
if (!PyArg_UnpackTuple(args, "range", 1, 1, &stop))
- goto Fail;
+ return NULL;
stop = PyNumber_Index(stop);
if (!stop)
- goto Fail;
+ return NULL;
start = PyLong_FromLong(0);
+ if (!start) {
+ Py_DECREF(stop);
+ return NULL;
+ }
step = PyLong_FromLong(1);
- if (!start || !step)
- goto Fail;
+ if (!step) {
+ Py_DECREF(stop);
+ Py_DECREF(start);
+ return NULL;
+ }
}
else {
if (!PyArg_UnpackTuple(args, "range", 2, 3,
&start, &stop, &step))
- goto Fail;
+ return NULL;
/* Convert borrowed refs to owned refs */
start = PyNumber_Index(start);
+ if (!start)
+ return NULL;
stop = PyNumber_Index(stop);
- step = validate_step(step);
- if (!start || !stop || !step)
- goto Fail;
+ if (!stop) {
+ Py_DECREF(start);
+ return NULL;
+ }
+ step = validate_step(step); /* Caution, this can clear exceptions */
+ if (!step) {
+ Py_DECREF(start);
+ Py_DECREF(stop);
+ return NULL;
+ }
}
obj = PyObject_New(rangeobject, &PyRange_Type);