summaryrefslogtreecommitdiffstats
path: root/Tools/freeze
diff options
context:
space:
mode:
authorGuido van Rossum <guido@python.org>1998-03-05 05:15:07 (GMT)
committerGuido van Rossum <guido@python.org>1998-03-05 05:15:07 (GMT)
commit3c51cf2b6995995fc02771eceb41683fb194c932 (patch)
treed9e377d7f8c1e68dcdbf3065a33484cc2622e6d2 /Tools/freeze
parent912a14c0287aff5014d14dd4dd228c4032465374 (diff)
downloadcpython-3c51cf2b6995995fc02771eceb41683fb194c932.zip
cpython-3c51cf2b6995995fc02771eceb41683fb194c932.tar.gz
cpython-3c51cf2b6995995fc02771eceb41683fb194c932.tar.bz2
Oops, bug omission: also scan internal code objects for imports!
Diffstat (limited to 'Tools/freeze')
-rw-r--r--Tools/freeze/modulefinder.py68
1 files changed, 37 insertions, 31 deletions
diff --git a/Tools/freeze/modulefinder.py b/Tools/freeze/modulefinder.py
index b6b36e2..8dce01d 100644
--- a/Tools/freeze/modulefinder.py
+++ b/Tools/freeze/modulefinder.py
@@ -232,40 +232,46 @@ class ModuleFinder:
if co:
m.__file__ = pathname
m.__code__ = co
- code = co.co_code
- n = len(code)
- i = 0
- lastname = None
- while i < n:
- c = code[i]
- i = i+1
- op = ord(c)
- if op >= dis.HAVE_ARGUMENT:
- oparg = ord(code[i]) + ord(code[i+1])*256
- i = i+2
- if op == IMPORT_NAME:
- name = lastname = co.co_names[oparg]
- if not self.badmodules.has_key(lastname):
- try:
- self.import_hook(name, m)
- except ImportError, msg:
- self.msg(2, "ImportError:", str(msg))
- self.badmodules[name] = None
- elif op == IMPORT_FROM:
- name = co.co_names[oparg]
- assert lastname is not None
- if not self.badmodules.has_key(lastname):
- try:
- self.import_hook(lastname, m, [name])
- except ImportError, msg:
- self.msg(2, "ImportError:", str(msg))
- fullname = lastname + "." + name
- self.badmodules[fullname] = None
- else:
- lastname = None
+ self.scan_code(co, m)
self.msgout(2, "load_module ->", m)
return m
+ def scan_code(self, co, m):
+ code = co.co_code
+ n = len(code)
+ i = 0
+ lastname = None
+ while i < n:
+ c = code[i]
+ i = i+1
+ op = ord(c)
+ if op >= dis.HAVE_ARGUMENT:
+ oparg = ord(code[i]) + ord(code[i+1])*256
+ i = i+2
+ if op == IMPORT_NAME:
+ name = lastname = co.co_names[oparg]
+ if not self.badmodules.has_key(lastname):
+ try:
+ self.import_hook(name, m)
+ except ImportError, msg:
+ self.msg(2, "ImportError:", str(msg))
+ self.badmodules[name] = None
+ elif op == IMPORT_FROM:
+ name = co.co_names[oparg]
+ assert lastname is not None
+ if not self.badmodules.has_key(lastname):
+ try:
+ self.import_hook(lastname, m, [name])
+ except ImportError, msg:
+ self.msg(2, "ImportError:", str(msg))
+ fullname = lastname + "." + name
+ self.badmodules[fullname] = None
+ else:
+ lastname = None
+ for c in co.co_consts:
+ if isinstance(c, type(co)):
+ self.scan_code(c, m)
+
def load_package(self, fqname, pathname):
self.msgin(2, "load_package", fqname, pathname)
m = self.add_module(fqname)