Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
C
cpython
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Kirill Smelkov
cpython
Commits
13bc4a45
Commit
13bc4a45
authored
Aug 05, 2013
by
Antoine Pitrou
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Issue #4885: Add weakref support to mmap objects. Patch by Valerie Lambert.
parent
55b2d3f7
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
23 additions
and
3 deletions
+23
-3
Lib/test/test_mmap.py
Lib/test/test_mmap.py
+11
-1
Misc/ACKS
Misc/ACKS
+1
-0
Misc/NEWS
Misc/NEWS
+4
-1
Modules/mmapmodule.c
Modules/mmapmodule.c
+7
-1
No files found.
Lib/test/test_mmap.py
View file @
13bc4a45
from
test.support
import
(
TESTFN
,
run_unittest
,
import_module
,
unlink
,
from
test.support
import
(
TESTFN
,
run_unittest
,
import_module
,
unlink
,
requires
,
_2G
,
_4G
)
requires
,
_2G
,
_4G
,
gc_collect
)
import
unittest
import
unittest
import
os
import
os
import
re
import
re
import
itertools
import
itertools
import
socket
import
socket
import
sys
import
sys
import
weakref
# Skip test if we can't import mmap.
# Skip test if we can't import mmap.
mmap
=
import_module
(
'mmap'
)
mmap
=
import_module
(
'mmap'
)
...
@@ -692,6 +693,15 @@ class MmapTests(unittest.TestCase):
...
@@ -692,6 +693,15 @@ class MmapTests(unittest.TestCase):
"wrong exception raised in context manager"
)
"wrong exception raised in context manager"
)
self
.
assertTrue
(
m
.
closed
,
"context manager failed"
)
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
):
class
LargeMmapTests
(
unittest
.
TestCase
):
def
setUp
(
self
):
def
setUp
(
self
):
...
...
Misc/ACKS
View file @
13bc4a45
...
@@ -701,6 +701,7 @@ Ross Lagerwall
...
@@ -701,6 +701,7 @@ Ross Lagerwall
Cameron Laird
Cameron Laird
David Lam
David Lam
Thomas Lamb
Thomas Lamb
Valerie Lambert
Jean-Baptiste "Jiba" Lamy
Jean-Baptiste "Jiba" Lamy
Ronan Lamy
Ronan Lamy
Torsten Landschoff
Torsten Landschoff
...
...
Misc/NEWS
View file @
13bc4a45
...
@@ -13,7 +13,10 @@ Core and Builtins
...
@@ -13,7 +13,10 @@ Core and Builtins
Library
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
?
What'
s
New
in
Python
3.4.0
Alpha
1
?
===================================
===================================
...
...
Modules/mmapmodule.c
View file @
13bc4a45
...
@@ -20,6 +20,7 @@
...
@@ -20,6 +20,7 @@
#define PY_SSIZE_T_CLEAN
#define PY_SSIZE_T_CLEAN
#include <Python.h>
#include <Python.h>
#include "structmember.h"
#ifndef MS_WINDOWS
#ifndef MS_WINDOWS
#define UNIX
#define UNIX
...
@@ -108,6 +109,7 @@ typedef struct {
...
@@ -108,6 +109,7 @@ typedef struct {
int
fd
;
int
fd
;
#endif
#endif
PyObject
*
weakreflist
;
access_mode
access
;
access_mode
access
;
}
mmap_object
;
}
mmap_object
;
...
@@ -134,6 +136,8 @@ mmap_object_dealloc(mmap_object *m_obj)
...
@@ -134,6 +136,8 @@ mmap_object_dealloc(mmap_object *m_obj)
}
}
#endif
/* UNIX */
#endif
/* UNIX */
if
(
m_obj
->
weakreflist
!=
NULL
)
PyObject_ClearWeakRefs
((
PyObject
*
)
m_obj
);
Py_TYPE
(
m_obj
)
->
tp_free
((
PyObject
*
)
m_obj
);
Py_TYPE
(
m_obj
)
->
tp_free
((
PyObject
*
)
m_obj
);
}
}
...
@@ -1032,7 +1036,7 @@ static PyTypeObject mmap_object_type = {
...
@@ -1032,7 +1036,7 @@ static PyTypeObject mmap_object_type = {
0
,
/* tp_traverse */
0
,
/* tp_traverse */
0
,
/* tp_clear */
0
,
/* tp_clear */
0
,
/* tp_richcompare */
0
,
/* tp_richcompare */
0
,
/* tp_weaklistoffset */
offsetof
(
mmap_object
,
weakreflist
),
/* tp_weaklistoffset */
0
,
/* tp_iter */
0
,
/* tp_iter */
0
,
/* tp_iternext */
0
,
/* tp_iternext */
mmap_object_methods
,
/* tp_methods */
mmap_object_methods
,
/* tp_methods */
...
@@ -1190,6 +1194,7 @@ new_mmap_object(PyTypeObject *type, PyObject *args, PyObject *kwdict)
...
@@ -1190,6 +1194,7 @@ new_mmap_object(PyTypeObject *type, PyObject *args, PyObject *kwdict)
m_obj
->
data
=
NULL
;
m_obj
->
data
=
NULL
;
m_obj
->
size
=
(
size_t
)
map_size
;
m_obj
->
size
=
(
size_t
)
map_size
;
m_obj
->
pos
=
(
size_t
)
0
;
m_obj
->
pos
=
(
size_t
)
0
;
m_obj
->
weakreflist
=
NULL
;
m_obj
->
exports
=
0
;
m_obj
->
exports
=
0
;
m_obj
->
offset
=
offset
;
m_obj
->
offset
=
offset
;
if
(
fd
==
-
1
)
{
if
(
fd
==
-
1
)
{
...
@@ -1394,6 +1399,7 @@ new_mmap_object(PyTypeObject *type, PyObject *args, PyObject *kwdict)
...
@@ -1394,6 +1399,7 @@ new_mmap_object(PyTypeObject *type, PyObject *args, PyObject *kwdict)
/* set the initial position */
/* set the initial position */
m_obj
->
pos
=
(
size_t
)
0
;
m_obj
->
pos
=
(
size_t
)
0
;
m_obj
->
weakreflist
=
NULL
;
m_obj
->
exports
=
0
;
m_obj
->
exports
=
0
;
/* set the tag name */
/* set the tag name */
if
(
tagname
!=
NULL
&&
*
tagname
!=
'\0'
)
{
if
(
tagname
!=
NULL
&&
*
tagname
!=
'\0'
)
{
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment