diff Objects/object.c @ 50374:43aacbe647cb 3.0

Recorded merge of revisions 68058 via svnmerge from svn+ssh://pythondev@svn.python.org/python/branches/py3k ................ r68058 | nick.coghlan | 2008-12-30 17:29:12 +1000 (Tue, 30 Dec 2008) | 9 lines Recorded merge of revisions 68051 via svnmerge from svn+ssh://pythondev@svn.python.org/python/trunk ........ r68051 | nick.coghlan | 2008-12-30 11:18:48 +1000 (Tue, 30 Dec 2008) | 1 line Issue #4701: implicitly call PyType_Ready from PyObject_Hash ........ ................
author Nick Coghlan <ncoghlan@gmail.com>
date Tue, 30 Dec 2008 07:41:03 +0000
parents 1adfabcbe073
children 0162cd4f55be 27db82a5cda9
line wrap: on
line diff
--- a/Objects/object.c	Mon Dec 29 22:49:14 2008 +0000
+++ b/Objects/object.c	Tue Dec 30 07:41:03 2008 +0000
@@ -846,6 +846,17 @@
 	PyTypeObject *tp = Py_TYPE(v);
 	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);
+	}
 	/* Otherwise, the object can't be hashed */
 	return PyObject_HashNotImplemented(v);
 }