[Python-checkins] CVS: python/dist/src/Objects stringobject.c,2.131,2.132 unicodeobject.c,2.112,2.113
Tim Peters
tim_one@users.sourceforge.net
Tue, 11 Sep 2001 22:19:00 -0700
Update of /cvsroot/python/python/dist/src/Objects
In directory usw-pr-cvs1:/tmp/cvs-serv24899/python/Objects
Modified Files:
stringobject.c unicodeobject.c
Log Message:
str_subtype_new, unicode_subtype_new:
+ These were leaving the hash fields at 0, which all string and unicode
routines believe is a legitimate hash code. As a result, hash() applied
to str and unicode subclass instances always returned 0, which in turn
confused dict operations, etc.
+ Changed local names "new"; no point to antagonizing C++ compilers.
Index: stringobject.c
===================================================================
RCS file: /cvsroot/python/python/dist/src/Objects/stringobject.c,v
retrieving revision 2.131
retrieving revision 2.132
diff -C2 -d -r2.131 -r2.132
*** stringobject.c 2001/09/12 02:18:30 2.131
--- stringobject.c 2001/09/12 05:18:58 2.132
***************
*** 2672,2676 ****
str_subtype_new(PyTypeObject *type, PyObject *args, PyObject *kwds)
{
! PyObject *tmp, *new;
int n;
--- 2672,2676 ----
str_subtype_new(PyTypeObject *type, PyObject *args, PyObject *kwds)
{
! PyObject *tmp, *pnew;
int n;
***************
*** 2680,2688 ****
return NULL;
assert(PyString_CheckExact(tmp));
! new = type->tp_alloc(type, n = PyString_GET_SIZE(tmp));
! if (new != NULL)
! memcpy(PyString_AS_STRING(new), PyString_AS_STRING(tmp), n+1);
Py_DECREF(tmp);
! return new;
}
--- 2680,2698 ----
return NULL;
assert(PyString_CheckExact(tmp));
! n = PyString_GET_SIZE(tmp);
! pnew = type->tp_alloc(type, n);
! if (pnew != NULL) {
! memcpy(PyString_AS_STRING(pnew), PyString_AS_STRING(tmp), n+1);
! #ifdef CACHE_HASH
! ((PyStringObject *)pnew)->ob_shash =
! ((PyStringObject *)tmp)->ob_shash;
! #endif
! #ifdef INTERN_STRINGS
! ((PyStringObject *)pnew)->ob_sinterned =
! ((PyStringObject *)tmp)->ob_sinterned;
! #endif
! }
Py_DECREF(tmp);
! return pnew;
}
Index: unicodeobject.c
===================================================================
RCS file: /cvsroot/python/python/dist/src/Objects/unicodeobject.c,v
retrieving revision 2.112
retrieving revision 2.113
diff -C2 -d -r2.112 -r2.113
*** unicodeobject.c 2001/09/12 03:03:31 2.112
--- unicodeobject.c 2001/09/12 05:18:58 2.113
***************
*** 5332,5336 ****
unicode_subtype_new(PyTypeObject *type, PyObject *args, PyObject *kwds)
{
! PyUnicodeObject *tmp, *new;
int n;
--- 5332,5336 ----
unicode_subtype_new(PyTypeObject *type, PyObject *args, PyObject *kwds)
{
! PyUnicodeObject *tmp, *pnew;
int n;
***************
*** 5340,5356 ****
return NULL;
assert(PyUnicode_Check(tmp));
! new = (PyUnicodeObject *) type->tp_alloc(type, n = tmp->length);
! if (new == NULL)
return NULL;
! new->str = PyMem_NEW(Py_UNICODE, n+1);
! if (new->str == NULL) {
! _Py_ForgetReference((PyObject *)new);
! PyObject_DEL(new);
return NULL;
}
! Py_UNICODE_COPY(new->str, tmp->str, n+1);
! new->length = n;
Py_DECREF(tmp);
! return (PyObject *)new;
}
--- 5340,5357 ----
return NULL;
assert(PyUnicode_Check(tmp));
! pnew = (PyUnicodeObject *) type->tp_alloc(type, n = tmp->length);
! if (pnew == NULL)
return NULL;
! pnew->str = PyMem_NEW(Py_UNICODE, n+1);
! if (pnew->str == NULL) {
! _Py_ForgetReference((PyObject *)pnew);
! PyObject_DEL(pnew);
return NULL;
}
! Py_UNICODE_COPY(pnew->str, tmp->str, n+1);
! pnew->length = n;
! pnew->hash = tmp->hash;
Py_DECREF(tmp);
! return (PyObject *)pnew;
}