From 908caac52e8e62baa1ee54e4e650e1cd3ac37907 Mon Sep 17 00:00:00 2001 From: Christian Heimes Date: Sun, 27 Jan 2008 23:34:59 +0000 Subject: Added clear cache methods to clear the internal type lookup cache for ref leak test runs. --- Python/pythonrun.c | 3 +++ Python/sysmodule.c | 13 +++++++++++++ 2 files changed, 16 insertions(+) (limited to 'Python') diff --git a/Python/pythonrun.c b/Python/pythonrun.c index 4939f54890..f5465c5ede 100644 --- a/Python/pythonrun.c +++ b/Python/pythonrun.c @@ -377,6 +377,9 @@ Py_Finalize(void) Py_XDECREF(warnings_module); warnings_module = NULL; + /* Clear type lookup cache */ + PyType_ClearCache(); + /* Collect garbage. This may call finalizers; it's nice to call these * before all modules are destroyed. * XXX If a __del__ or weakref callback is triggered here, and tries to diff --git a/Python/sysmodule.c b/Python/sysmodule.c index 12ad828bbb..f9fb81596e 100644 --- a/Python/sysmodule.c +++ b/Python/sysmodule.c @@ -754,6 +754,17 @@ a 11-tuple where the entries in the tuple are counts of:\n\ 10. Number of stack pops performed by call_function()" ); +static PyObject * +sys_cleartypecache(PyObject* self, PyObject* args) +{ + PyType_ClearCache(); + Py_RETURN_NONE; +} + +PyDoc_STRVAR(cleartypecache_doc, +"_cleartypecache() -> None\n\ +Clear the internal type lookup cache."); + #ifdef __cplusplus extern "C" { #endif @@ -776,6 +787,8 @@ static PyMethodDef sys_methods[] = { /* Might as well keep this in alphabetic order */ {"callstats", (PyCFunction)PyEval_GetCallStats, METH_NOARGS, callstats_doc}, + {"_cleartypecache", sys_cleartypecache, METH_NOARGS, + cleartypecache_doc}, {"_current_frames", sys_current_frames, METH_NOARGS, current_frames_doc}, {"displayhook", sys_displayhook, METH_O, displayhook_doc}, -- cgit v1.2.1