Mercurial > cpython-lru_cache-weakref
diff Objects/unicodeobject.c @ 19886:3b0da13ace48 legacy-trunk
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.
| author | Tim Peters <tim.peters@gmail.com> |
|---|---|
| date | Wed, 12 Sep 2001 05:18:58 +0000 |
| parents | 72e6eb653312 |
| children | 8a0c97453df4 |
line wrap: on
line diff
--- a/Objects/unicodeobject.c Wed Sep 12 03:03:31 2001 +0000 +++ b/Objects/unicodeobject.c Wed Sep 12 05:18:58 2001 +0000 @@ -5331,7 +5331,7 @@ static PyObject * unicode_subtype_new(PyTypeObject *type, PyObject *args, PyObject *kwds) { - PyUnicodeObject *tmp, *new; + PyUnicodeObject *tmp, *pnew; int n; assert(PyType_IsSubtype(type, &PyUnicode_Type)); @@ -5339,19 +5339,20 @@ if (tmp == NULL) return NULL; assert(PyUnicode_Check(tmp)); - new = (PyUnicodeObject *) type->tp_alloc(type, n = tmp->length); - if (new == NULL) + pnew = (PyUnicodeObject *) type->tp_alloc(type, n = tmp->length); + if (pnew == NULL) return NULL; - new->str = PyMem_NEW(Py_UNICODE, n+1); - if (new->str == NULL) { - _Py_ForgetReference((PyObject *)new); - PyObject_DEL(new); + pnew->str = PyMem_NEW(Py_UNICODE, n+1); + if (pnew->str == NULL) { + _Py_ForgetReference((PyObject *)pnew); + PyObject_DEL(pnew); return NULL; } - Py_UNICODE_COPY(new->str, tmp->str, n+1); - new->length = n; + Py_UNICODE_COPY(pnew->str, tmp->str, n+1); + pnew->length = n; + pnew->hash = tmp->hash; Py_DECREF(tmp); - return (PyObject *)new; + return (PyObject *)pnew; } static char unicode_doc[] =
