[Python-checkins] CVS: python/dist/src/Objects stringobject.c,2.106,2.107 unicodeobject.c,2.88,2.89

Tim Peters tim_one@users.sourceforge.net
Fri, 04 May 2001 22:36:50 -0700


Update of /cvsroot/python/python/dist/src/Objects
In directory usw-pr-cvs1:/tmp/cvs-serv31444/python/dist/src/Objects

Modified Files:
	stringobject.c unicodeobject.c 
Log Message:
Make unicode.join() work nice with iterators.  This also required a change
to string.join(), so that when the latter figures out in midstream that
it really needs unicode.join() instead, unicode.join() can actually get
all the sequence elements (i.e., there's no guarantee that the sequence
passed to string.join() can be iterated over *again* by unicode.join(),
so string.join() must not pass on the original sequence object anymore).


Index: stringobject.c
===================================================================
RCS file: /cvsroot/python/python/dist/src/Objects/stringobject.c,v
retrieving revision 2.106
retrieving revision 2.107
diff -C2 -r2.106 -r2.107
*** stringobject.c	2001/05/02 14:21:53	2.106
--- stringobject.c	2001/05/05 05:36:48	2.107
***************
*** 862,867 ****
  		if (!PyString_Check(item)){
  			if (PyUnicode_Check(item)) {
  				Py_DECREF(seq);
! 				return PyUnicode_Join((PyObject *)self, orig);
  			}
  			PyErr_Format(PyExc_TypeError,
--- 862,874 ----
  		if (!PyString_Check(item)){
  			if (PyUnicode_Check(item)) {
+ 				/* Defer to Unicode join.
+ 				 * CAUTION:  There's no gurantee that the
+ 				 * original sequence can be iterated over
+ 				 * again, so we must pass seq here.
+ 				 */
+ 				PyObject *result;
+ 				result = PyUnicode_Join((PyObject *)self, seq);
  				Py_DECREF(seq);
! 				return result;
  			}
  			PyErr_Format(PyExc_TypeError,

Index: unicodeobject.c
===================================================================
RCS file: /cvsroot/python/python/dist/src/Objects/unicodeobject.c,v
retrieving revision 2.88
retrieving revision 2.89
diff -C2 -r2.88 -r2.89
*** unicodeobject.c	2001/04/28 05:38:26	2.88
--- unicodeobject.c	2001/05/05 05:36:48	2.89
***************
*** 2725,2732 ****
      int sz = 100;
      int i;
  
!     seqlen = PySequence_Size(seq);
!     if (seqlen < 0 && PyErr_Occurred())
! 	return NULL;
  
      if (separator == NULL) {
--- 2725,2733 ----
      int sz = 100;
      int i;
+     PyObject *it;
  
!     it = PyObject_GetIter(seq);
!     if (it == NULL)
!         return NULL;
  
      if (separator == NULL) {
***************
*** 2738,2742 ****
  	separator = PyUnicode_FromObject(separator);
  	if (separator == NULL)
! 	    return NULL;
  	sep = PyUnicode_AS_UNICODE(separator);
  	seplen = PyUnicode_GET_SIZE(separator);
--- 2739,2743 ----
  	separator = PyUnicode_FromObject(separator);
  	if (separator == NULL)
! 	    goto onError;
  	sep = PyUnicode_AS_UNICODE(separator);
  	seplen = PyUnicode_GET_SIZE(separator);
***************
*** 2749,2759 ****
      reslen = 0;
  
!     for (i = 0; i < seqlen; i++) {
  	int itemlen;
! 	PyObject *item;
! 
! 	item = PySequence_GetItem(seq, i);
! 	if (item == NULL)
! 	    goto onError;
  	if (!PyUnicode_Check(item)) {
  	    PyObject *v;
--- 2750,2761 ----
      reslen = 0;
  
!     for (i = 0; ; ++i) {
  	int itemlen;
! 	PyObject *item = PyIter_Next(it);
! 	if (item == NULL) {
! 	    if (PyErr_Occurred())
! 		goto onError;
! 	    break;
! 	}
  	if (!PyUnicode_Check(item)) {
  	    PyObject *v;
***************
*** 2785,2793 ****
  
      Py_XDECREF(separator);
      return (PyObject *)res;
  
   onError:
      Py_XDECREF(separator);
!     Py_DECREF(res);
      return NULL;
  }
--- 2787,2797 ----
  
      Py_XDECREF(separator);
+     Py_DECREF(it);
      return (PyObject *)res;
  
   onError:
      Py_XDECREF(separator);
!     Py_XDECREF(res);
!     Py_DECREF(it);
      return NULL;
  }