from test.support import (TESTFN, run_unittest, import_module, unlink,
- requires, _2G, _4G)
+ requires, _2G, _4G, gc_collect)
import unittest
import os
import re
import itertools
import socket
import sys
+import weakref
# Skip test if we can't import mmap.
mmap = import_module('mmap')
"wrong exception raised in context manager")
self.assertTrue(m.closed, "context manager failed")
+ def test_weakref(self):
+ # Check mmap objects are weakrefable
+ mm = mmap.mmap(-1, 16)
+ wr = weakref.ref(mm)
+ self.assertIs(wr(), mm)
+ del mm
+ gc_collect()
+ self.assertIs(wr(), None)
+
class LargeMmapTests(unittest.TestCase):
def setUp(self):
Cameron Laird
David Lam
Thomas Lamb
+Valerie Lambert
Jean-Baptiste "Jiba" Lamy
Ronan Lamy
Torsten Landschoff
Library
-------
-- Issue 8860: Fixed rounding in timedelta constructor.
+- Issue #4885: Add weakref support to mmap objects. Patch by Valerie Lambert.
+
+- Issue #8860: Fixed rounding in timedelta constructor.
+
What's New in Python 3.4.0 Alpha 1?
===================================
#define PY_SSIZE_T_CLEAN
#include <Python.h>
+#include "structmember.h"
#ifndef MS_WINDOWS
#define UNIX
int fd;
#endif
+ PyObject *weakreflist;
access_mode access;
} mmap_object;
}
#endif /* UNIX */
+ if (m_obj->weakreflist != NULL)
+ PyObject_ClearWeakRefs((PyObject *) m_obj);
Py_TYPE(m_obj)->tp_free((PyObject*)m_obj);
}
0, /* tp_traverse */
0, /* tp_clear */
0, /* tp_richcompare */
- 0, /* tp_weaklistoffset */
+ offsetof(mmap_object, weakreflist), /* tp_weaklistoffset */
0, /* tp_iter */
0, /* tp_iternext */
mmap_object_methods, /* tp_methods */
m_obj->data = NULL;
m_obj->size = (size_t) map_size;
m_obj->pos = (size_t) 0;
+ m_obj->weakreflist = NULL;
m_obj->exports = 0;
m_obj->offset = offset;
if (fd == -1) {
/* set the initial position */
m_obj->pos = (size_t) 0;
+ m_obj->weakreflist = NULL;
m_obj->exports = 0;
/* set the tag name */
if (tagname != NULL && *tagname != '\0') {