From 2caf8df86802fb24a23ed2cf57674618b5a8f674 Mon Sep 17 00:00:00 2001 From: Tim Peters Date: Sun, 14 Jan 2001 05:05:51 +0000 Subject: [PATCH] SF bug 128713: type(mmap_object) blew up on Linux. --- Lib/tempfile.py | 11 +++++++++-- Lib/test/output/test_mmap | 1 + Lib/test/test_mmap.py | 2 ++ Modules/mmapmodule.c | 7 ++++--- 4 files changed, 16 insertions(+), 5 deletions(-) diff --git a/Lib/tempfile.py b/Lib/tempfile.py index 8ac707d7e09..3ad6d7c0852 100644 --- a/Lib/tempfile.py +++ b/Lib/tempfile.py @@ -89,6 +89,7 @@ elif os.name == 'mac': else: template = 'tmp' # XXX might choose a better one +_pidcache = {} def gettempprefix(): """Function to calculate a prefix of the filename to use. @@ -96,9 +97,15 @@ def gettempprefix(): notion, so that concurrent processes don't generate the same prefix. """ - global template if template is None: - return '@' + `os.getpid()` + '.' + p = os.getpid() + t = _pidcache.get(p, 0) + if t: + return t + if len(_pidcache) > 100: # stop unbounded growth + _pidcache.clear() + t = _pidcache[p] = '@' + `p` + '.' + return t else: return template diff --git a/Lib/test/output/test_mmap b/Lib/test/output/test_mmap index 24e28f835f3..ce2c8234287 100644 --- a/Lib/test/output/test_mmap +++ b/Lib/test/output/test_mmap @@ -1,4 +1,5 @@ test_mmap + Position of foo: 1.0 pages Length of file: 2.0 pages Contents of byte 0: '\000' diff --git a/Lib/test/test_mmap.py b/Lib/test/test_mmap.py index d07e4c6daf8..7c49cf2acb0 100644 --- a/Lib/test/test_mmap.py +++ b/Lib/test/test_mmap.py @@ -18,6 +18,8 @@ def test_both(): f.close() # Simple sanity checks + + print type(m) # SF bug 128713: segfaulted on Linux print ' Position of foo:', string.find(m, 'foo') / float(PAGESIZE), 'pages' assert string.find(m, 'foo') == PAGESIZE diff --git a/Modules/mmapmodule.c b/Modules/mmapmodule.c index c567e7b5830..c1cc013ed29 100644 --- a/Modules/mmapmodule.c +++ b/Modules/mmapmodule.c @@ -841,9 +841,6 @@ new_mmap_object(PyObject *self, PyObject *args) int fileno; HANDLE fh = 0; - /* Patch the object type */ - mmap_object_type.ob_type = &PyType_Type; - if (!PyArg_ParseTuple(args, "iO|z", &fileno, @@ -956,6 +953,10 @@ DL_EXPORT(void) initmmap(void) { PyObject *dict, *module; + + /* Patch the object type */ + mmap_object_type.ob_type = &PyType_Type; + module = Py_InitModule ("mmap", mmap_functions); dict = PyModule_GetDict (module); mmap_module_error = PyExc_EnvironmentError;