[Python-checkins] CVS: python/dist/src/Objects object.c,2.145,2.146 stringobject.c,2.129,2.130

Tim Peters tim_one@users.sourceforge.net
Mon, 10 Sep 2001 18:42:01 -0700


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

Modified Files:
	object.c stringobject.c 
Log Message:
More on SF bug [#460020] bug or feature: unicode() and subclasses.
Repaired str(i) to return a genuine string when i is an instance of a str
subclass.  New PyString_CheckExact() macro.


Index: object.c
===================================================================
RCS file: /cvsroot/python/python/dist/src/Objects/object.c,v
retrieving revision 2.145
retrieving revision 2.146
diff -C2 -d -r2.145 -r2.146
*** object.c	2001/09/10 18:27:43	2.145
--- object.c	2001/09/11 01:41:59	2.146
***************
*** 251,257 ****
  	if (v == NULL)
  		return PyString_FromString("<NULL>");
! 	if (PyString_Check(v)) {
  		Py_INCREF(v);
  		return v;
  	}
  	if (v->ob_type->tp_str == NULL)
--- 251,263 ----
  	if (v == NULL)
  		return PyString_FromString("<NULL>");
! 	if (PyString_CheckExact(v)) {
  		Py_INCREF(v);
  		return v;
+ 	}
+ 	if (PyString_Check(v)) {
+ 		/* For a string subtype that's not a string, return a true
+ 		   string with the same string data. */
+ 		PyStringObject *s = (PyStringObject *)v;
+ 		return PyString_FromStringAndSize(s->ob_sval, s->ob_size);
  	}
  	if (v->ob_type->tp_str == NULL)

Index: stringobject.c
===================================================================
RCS file: /cvsroot/python/python/dist/src/Objects/stringobject.c,v
retrieving revision 2.129
retrieving revision 2.130
diff -C2 -d -r2.129 -r2.130
*** stringobject.c	2001/08/31 16:11:15	2.129
--- stringobject.c	2001/09/11 01:41:59	2.130
***************
*** 2712,2716 ****
  	if (tmp == NULL)
  		return NULL;
! 	assert(PyString_Check(tmp));
  	new = type->tp_alloc(type, n = PyString_GET_SIZE(tmp));
  	if (new != NULL)
--- 2712,2716 ----
  	if (tmp == NULL)
  		return NULL;
! 	assert(PyString_CheckExact(tmp));
  	new = type->tp_alloc(type, n = PyString_GET_SIZE(tmp));
  	if (new != NULL)