diff options
author | Barry Warsaw <barry@python.org> | 2000-07-11 04:58:12 (GMT) |
---|---|---|
committer | Barry Warsaw <barry@python.org> | 2000-07-11 04:58:12 (GMT) |
commit | 771d0675b6fc08f2744c71cc66664d4ea4b22271 (patch) | |
tree | f1c1edcad8a33c8b4b078b35f6b8c6b090e58c01 /Objects | |
parent | 20f41b64563283467529dd1a001afafebf10d939 (diff) | |
download | cpython-771d0675b6fc08f2744c71cc66664d4ea4b22271.zip cpython-771d0675b6fc08f2744c71cc66664d4ea4b22271.tar.gz cpython-771d0675b6fc08f2744c71cc66664d4ea4b22271.tar.bz2 |
string_join(): Some cleaning up of reference counting. In the
seqlen==1 clause, before returning item, we need to DECREF seq. In
the res=PyString... failure clause, we need to goto finally to also
decref seq (and the DECREF of res in finally is changed to a
XDECREF). Also, we need to DECREF seq just before the
PyUnicode_Join() return.
Diffstat (limited to 'Objects')
-rw-r--r-- | Objects/stringobject.c | 17 |
1 files changed, 10 insertions, 7 deletions
diff --git a/Objects/stringobject.c b/Objects/stringobject.c index 2667fa9..dc41122 100644 --- a/Objects/stringobject.c +++ b/Objects/stringobject.c @@ -749,24 +749,27 @@ string_join(PyStringObject *self, PyObject *args) if (!PyArg_ParseTuple(args, "O:join", &orig)) return NULL; - seq = PySequence_Fast(orig, ""); - if (seq == NULL) { + if (!(seq = PySequence_Fast(orig, ""))) { if (PyErr_ExceptionMatches(PyExc_TypeError)) PyErr_Format(PyExc_TypeError, "sequence expected, %.80s found", orig->ob_type->tp_name); return NULL; } - + /* From here on out, errors go through finally: for proper + * reference count manipulations. + */ seqlen = PySequence_Length(seq); if (seqlen == 1) { item = PySequence_Fast_GET_ITEM(seq, 0); Py_INCREF(item); + Py_DECREF(seq); return item; } if (!(res = PyString_FromStringAndSize((char*)NULL, sz))) - return NULL; + goto finally; + p = PyString_AsString(res); for (i = 0; i < seqlen; i++) { @@ -774,8 +777,8 @@ string_join(PyStringObject *self, PyObject *args) if (!PyString_Check(item)){ if (PyUnicode_Check(item)) { Py_DECREF(res); - return PyUnicode_Join((PyObject *)self, - seq); + Py_DECREF(seq); + return PyUnicode_Join((PyObject *)self, seq); } PyErr_Format(PyExc_TypeError, "sequence item %i: expected string, %.80s found", @@ -806,7 +809,7 @@ string_join(PyStringObject *self, PyObject *args) finally: Py_DECREF(seq); - Py_DECREF(res); + Py_XDECREF(res); return NULL; } |