[Python-checkins] CVS: python/dist/src/Objects stringobject.c,2.78,2.79

Barry Warsaw python-dev@python.org
Mon, 10 Jul 2000 21:58:15 -0700


Update of /cvsroot/python/python/dist/src/Objects
In directory slayer.i.sourceforge.net:/tmp/cvs-serv31629

Modified Files:
	stringobject.c 
Log Message:
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.


Index: stringobject.c
===================================================================
RCS file: /cvsroot/python/python/dist/src/Objects/stringobject.c,v
retrieving revision 2.78
retrieving revision 2.79
diff -C2 -r2.78 -r2.79
*** stringobject.c	2000/07/11 03:28:17	2.78
--- stringobject.c	2000/07/11 04:58:12	2.79
***************
*** 750,755 ****
  		return NULL;
  
! 	seq = PySequence_Fast(orig, "");
! 	if (seq == NULL) {
  		if (PyErr_ExceptionMatches(PyExc_TypeError))
  			PyErr_Format(PyExc_TypeError,
--- 750,754 ----
  		return NULL;
  
! 	if (!(seq = PySequence_Fast(orig, ""))) {
  		if (PyErr_ExceptionMatches(PyExc_TypeError))
  			PyErr_Format(PyExc_TypeError,
***************
*** 758,771 ****
  		return NULL;
  	}
! 
  	seqlen = PySequence_Length(seq);
  	if (seqlen == 1) {
  		item = PySequence_Fast_GET_ITEM(seq, 0);
  		Py_INCREF(item);
  		return item;
  	}
  
  	if (!(res = PyString_FromStringAndSize((char*)NULL, sz)))
! 		return NULL;
  	p = PyString_AsString(res);
  
--- 757,774 ----
  		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)))
! 		goto finally;
! 
  	p = PyString_AsString(res);
  
***************
*** 775,780 ****
  			if (PyUnicode_Check(item)) {
  				Py_DECREF(res);
! 				return PyUnicode_Join((PyObject *)self, 
! 						      seq);
  			}
  			PyErr_Format(PyExc_TypeError,
--- 778,783 ----
  			if (PyUnicode_Check(item)) {
  				Py_DECREF(res);
! 				Py_DECREF(seq);
! 				return PyUnicode_Join((PyObject *)self, seq);
  			}
  			PyErr_Format(PyExc_TypeError,
***************
*** 807,811 ****
    finally:
  	Py_DECREF(seq);
! 	Py_DECREF(res);
  	return NULL;
  }
--- 810,814 ----
    finally:
  	Py_DECREF(seq);
! 	Py_XDECREF(res);
  	return NULL;
  }