]> granicus.if.org Git - python/commitdiff
Added _struct._clearcache() for regression tests
authorChristian Heimes <christian@cheimes.de>
Fri, 4 Jan 2008 02:54:42 +0000 (02:54 +0000)
committerChristian Heimes <christian@cheimes.de>
Fri, 4 Jan 2008 02:54:42 +0000 (02:54 +0000)
Lib/struct.py
Lib/test/regrtest.py
Modules/_struct.c

index 297e7d0d90d967cbdba4c8a96a8b9bd6c4668d1e..3784c055be96b940871cf79fd94886753a0d7a20 100644 (file)
@@ -1 +1,2 @@
 from _struct import *
+from _struct import _clearcache
index 0cc0c5783aa24ed2128235062643147048a55556..1da6967ae57574d6b1dacdb985c7cfb922740814 100755 (executable)
@@ -729,6 +729,7 @@ def dash_R_cleanup(fs, ps, pic, abcs):
     linecache.clearcache()
     mimetypes._default_mime_types()
     filecmp._cache.clear()
+    struct._clearcache()
     doctest.master = None
 
     # Collect cyclic trash.
index e3a873187ee506b9260774ddb4a29d124fba171b..41cdca706241e519f17c87dd610a45bac0dcafd3 100644 (file)
@@ -1851,11 +1851,11 @@ PyTypeObject PyStructType = {
 /* ---- 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 @@ cache_struct(PyObject *fmt)
        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 @@ unpack_from(PyObject *self, PyObject *args, PyObject *kwds)
 }
 
 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},