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

M.-A. Lemburg python-dev@python.org
Sat, 7 Oct 2000 01:54:12 -0700


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

Modified Files:
	stringobject.c 
Log Message:
[ Bug #116174 ] using %% in cstrings sometimes fails with unicode paramsFix for the bug reported in Bug #116174: "%% %s" % u"abc" failed due
to the way string formatting delegated work to the Unicode formatting
function.

Index: stringobject.c
===================================================================
RCS file: /cvsroot/python/python/dist/src/Objects/stringobject.c,v
retrieving revision 2.90
retrieving revision 2.91
diff -C2 -r2.90 -r2.91
*** stringobject.c	2000/09/26 05:46:01	2.90
--- stringobject.c	2000/10/07 08:54:09	2.91
***************
*** 2667,2671 ****
  	int fmtcnt, rescnt, reslen, arglen, argidx;
  	int args_owned = 0;
! 	PyObject *result, *orig_args;
  	PyObject *dict = NULL;
  	if (format == NULL || !PyString_Check(format) || args == NULL) {
--- 2667,2671 ----
  	int fmtcnt, rescnt, reslen, arglen, argidx;
  	int args_owned = 0;
! 	PyObject *result, *orig_args, *v, *w;
  	PyObject *dict = NULL;
  	if (format == NULL || !PyString_Check(format) || args == NULL) {
***************
*** 3056,3075 ****
  		args = orig_args;
  	}
! 	/* Paste rest of format string to what we have of the result
! 	   string; we reuse result for this */
  	rescnt = res - PyString_AS_STRING(result);
  	fmtcnt = PyString_GET_SIZE(format) - \
  		 (fmt - PyString_AS_STRING(format));
! 	if (_PyString_Resize(&result, rescnt + fmtcnt)) {
! 		Py_DECREF(args);
  		goto error;
! 	}
! 	memcpy(PyString_AS_STRING(result) + rescnt, fmt, fmtcnt);
! 	format = result;
! 	/* Let Unicode do its magic */
! 	result = PyUnicode_Format(format, args);
  	Py_DECREF(format);
  	Py_DECREF(args);
! 	return result;
  	
   error:
--- 3056,3081 ----
  		args = orig_args;
  	}
! 	args_owned = 1;
! 	/* Take what we have of the result and let the Unicode formatting
! 	   function format the rest of the input. */
  	rescnt = res - PyString_AS_STRING(result);
+ 	if (_PyString_Resize(&result, rescnt))
+ 		goto error;
  	fmtcnt = PyString_GET_SIZE(format) - \
  		 (fmt - PyString_AS_STRING(format));
! 	format = PyUnicode_Decode(fmt, fmtcnt, NULL, NULL);
! 	if (format == NULL)
  		goto error;
! 	v = PyUnicode_Format(format, args);
  	Py_DECREF(format);
+ 	if (v == NULL)
+ 		goto error;
+ 	/* Paste what we have (result) to what the Unicode formatting
+ 	   function returned (v) and return the result (or error) */
+ 	w = PyUnicode_Concat(result, v);
+ 	Py_DECREF(result);
+ 	Py_DECREF(v);
  	Py_DECREF(args);
! 	return w;
  	
   error: