diff Objects/typeobject.c @ 45025:ea3fe302d392 legacy-trunk

Added clear cache methods to clear the internal type lookup cache for ref leak test runs.
author Christian Heimes <christian@cheimes.de>
date Sun, 27 Jan 2008 23:34:59 +0000
parents e224ad4b8b8c
children b7231bf6bfb7
line wrap: on
line diff
--- a/Objects/typeobject.c	Sun Jan 27 23:08:46 2008 +0000
+++ b/Objects/typeobject.c	Sun Jan 27 23:34:59 2008 +0000
@@ -32,6 +32,24 @@
 
 static struct method_cache_entry method_cache[1 << MCACHE_SIZE_EXP];
 static unsigned int next_version_tag = 0;
+static void type_modified(PyTypeObject *);
+
+unsigned int
+PyType_ClearCache(void)
+{
+	Py_ssize_t i;
+	unsigned int cur_version_tag = next_version_tag - 1;
+	
+	for (i = 0; i < (1 << MCACHE_SIZE_EXP); i++) {
+		method_cache[i].version = 0;
+		Py_CLEAR(method_cache[i].name);
+		method_cache[i].value = NULL;
+	}
+	next_version_tag = 0;
+	/* mark all version tags as invalid */
+	type_modified(&PyBaseObject_Type);
+	return cur_version_tag;
+}
 
 static void
 type_modified(PyTypeObject *type)