Mercurial > cpython-lru_cache-weakref
annotate Python/makeopcodetargets.py @ 78758:ca4bf8e10bc0
Issue #15316: Let exceptions raised during imports triggered by the
fromlist of __import__ propagate.
The problem previously was that if something listed in fromlist didn't
exist then that's okay. The fix for that was too broad in terms of
catching ImportError.
The trick with the solution to this issue is that the proper
refactoring of import thanks to importlib doesn't allow for a way to
distinguish (portably) between an ImportError because finders couldn't
find a loader, or a loader raised the exception. In Python 3.4 the
hope is to introduce a new exception (e.g. ModuleNotFound) to make it
clean to differentiate why ImportError was raised.
| author | Brett Cannon <brett@python.org> |
|---|---|
| date | Fri, 24 Aug 2012 18:25:59 -0400 |
| parents | d30b54ffd5e8 |
| children |
| rev | line source |
|---|---|
|
51031
d86e23318b41
Issue #4753: By enabling a configure option named '--with-computed-gotos'
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
1 #! /usr/bin/env python |
|
d86e23318b41
Issue #4753: By enabling a configure option named '--with-computed-gotos'
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
2 """Generate C code for the jump table of the threaded code interpreter |
|
d86e23318b41
Issue #4753: By enabling a configure option named '--with-computed-gotos'
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
3 (for compilers supporting computed gotos or "labels-as-values", such as gcc). |
|
d86e23318b41
Issue #4753: By enabling a configure option named '--with-computed-gotos'
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
4 """ |
|
d86e23318b41
Issue #4753: By enabling a configure option named '--with-computed-gotos'
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
5 |
|
51202
df090597afaa
Make Python/makeopcodetargets runnable with Python 2.3. With any luck, this
Mark Dickinson <dickinsm@gmail.com>
parents:
51031
diff
changeset
|
6 # This code should stay compatible with Python 2.3, at least while |
|
df090597afaa
Make Python/makeopcodetargets runnable with Python 2.3. With any luck, this
Mark Dickinson <dickinsm@gmail.com>
parents:
51031
diff
changeset
|
7 # some of the buildbots have Python 2.3 as their system Python. |
|
df090597afaa
Make Python/makeopcodetargets runnable with Python 2.3. With any luck, this
Mark Dickinson <dickinsm@gmail.com>
parents:
51031
diff
changeset
|
8 |
|
51031
d86e23318b41
Issue #4753: By enabling a configure option named '--with-computed-gotos'
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
9 import imp |
|
d86e23318b41
Issue #4753: By enabling a configure option named '--with-computed-gotos'
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
10 import os |
|
d86e23318b41
Issue #4753: By enabling a configure option named '--with-computed-gotos'
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
11 |
|
d86e23318b41
Issue #4753: By enabling a configure option named '--with-computed-gotos'
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
12 |
|
d86e23318b41
Issue #4753: By enabling a configure option named '--with-computed-gotos'
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
13 def find_module(modname): |
|
d86e23318b41
Issue #4753: By enabling a configure option named '--with-computed-gotos'
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
14 """Finds and returns a module in the local dist/checkout. |
|
d86e23318b41
Issue #4753: By enabling a configure option named '--with-computed-gotos'
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
15 """ |
|
d86e23318b41
Issue #4753: By enabling a configure option named '--with-computed-gotos'
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
16 modpath = os.path.join( |
|
d86e23318b41
Issue #4753: By enabling a configure option named '--with-computed-gotos'
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
17 os.path.dirname(os.path.dirname(__file__)), "Lib") |
|
d86e23318b41
Issue #4753: By enabling a configure option named '--with-computed-gotos'
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
18 return imp.load_module(modname, *imp.find_module(modname, [modpath])) |
|
d86e23318b41
Issue #4753: By enabling a configure option named '--with-computed-gotos'
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
19 |
|
d86e23318b41
Issue #4753: By enabling a configure option named '--with-computed-gotos'
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
20 def write_contents(f): |
|
d86e23318b41
Issue #4753: By enabling a configure option named '--with-computed-gotos'
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
21 """Write C code contents to the target file object. |
|
d86e23318b41
Issue #4753: By enabling a configure option named '--with-computed-gotos'
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
22 """ |
|
d86e23318b41
Issue #4753: By enabling a configure option named '--with-computed-gotos'
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
23 opcode = find_module("opcode") |
|
d86e23318b41
Issue #4753: By enabling a configure option named '--with-computed-gotos'
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
24 targets = ['_unknown_opcode'] * 256 |
|
d86e23318b41
Issue #4753: By enabling a configure option named '--with-computed-gotos'
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
25 for opname, op in opcode.opmap.items(): |
|
d86e23318b41
Issue #4753: By enabling a configure option named '--with-computed-gotos'
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
26 targets[op] = "TARGET_%s" % opname |
|
d86e23318b41
Issue #4753: By enabling a configure option named '--with-computed-gotos'
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
27 f.write("static void *opcode_targets[256] = {\n") |
|
61467
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
51202
diff
changeset
|
28 f.write(",\n".join([" &&%s" % s for s in targets])) |
|
51031
d86e23318b41
Issue #4753: By enabling a configure option named '--with-computed-gotos'
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
29 f.write("\n};\n") |
|
d86e23318b41
Issue #4753: By enabling a configure option named '--with-computed-gotos'
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
30 |
|
d86e23318b41
Issue #4753: By enabling a configure option named '--with-computed-gotos'
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
31 |
|
d86e23318b41
Issue #4753: By enabling a configure option named '--with-computed-gotos'
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
32 if __name__ == "__main__": |
|
d86e23318b41
Issue #4753: By enabling a configure option named '--with-computed-gotos'
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
33 import sys |
|
d86e23318b41
Issue #4753: By enabling a configure option named '--with-computed-gotos'
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
34 assert len(sys.argv) < 3, "Too many arguments" |
|
d86e23318b41
Issue #4753: By enabling a configure option named '--with-computed-gotos'
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
35 if len(sys.argv) == 2: |
|
d86e23318b41
Issue #4753: By enabling a configure option named '--with-computed-gotos'
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
36 target = sys.argv[1] |
|
d86e23318b41
Issue #4753: By enabling a configure option named '--with-computed-gotos'
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
37 else: |
|
d86e23318b41
Issue #4753: By enabling a configure option named '--with-computed-gotos'
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
38 target = "Python/opcode_targets.h" |
|
d86e23318b41
Issue #4753: By enabling a configure option named '--with-computed-gotos'
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
39 f = open(target, "w") |
|
d86e23318b41
Issue #4753: By enabling a configure option named '--with-computed-gotos'
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
40 try: |
|
d86e23318b41
Issue #4753: By enabling a configure option named '--with-computed-gotos'
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
41 write_contents(f) |
|
d86e23318b41
Issue #4753: By enabling a configure option named '--with-computed-gotos'
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
42 finally: |
|
d86e23318b41
Issue #4753: By enabling a configure option named '--with-computed-gotos'
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
43 f.close() |
