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
4925cde1
Commit
4925cde1
authored
May 20, 2011
by
Victor Stinner
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Issue #12124: zipimport doesn't keep a reference to zlib.decompress() anymore
to be able to unload the module.
parent
ae8856fe
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
26 additions
and
41 deletions
+26
-41
Lib/test/test_zipimport.py
Lib/test/test_zipimport.py
+0
-17
Misc/NEWS
Misc/NEWS
+3
-0
Modules/zipimport.c
Modules/zipimport.c
+23
-24
No files found.
Lib/test/test_zipimport.py
View file @
4925cde1
...
...
@@ -19,11 +19,6 @@ import io
from
traceback
import
extract_tb
,
extract_stack
,
print_tb
raise_src
=
'def do_raise(): raise TypeError
\
n
'
# so we only run testAFakeZlib once if this test is run repeatedly
# which happens when we look for ref leaks
test_imported
=
False
def
make_pyc
(
co
,
mtime
):
data
=
marshal
.
dumps
(
co
)
if
type
(
mtime
)
is
type
(
0.0
):
...
...
@@ -453,19 +448,7 @@ class BadFileZipImportTestCase(unittest.TestCase):
zipimport
.
_zip_directory_cache
.
clear
()
def
cleanup
():
# this is necessary if test is run repeated (like when finding leaks)
global
test_imported
if
test_imported
:
zipimport
.
_zip_directory_cache
.
clear
()
if
hasattr
(
UncompressedZipImportTestCase
,
'testAFakeZlib'
):
delattr
(
UncompressedZipImportTestCase
,
'testAFakeZlib'
)
if
hasattr
(
CompressedZipImportTestCase
,
'testAFakeZlib'
):
delattr
(
CompressedZipImportTestCase
,
'testAFakeZlib'
)
test_imported
=
True
def
test_main
():
cleanup
()
try
:
support
.
run_unittest
(
UncompressedZipImportTestCase
,
...
...
Misc/NEWS
View file @
4925cde1
...
...
@@ -72,6 +72,9 @@ Core and Builtins
Library
-------
- Issue #12124: zipimport doesn't keep a reference to zlib.decompress() anymore
to be able to unload the module.
- Issue #10801: In zipfile, support different encodings for the header and
the filenames.
...
...
Modules/zipimport.c
View file @
4925cde1
...
...
@@ -785,35 +785,33 @@ error:
/* Return the zlib.decompress function object, or NULL if zlib couldn't
be imported. The function is cached when found, so subsequent calls
don't import zlib again. Returns a *borrowed* reference.
XXX This makes zlib.decompress immortal. */
don't import zlib again. */
static
PyObject
*
get_decompress_func
(
void
)
{
static
PyObject
*
decompress
=
NULL
;
static
int
importing_zlib
=
0
;
PyObject
*
zlib
;
PyObject
*
decompress
;
if
(
decompress
==
NULL
)
{
PyObject
*
zlib
;
static
int
importing_zlib
=
0
;
if
(
importing_zlib
!=
0
)
/* Someone has a zlib.py[co] in their Zip file;
let's avoid a stack overflow. */
return
NULL
;
importing_zlib
=
1
;
zlib
=
PyImport_ImportModuleNoBlock
(
"zlib"
);
importing_zlib
=
0
;
if
(
zlib
!=
NULL
)
{
decompress
=
PyObject_GetAttrString
(
zlib
,
"decompress"
);
Py_DECREF
(
zlib
);
}
else
PyErr_Clear
();
if
(
Py_VerboseFlag
)
PySys_WriteStderr
(
"# zipimport: zlib %s
\n
"
,
zlib
!=
NULL
?
"available"
:
"UNAVAILABLE"
);
if
(
importing_zlib
!=
0
)
/* Someone has a zlib.py[co] in their Zip file;
let's avoid a stack overflow. */
return
NULL
;
importing_zlib
=
1
;
zlib
=
PyImport_ImportModuleNoBlock
(
"zlib"
);
importing_zlib
=
0
;
if
(
zlib
!=
NULL
)
{
decompress
=
PyObject_GetAttrString
(
zlib
,
"decompress"
);
Py_DECREF
(
zlib
);
}
else
{
PyErr_Clear
();
decompress
=
NULL
;
}
if
(
Py_VerboseFlag
)
PySys_WriteStderr
(
"# zipimport: zlib %s
\n
"
,
zlib
!=
NULL
?
"available"
:
"UNAVAILABLE"
);
return
decompress
;
}
...
...
@@ -904,6 +902,7 @@ get_data(char *archive, PyObject *toc_entry)
goto
error
;
}
data
=
PyObject_CallFunction
(
decompress
,
"Oi"
,
raw_data
,
-
15
);
Py_DECREF
(
decompress
);
error:
Py_DECREF
(
raw_data
);
return
data
;
...
...
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