[Python-checkins] r59701 - in python/trunk: Lib/struct.py Lib/test/regrtest.py Modules/_struct.c

christian.heimes python-checkins at python.org
Fri Jan 4 03:54:43 CET 2008


Author: christian.heimes
Date: Fri Jan  4 03:54:42 2008
New Revision: 59701

Modified:
   python/trunk/Lib/struct.py
   python/trunk/Lib/test/regrtest.py
   python/trunk/Modules/_struct.c
Log:
Added _struct._clearcache() for regression tests

Modified: python/trunk/Lib/struct.py
==============================================================================
--- python/trunk/Lib/struct.py	(original)
+++ python/trunk/Lib/struct.py	Fri Jan  4 03:54:42 2008
@@ -1 +1,2 @@
 from _struct import *
+from _struct import _clearcache

Modified: python/trunk/Lib/test/regrtest.py
==============================================================================
--- python/trunk/Lib/test/regrtest.py	(original)
+++ python/trunk/Lib/test/regrtest.py	Fri Jan  4 03:54:42 2008
@@ -729,6 +729,7 @@
     linecache.clearcache()
     mimetypes._default_mime_types()
     filecmp._cache.clear()
+    struct._clearcache()
     doctest.master = None
 
     # Collect cyclic trash.

Modified: python/trunk/Modules/_struct.c
==============================================================================
--- python/trunk/Modules/_struct.c	(original)
+++ python/trunk/Modules/_struct.c	Fri Jan  4 03:54:42 2008
@@ -1851,11 +1851,11 @@
 /* ---- Standalone functions  ---- */
 
 #define MAXCACHE 100
+static PyObject *cache = NULL;
 
 static PyObject *
 cache_struct(PyObject *fmt)
 {
-	static PyObject *cache = NULL;
 	PyObject * s_object;
 
 	if (cache == NULL) {
@@ -1881,6 +1881,17 @@
 	return s_object;
 }
 
+PyDoc_STRVAR(clearcache_doc,
+"Clear the internal cache.");
+
+static PyObject *
+clearcache(PyObject *self)
+{
+	if (cache != NULL)
+		PyDict_Clear(cache);
+	Py_RETURN_NONE;
+}
+
 PyDoc_STRVAR(calcsize_doc,
 "Return size of C struct described by format string fmt.");
 
@@ -2006,6 +2017,7 @@
 }
 
 static struct PyMethodDef module_functions[] = {
+	{"_clearcache",	(PyCFunction)clearcache,	METH_NOARGS, 	clearcache_doc},
 	{"calcsize",	calcsize,	METH_O, 	calcsize_doc},
 	{"pack",	pack,		METH_VARARGS, 	pack_doc},
 	{"pack_into",	pack_into,	METH_VARARGS, 	pack_into_doc},


More information about the Python-checkins mailing list