[Python-checkins] cpython: don't depend on __debug__ because it's baked in at freeze time (issue #16046)
benjamin.peterson
python-checkins at python.org
Tue Sep 25 17:23:17 CEST 2012
http://hg.python.org/cpython/rev/4de5e4ec3cff
changeset: 79173:4de5e4ec3cff
parent: 79170:856c12dd1deb
user: Benjamin Peterson <benjamin at python.org>
date: Tue Sep 25 11:22:59 2012 -0400
summary:
don't depend on __debug__ because it's baked in at freeze time (issue #16046)
files:
Lib/importlib/_bootstrap.py | 17 +-
Misc/NEWS | 2 +
Python/importlib.h | 8533 +++++++++++-----------
3 files changed, 4282 insertions(+), 4270 deletions(-)
diff --git a/Lib/importlib/_bootstrap.py b/Lib/importlib/_bootstrap.py
--- a/Lib/importlib/_bootstrap.py
+++ b/Lib/importlib/_bootstrap.py
@@ -411,25 +411,21 @@
DEBUG_BYTECODE_SUFFIXES = ['.pyc']
OPTIMIZED_BYTECODE_SUFFIXES = ['.pyo']
-if __debug__:
- BYTECODE_SUFFIXES = DEBUG_BYTECODE_SUFFIXES
-else:
- BYTECODE_SUFFIXES = OPTIMIZED_BYTECODE_SUFFIXES
def cache_from_source(path, debug_override=None):
"""Given the path to a .py file, return the path to its .pyc/.pyo file.
The .py file does not need to exist; this simply returns the path to the
.pyc/.pyo file calculated as if the .py file were imported. The extension
- will be .pyc unless __debug__ is not defined, then it will be .pyo.
+ will be .pyc unless sys.flags.optimize is non-zero, then it will be .pyo.
If debug_override is not None, then it must be a boolean and is taken as
- the value of __debug__ instead.
+ the value of bool(sys.flags.optimize) instead.
If sys.implementation.cache_tag is None then NotImplementedError is raised.
"""
- debug = __debug__ if debug_override is None else debug_override
+ debug = not sys.flags.optimize if debug_override is None else debug_override
if debug:
suffixes = DEBUG_BYTECODE_SUFFIXES
else:
@@ -1688,10 +1684,15 @@
modules, those two modules must be explicitly passed in.
"""
- global _imp, sys
+ global _imp, sys, BYTECODE_SUFFIXES
_imp = _imp_module
sys = sys_module
+ if sys.flags.optimize:
+ BYTECODE_SUFFIXES = OPTIMIZED_BYTECODE_SUFFIXES
+ else:
+ BYTECODE_SUFFIXES = DEBUG_BYTECODE_SUFFIXES
+
for module in (_imp, sys):
if not hasattr(module, '__loader__'):
module.__loader__ = BuiltinImporter
diff --git a/Misc/NEWS b/Misc/NEWS
--- a/Misc/NEWS
+++ b/Misc/NEWS
@@ -10,6 +10,8 @@
Core and Builtins
-----------------
+- Issue #16046: Fix loading sourceless legacy pyos.
+
- Issue #15379: Fix passing of non-BMP characters as integers for the charmap
decoder (already working as unicode strings). Patch by Serhiy Storchaka.
diff --git a/Python/importlib.h b/Python/importlib.h
--- a/Python/importlib.h
+++ b/Python/importlib.h
[stripped]
--
Repository URL: http://hg.python.org/cpython
More information about the Python-checkins
mailing list