diff options
author | Nick Coghlan <ncoghlan@gmail.com> | 2008-12-30 01:18:48 (GMT) |
---|---|---|
committer | Nick Coghlan <ncoghlan@gmail.com> | 2008-12-30 01:18:48 (GMT) |
commit | 180e4007661f4480c3be50289748526c2647d28e (patch) | |
tree | 9c1da39d98c91ebb08054ddb19d608596b19b498 /Objects/object.c | |
parent | c13acb18bc2db9d8824ba94b86d8e4c8909d6b6c (diff) | |
download | cpython-180e4007661f4480c3be50289748526c2647d28e.zip cpython-180e4007661f4480c3be50289748526c2647d28e.tar.gz cpython-180e4007661f4480c3be50289748526c2647d28e.tar.bz2 |
Issue #4701: implicitly call PyType_Ready from PyObject_Hash
Diffstat (limited to 'Objects/object.c')
-rw-r--r-- | Objects/object.c | 11 |
1 files changed, 11 insertions, 0 deletions
diff --git a/Objects/object.c b/Objects/object.c index c882cf2..7b82db9 100644 --- a/Objects/object.c +++ b/Objects/object.c @@ -1100,6 +1100,17 @@ PyObject_Hash(PyObject *v) PyTypeObject *tp = v->ob_type; if (tp->tp_hash != NULL) return (*tp->tp_hash)(v); + /* To keep to the general practice that inheriting + * solely from object in C code should work without + * an explicit call to PyType_Ready, we implicitly call + * PyType_Ready here and then check the tp_hash slot again + */ + if (tp->tp_dict == NULL) { + if (PyType_Ready(tp) < 0) + return -1; + if (tp->tp_hash != NULL) + return (*tp->tp_hash)(v); + } if (tp->tp_compare == NULL && RICHCOMPARE(tp) == NULL) { return _Py_HashPointer(v); /* Use address as hash value */ } |