summaryrefslogtreecommitdiffstats
path: root/Objects
diff options
context:
space:
mode:
authorTim Peters <tim.peters@gmail.com>2001-09-12 05:18:58 (GMT)
committerTim Peters <tim.peters@gmail.com>2001-09-12 05:18:58 (GMT)
commitaf90b3e610212a4994962246875e5bfc5574dff6 (patch)
tree241056a3295c441dc7ef56d2cd690af5f1287281 /Objects
parent7a29bd58614da9fc478d7167ba918d92c2dcca7e (diff)
downloadcpython-af90b3e610212a4994962246875e5bfc5574dff6.zip
cpython-af90b3e610212a4994962246875e5bfc5574dff6.tar.gz
cpython-af90b3e610212a4994962246875e5bfc5574dff6.tar.bz2
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.
Diffstat (limited to 'Objects')
-rw-r--r--Objects/stringobject.c20
-rw-r--r--Objects/unicodeobject.c21
2 files changed, 26 insertions, 15 deletions
diff --git a/Objects/stringobject.c b/Objects/stringobject.c
index b220859..3c03b9e 100644
--- a/Objects/stringobject.c
+++ b/Objects/stringobject.c
@@ -2671,7 +2671,7 @@ string_new(PyTypeObject *type, PyObject *args, PyObject *kwds)
static PyObject *
str_subtype_new(PyTypeObject *type, PyObject *args, PyObject *kwds)
{
- PyObject *tmp, *new;
+ PyObject *tmp, *pnew;
int n;
assert(PyType_IsSubtype(type, &PyString_Type));
@@ -2679,11 +2679,21 @@ str_subtype_new(PyTypeObject *type, PyObject *args, PyObject *kwds)
if (tmp == NULL)
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);
+ 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 new;
+ return pnew;
}
static char string_doc[] =
diff --git a/Objects/unicodeobject.c b/Objects/unicodeobject.c
index c5912b5..5080eb8 100644
--- a/Objects/unicodeobject.c
+++ b/Objects/unicodeobject.c
@@ -5331,7 +5331,7 @@ unicode_new(PyTypeObject *type, PyObject *args, PyObject *kwds)
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 @@ unicode_subtype_new(PyTypeObject *type, PyObject *args, PyObject *kwds)
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[] =