Skip to content

Commit 3be6bec

Browse files
author
christian.heimes
committed
Added _struct._clearcache() for regression tests
git-svn-id: http://svn.python.org/projects/python/trunk@59701 6015fed2-1504-0410-9fe1-9d1591cc4771
1 parent ab045f8 commit 3be6bec

File tree

3 files changed

+15
-1
lines changed

3 files changed

+15
-1
lines changed

Lib/struct.py

+1
Original file line numberDiff line numberDiff line change
@@ -1 +1,2 @@
11
from _struct import *
2+
from _struct import _clearcache

Lib/test/regrtest.py

+1
Original file line numberDiff line numberDiff line change
@@ -729,6 +729,7 @@ def dash_R_cleanup(fs, ps, pic, abcs):
729729
linecache.clearcache()
730730
mimetypes._default_mime_types()
731731
filecmp._cache.clear()
732+
struct._clearcache()
732733
doctest.master = None
733734

734735
# Collect cyclic trash.

Modules/_struct.c

+13-1
Original file line numberDiff line numberDiff line change
@@ -1851,11 +1851,11 @@ PyTypeObject PyStructType = {
18511851
/* ---- Standalone functions ---- */
18521852

18531853
#define MAXCACHE 100
1854+
static PyObject *cache = NULL;
18541855

18551856
static PyObject *
18561857
cache_struct(PyObject *fmt)
18571858
{
1858-
static PyObject *cache = NULL;
18591859
PyObject * s_object;
18601860

18611861
if (cache == NULL) {
@@ -1881,6 +1881,17 @@ cache_struct(PyObject *fmt)
18811881
return s_object;
18821882
}
18831883

1884+
PyDoc_STRVAR(clearcache_doc,
1885+
"Clear the internal cache.");
1886+
1887+
static PyObject *
1888+
clearcache(PyObject *self)
1889+
{
1890+
if (cache != NULL)
1891+
PyDict_Clear(cache);
1892+
Py_RETURN_NONE;
1893+
}
1894+
18841895
PyDoc_STRVAR(calcsize_doc,
18851896
"Return size of C struct described by format string fmt.");
18861897

@@ -2006,6 +2017,7 @@ unpack_from(PyObject *self, PyObject *args, PyObject *kwds)
20062017
}
20072018

20082019
static struct PyMethodDef module_functions[] = {
2020+
{"_clearcache", (PyCFunction)clearcache, METH_NOARGS, clearcache_doc},
20092021
{"calcsize", calcsize, METH_O, calcsize_doc},
20102022
{"pack", pack, METH_VARARGS, pack_doc},
20112023
{"pack_into", pack_into, METH_VARARGS, pack_into_doc},

0 commit comments

Comments
 (0)