[Python-checkins] CVS: python/dist/src/Objects unicodeobject.c,2.115,2.116

M.-A. Lemburg lemburg@users.sourceforge.net
2001年9月20日 10:23:00 -0700


Update of /cvsroot/python/python/dist/src/Objects
In directory usw-pr-cvs1:/tmp/cvs-serv10095/Objects
Modified Files:
	unicodeobject.c 
Log Message:
Fix Unicode .join() method to raise a TypeError for sequence
elements which are not Unicode objects or strings. (This matches
the string.join() behaviour.)
Fix a memory leak in the .join() method which occurs in case
the Unicode resize fails.
Restore the test_unicode output.
Index: unicodeobject.c
===================================================================
RCS file: /cvsroot/python/python/dist/src/Objects/unicodeobject.c,v
retrieving revision 2.115
retrieving revision 2.116
diff -C2 -d -r2.115 -r2.116
*** unicodeobject.c	2001年09月20日 12:53:16	2.115
--- unicodeobject.c	2001年09月20日 17:22:58	2.116
***************
*** 3198,3201 ****
--- 3198,3209 ----
 	if (!PyUnicode_Check(item)) {
 	 PyObject *v;
+ 	 if (!PyString_Check(item)) {
+ 		PyErr_Format(PyExc_TypeError,
+ 			 "sequence item %i: expected string or Unicode,"
+ 			 " %.80s found",
+ 			 i, item->ob_type->tp_name);
+ 		Py_DECREF(item);
+ 		goto onError;
+ 	 }
 	 v = PyUnicode_FromObject(item);
 	 Py_DECREF(item);
***************
*** 3206,3211 ****
 	itemlen = PyUnicode_GET_SIZE(item);
 	while (reslen + itemlen + seplen >= sz) {
! 	 if (_PyUnicode_Resize(&res, sz*2))
 		goto onError;
 	 sz *= 2;
 	 p = PyUnicode_AS_UNICODE(res) + reslen;
--- 3214,3221 ----
 	itemlen = PyUnicode_GET_SIZE(item);
 	while (reslen + itemlen + seplen >= sz) {
! 	 if (_PyUnicode_Resize(&res, sz*2)) {
! 		Py_DECREF(item);
 		goto onError;
+ 	 }
 	 sz *= 2;
 	 p = PyUnicode_AS_UNICODE(res) + reslen;

AltStyle によって変換されたページ (->オリジナル) /