Skip to content

Commit

Permalink
Bug 1043144 - Don't write machc bytecode file; r=mshal
Browse files Browse the repository at this point in the history
When writing bytecode, Python will append "c" to the loaded filename to
produce a bytecode file. Since "mach" was being imported, this resulted
in the creation of a "machc" file.

The implementation of imp.load_module() in CPython's import.c checks
sys.dont_write_bytecode. So, we wrap imp.load_module to set this flag
when importing mach.

--HG--
extra : rebase_source : 248a2349663affee3920a0726e10818d57c6ff17
extra : amend_source : 221280da9963cf91975658144ff3011353852fee
  • Loading branch information
indygreg committed Aug 5, 2014
1 parent a084621 commit 2949694
Showing 1 changed file with 17 additions and 0 deletions.
17 changes: 17 additions & 0 deletions mach
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,7 @@ if __name__ == '__main__':
def fork_interpose():
import imp
import os
import sys
orig_find_module = imp.find_module
def my_find_module(name, dirs):
if name == 'mach':
Expand All @@ -100,7 +101,23 @@ if __name__ == '__main__':
return (f, path, ('', 'r', imp.PY_SOURCE))
return orig_find_module(name, dirs)

# Don't allow writing bytecode file for mach module.
orig_load_module = imp.load_module
def my_load_module(name, file, path, description):
# multiprocess.forking invokes imp.load_module manually and
# hard-codes the name __parents_main__ as the module name.
if name == '__parents_main__':
old_bytecode = sys.dont_write_bytecode
sys.dont_write_bytecode = True
try:
return orig_load_module(name, file, path, description)
finally:
sys.dont_write_bytecode = old_bytecode

return orig_load_module(name, file, path, description)

imp.find_module = my_find_module
imp.load_module = my_load_module
from multiprocessing.forking import main; main()

def my_get_command_line():
Expand Down

0 comments on commit 2949694

Please sign in to comment.