[Python-Dev] Bug in stringobject?

M.-A. Lemburg mal at egenix.com
Fri Jun 16 15:07:07 CEST 2006

Georg Brandl wrote:
> In string_replace, there is
> 	if (PyString_Check(from)) {
> 	  /* Can this be made a '!check' after the Unicode check? */
> 	}
> 	if (PyUnicode_Check(from))
> 		return PyUnicode_Replace((PyObject *)self,
> 					 from, to, count);
> #endif
> 	else if (PyObject_AsCharBuffer(from, &tmp_s, &tmp_len))
> 		return NULL;
> [the same check with "to"]
> 	return (PyObject *)replace((PyStringObject *) self,
> 				   (PyStringObject *) from,
> 				   (PyStringObject *) to, count);
> Can this be correct if from or to isn't a string object, but a
> char buffer compatible object?

Certainly not :-)

Also note that tmp_s and tmp_len are no longer used in the

It appears as if there's some code missing from the function
(and that there's no unit which actually does a string
replace with non-string objects).

Since replace() only works on string objects, it appears
as if a temporary string object would have to be created.
However, this would involve an unnecessary allocation
and copy process... it appears as if the refactoring
during the NFS sprint left out that case.

Marc-Andre Lemburg

Professional Python Services directly from the Source  (#1, Jun 16 2006)
>>> Python/Zope Consulting and Support ...        http://www.egenix.com/
>>> mxODBC.Zope.Database.Adapter ...             http://zope.egenix.com/
>>> mxODBC, mxDateTime, mxTextTools ...        http://python.egenix.com/

::: Try mxODBC.Zope.DA for Windows,Linux,Solaris,FreeBSD for free ! ::::

More information about the Python-Dev mailing list