[Python-checkins] CVS: python/dist/src/Objects stringobject.c,2.132,2.133
Tim Peters
tim_one@users.sourceforge.net
Wed, 12 Sep 2001 00:54:53 -0700
Update of /cvsroot/python/python/dist/src/Objects
In directory usw-pr-cvs1:/tmp/cvs-serv18582/python/dist/src/Objects
Modified Files:
stringobject.c
Log Message:
If interning an instance of a string subclass, intern a real string object
with the same value instead. This ensures that a string (or string
subclass) object's ob_sinterned pointer is always a str (or NULL), and
that the dict of interned strings only has strs as keys.
Index: stringobject.c
===================================================================
RCS file: /cvsroot/python/python/dist/src/Objects/stringobject.c,v
retrieving revision 2.132
retrieving revision 2.133
diff -C2 -d -r2.132 -r2.133
*** stringobject.c 2001/09/12 05:18:58 2.132
--- stringobject.c 2001/09/12 07:54:51 2.133
***************
*** 3554,3561 ****
return;
}
! t = (PyObject *)s;
! if (PyDict_SetItem(interned, t, t) == 0) {
! s->ob_sinterned = t;
! return;
}
PyErr_Clear();
--- 3554,3577 ----
return;
}
! /* Ensure that only true string objects appear in the intern dict,
! and as the value of ob_sinterned. */
! if (PyString_CheckExact(s)) {
! t = (PyObject *)s;
! if (PyDict_SetItem(interned, t, t) == 0) {
! s->ob_sinterned = t;
! return;
! }
! }
! else {
! t = PyString_FromStringAndSize(PyString_AS_STRING(s),
! PyString_GET_SIZE(s));
! if (t != NULL) {
! if (PyDict_SetItem(interned, t, t) == 0) {
! *p = s->ob_sinterned = t;
! Py_DECREF(s);
! return;
! }
! Py_DECREF(t);
! }
}
PyErr_Clear();