]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
SF bug 128713: type(mmap_object) blew up on Linux.
authorTim Peters <tim.peters@gmail.com>
Sun, 14 Jan 2001 05:05:51 +0000 (05:05 +0000)
committerTim Peters <tim.peters@gmail.com>
Sun, 14 Jan 2001 05:05:51 +0000 (05:05 +0000)
Lib/tempfile.py
Lib/test/output/test_mmap
Lib/test/test_mmap.py
Modules/mmapmodule.c

index 8ac707d7e0902eaf1b60ed71d95833c2f813183f..3ad6d7c08524b3c1264c2db9dc3aafa92dcac25e 100644 (file)
@@ -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
 
index 24e28f835f3e7f42331491476af6840ebc3d417f..ce2c823428785e121f9ad4ac78f48a121f9bd7f9 100644 (file)
@@ -1,4 +1,5 @@
 test_mmap
+<type 'mmap'>
   Position of foo: 1.0 pages
   Length of file: 2.0 pages
   Contents of byte 0: '\000'
index d07e4c6daf888ae3afcf14674c53ee1b7f6b1ee2..7c49cf2acb04c024ed048de7725bd4c2be90a053 100644 (file)
@@ -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
 
index c567e7b583008a1db40401e95333e9ab2a295a77..c1cc013ed29f14ff329e2d55d17c8b951b8f49c3 100644 (file)
@@ -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;