annotate Tools/scripts/nm2def.py @ 87690:66c1c9f32567 default tip

Add use_weakref option to functools.lru_cache The use_weakref option makes lru_cache create weak references to the function arguments when creating the cache key, which prevents them from staying in the memory forever even after all other references to them are gone. This is a proof of concept for http://bugs.python.org/issue19859
author Radomir Dopieralski <devel@sheep.art.pl>
date Tue, 03 Dec 2013 16:02:48 +0100
parents fcfe324663a6
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
59522
fcfe324663a6 convert shebang lines: python -> python3
Benjamin Peterson <benjamin@python.org>
parents: 47100
diff changeset
1 #! /usr/bin/env python3
8908
7d6813521f61 A script by Mark-Andre Lemburg to produce the PC/python_nt.def file
Guido van Rossum <guido@python.org>
parents:
diff changeset
2 """nm2def.py
7d6813521f61 A script by Mark-Andre Lemburg to produce the PC/python_nt.def file
Guido van Rossum <guido@python.org>
parents:
diff changeset
3
7d6813521f61 A script by Mark-Andre Lemburg to produce the PC/python_nt.def file
Guido van Rossum <guido@python.org>
parents:
diff changeset
4 Helpers to extract symbols from Unix libs and auto-generate
7d6813521f61 A script by Mark-Andre Lemburg to produce the PC/python_nt.def file
Guido van Rossum <guido@python.org>
parents:
diff changeset
5 Windows definition files from them. Depends on nm(1). Tested
7d6813521f61 A script by Mark-Andre Lemburg to produce the PC/python_nt.def file
Guido van Rossum <guido@python.org>
parents:
diff changeset
6 on Linux and Solaris only (-p option to nm is for Solaris only).
7d6813521f61 A script by Mark-Andre Lemburg to produce the PC/python_nt.def file
Guido van Rossum <guido@python.org>
parents:
diff changeset
7
7d6813521f61 A script by Mark-Andre Lemburg to produce the PC/python_nt.def file
Guido van Rossum <guido@python.org>
parents:
diff changeset
8 By Marc-Andre Lemburg, Aug 1998.
7d6813521f61 A script by Mark-Andre Lemburg to produce the PC/python_nt.def file
Guido van Rossum <guido@python.org>
parents:
diff changeset
9
7d6813521f61 A script by Mark-Andre Lemburg to produce the PC/python_nt.def file
Guido van Rossum <guido@python.org>
parents:
diff changeset
10 Additional notes: the output of nm is supposed to look like this:
7d6813521f61 A script by Mark-Andre Lemburg to produce the PC/python_nt.def file
Guido van Rossum <guido@python.org>
parents:
diff changeset
11
7d6813521f61 A script by Mark-Andre Lemburg to produce the PC/python_nt.def file
Guido van Rossum <guido@python.org>
parents:
diff changeset
12 acceler.o:
7d6813521f61 A script by Mark-Andre Lemburg to produce the PC/python_nt.def file
Guido van Rossum <guido@python.org>
parents:
diff changeset
13 000001fd T PyGrammar_AddAccelerators
7d6813521f61 A script by Mark-Andre Lemburg to produce the PC/python_nt.def file
Guido van Rossum <guido@python.org>
parents:
diff changeset
14 U PyGrammar_FindDFA
7d6813521f61 A script by Mark-Andre Lemburg to produce the PC/python_nt.def file
Guido van Rossum <guido@python.org>
parents:
diff changeset
15 00000237 T PyGrammar_RemoveAccelerators
7d6813521f61 A script by Mark-Andre Lemburg to produce the PC/python_nt.def file
Guido van Rossum <guido@python.org>
parents:
diff changeset
16 U _IO_stderr_
7d6813521f61 A script by Mark-Andre Lemburg to produce the PC/python_nt.def file
Guido van Rossum <guido@python.org>
parents:
diff changeset
17 U exit
7d6813521f61 A script by Mark-Andre Lemburg to produce the PC/python_nt.def file
Guido van Rossum <guido@python.org>
parents:
diff changeset
18 U fprintf
7d6813521f61 A script by Mark-Andre Lemburg to produce the PC/python_nt.def file
Guido van Rossum <guido@python.org>
parents:
diff changeset
19 U free
7d6813521f61 A script by Mark-Andre Lemburg to produce the PC/python_nt.def file
Guido van Rossum <guido@python.org>
parents:
diff changeset
20 U malloc
7d6813521f61 A script by Mark-Andre Lemburg to produce the PC/python_nt.def file
Guido van Rossum <guido@python.org>
parents:
diff changeset
21 U printf
7d6813521f61 A script by Mark-Andre Lemburg to produce the PC/python_nt.def file
Guido van Rossum <guido@python.org>
parents:
diff changeset
22
7d6813521f61 A script by Mark-Andre Lemburg to produce the PC/python_nt.def file
Guido van Rossum <guido@python.org>
parents:
diff changeset
23 grammar1.o:
7d6813521f61 A script by Mark-Andre Lemburg to produce the PC/python_nt.def file
Guido van Rossum <guido@python.org>
parents:
diff changeset
24 00000000 T PyGrammar_FindDFA
7d6813521f61 A script by Mark-Andre Lemburg to produce the PC/python_nt.def file
Guido van Rossum <guido@python.org>
parents:
diff changeset
25 00000034 T PyGrammar_LabelRepr
7d6813521f61 A script by Mark-Andre Lemburg to produce the PC/python_nt.def file
Guido van Rossum <guido@python.org>
parents:
diff changeset
26 U _PyParser_TokenNames
7d6813521f61 A script by Mark-Andre Lemburg to produce the PC/python_nt.def file
Guido van Rossum <guido@python.org>
parents:
diff changeset
27 U abort
7d6813521f61 A script by Mark-Andre Lemburg to produce the PC/python_nt.def file
Guido van Rossum <guido@python.org>
parents:
diff changeset
28 U printf
7d6813521f61 A script by Mark-Andre Lemburg to produce the PC/python_nt.def file
Guido van Rossum <guido@python.org>
parents:
diff changeset
29 U sprintf
7d6813521f61 A script by Mark-Andre Lemburg to produce the PC/python_nt.def file
Guido van Rossum <guido@python.org>
parents:
diff changeset
30
7d6813521f61 A script by Mark-Andre Lemburg to produce the PC/python_nt.def file
Guido van Rossum <guido@python.org>
parents:
diff changeset
31 ...
7d6813521f61 A script by Mark-Andre Lemburg to produce the PC/python_nt.def file
Guido van Rossum <guido@python.org>
parents:
diff changeset
32
7d6813521f61 A script by Mark-Andre Lemburg to produce the PC/python_nt.def file
Guido van Rossum <guido@python.org>
parents:
diff changeset
33 Even if this isn't the default output of your nm, there is generally an
7d6813521f61 A script by Mark-Andre Lemburg to produce the PC/python_nt.def file
Guido van Rossum <guido@python.org>
parents:
diff changeset
34 option to produce this format (since it is the original v7 Unix format).
7d6813521f61 A script by Mark-Andre Lemburg to produce the PC/python_nt.def file
Guido van Rossum <guido@python.org>
parents:
diff changeset
35
7d6813521f61 A script by Mark-Andre Lemburg to produce the PC/python_nt.def file
Guido van Rossum <guido@python.org>
parents:
diff changeset
36 """
45471
7dd2c1746267 Merged revisions 60990-61002 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents: 25219
diff changeset
37 import os, sys
8908
7d6813521f61 A script by Mark-Andre Lemburg to produce the PC/python_nt.def file
Guido van Rossum <guido@python.org>
parents:
diff changeset
38
7d6813521f61 A script by Mark-Andre Lemburg to produce the PC/python_nt.def file
Guido van Rossum <guido@python.org>
parents:
diff changeset
39 PYTHONLIB = 'libpython'+sys.version[:3]+'.a'
7d6813521f61 A script by Mark-Andre Lemburg to produce the PC/python_nt.def file
Guido van Rossum <guido@python.org>
parents:
diff changeset
40 PC_PYTHONLIB = 'Python'+sys.version[0]+sys.version[2]+'.dll'
7d6813521f61 A script by Mark-Andre Lemburg to produce the PC/python_nt.def file
Guido van Rossum <guido@python.org>
parents:
diff changeset
41 NM = 'nm -p -g %s' # For Linux, use "nm -g %s"
7d6813521f61 A script by Mark-Andre Lemburg to produce the PC/python_nt.def file
Guido van Rossum <guido@python.org>
parents:
diff changeset
42
7d6813521f61 A script by Mark-Andre Lemburg to produce the PC/python_nt.def file
Guido van Rossum <guido@python.org>
parents:
diff changeset
43 def symbols(lib=PYTHONLIB,types=('T','C','D')):
7d6813521f61 A script by Mark-Andre Lemburg to produce the PC/python_nt.def file
Guido van Rossum <guido@python.org>
parents:
diff changeset
44
7d6813521f61 A script by Mark-Andre Lemburg to produce the PC/python_nt.def file
Guido van Rossum <guido@python.org>
parents:
diff changeset
45 lines = os.popen(NM % lib).readlines()
25219
8a7a2f1f88f0 Apply diff2.txt from SF patch http://www.python.org/sf/572113
Walter Dörwald <walter@livinglogic.de>
parents: 15930
diff changeset
46 lines = [s.strip() for s in lines]
8908
7d6813521f61 A script by Mark-Andre Lemburg to produce the PC/python_nt.def file
Guido van Rossum <guido@python.org>
parents:
diff changeset
47 symbols = {}
7d6813521f61 A script by Mark-Andre Lemburg to produce the PC/python_nt.def file
Guido van Rossum <guido@python.org>
parents:
diff changeset
48 for line in lines:
9103
77a9b85f762a nannified
Guido van Rossum <guido@python.org>
parents: 8908
diff changeset
49 if len(line) == 0 or ':' in line:
77a9b85f762a nannified
Guido van Rossum <guido@python.org>
parents: 8908
diff changeset
50 continue
25219
8a7a2f1f88f0 Apply diff2.txt from SF patch http://www.python.org/sf/572113
Walter Dörwald <walter@livinglogic.de>
parents: 15930
diff changeset
51 items = line.split()
9103
77a9b85f762a nannified
Guido van Rossum <guido@python.org>
parents: 8908
diff changeset
52 if len(items) != 3:
77a9b85f762a nannified
Guido van Rossum <guido@python.org>
parents: 8908
diff changeset
53 continue
77a9b85f762a nannified
Guido van Rossum <guido@python.org>
parents: 8908
diff changeset
54 address, type, name = items
77a9b85f762a nannified
Guido van Rossum <guido@python.org>
parents: 8908
diff changeset
55 if type not in types:
77a9b85f762a nannified
Guido van Rossum <guido@python.org>
parents: 8908
diff changeset
56 continue
77a9b85f762a nannified
Guido van Rossum <guido@python.org>
parents: 8908
diff changeset
57 symbols[name] = address,type
8908
7d6813521f61 A script by Mark-Andre Lemburg to produce the PC/python_nt.def file
Guido van Rossum <guido@python.org>
parents:
diff changeset
58 return symbols
7d6813521f61 A script by Mark-Andre Lemburg to produce the PC/python_nt.def file
Guido van Rossum <guido@python.org>
parents:
diff changeset
59
7d6813521f61 A script by Mark-Andre Lemburg to produce the PC/python_nt.def file
Guido van Rossum <guido@python.org>
parents:
diff changeset
60 def export_list(symbols):
7d6813521f61 A script by Mark-Andre Lemburg to produce the PC/python_nt.def file
Guido van Rossum <guido@python.org>
parents:
diff changeset
61
7d6813521f61 A script by Mark-Andre Lemburg to produce the PC/python_nt.def file
Guido van Rossum <guido@python.org>
parents:
diff changeset
62 data = []
7d6813521f61 A script by Mark-Andre Lemburg to produce the PC/python_nt.def file
Guido van Rossum <guido@python.org>
parents:
diff changeset
63 code = []
7d6813521f61 A script by Mark-Andre Lemburg to produce the PC/python_nt.def file
Guido van Rossum <guido@python.org>
parents:
diff changeset
64 for name,(addr,type) in symbols.items():
9103
77a9b85f762a nannified
Guido van Rossum <guido@python.org>
parents: 8908
diff changeset
65 if type in ('C','D'):
77a9b85f762a nannified
Guido van Rossum <guido@python.org>
parents: 8908
diff changeset
66 data.append('\t'+name)
77a9b85f762a nannified
Guido van Rossum <guido@python.org>
parents: 8908
diff changeset
67 else:
77a9b85f762a nannified
Guido van Rossum <guido@python.org>
parents: 8908
diff changeset
68 code.append('\t'+name)
8908
7d6813521f61 A script by Mark-Andre Lemburg to produce the PC/python_nt.def file
Guido van Rossum <guido@python.org>
parents:
diff changeset
69 data.sort()
7d6813521f61 A script by Mark-Andre Lemburg to produce the PC/python_nt.def file
Guido van Rossum <guido@python.org>
parents:
diff changeset
70 data.append('')
7d6813521f61 A script by Mark-Andre Lemburg to produce the PC/python_nt.def file
Guido van Rossum <guido@python.org>
parents:
diff changeset
71 code.sort()
25219
8a7a2f1f88f0 Apply diff2.txt from SF patch http://www.python.org/sf/572113
Walter Dörwald <walter@livinglogic.de>
parents: 15930
diff changeset
72 return ' DATA\n'.join(data)+'\n'+'\n'.join(code)
8908
7d6813521f61 A script by Mark-Andre Lemburg to produce the PC/python_nt.def file
Guido van Rossum <guido@python.org>
parents:
diff changeset
73
7d6813521f61 A script by Mark-Andre Lemburg to produce the PC/python_nt.def file
Guido van Rossum <guido@python.org>
parents:
diff changeset
74 # Definition file template
7d6813521f61 A script by Mark-Andre Lemburg to produce the PC/python_nt.def file
Guido van Rossum <guido@python.org>
parents:
diff changeset
75 DEF_TEMPLATE = """\
7d6813521f61 A script by Mark-Andre Lemburg to produce the PC/python_nt.def file
Guido van Rossum <guido@python.org>
parents:
diff changeset
76 EXPORTS
7d6813521f61 A script by Mark-Andre Lemburg to produce the PC/python_nt.def file
Guido van Rossum <guido@python.org>
parents:
diff changeset
77 %s
7d6813521f61 A script by Mark-Andre Lemburg to produce the PC/python_nt.def file
Guido van Rossum <guido@python.org>
parents:
diff changeset
78 """
7d6813521f61 A script by Mark-Andre Lemburg to produce the PC/python_nt.def file
Guido van Rossum <guido@python.org>
parents:
diff changeset
79
7d6813521f61 A script by Mark-Andre Lemburg to produce the PC/python_nt.def file
Guido van Rossum <guido@python.org>
parents:
diff changeset
80 # Special symbols that have to be included even though they don't
7d6813521f61 A script by Mark-Andre Lemburg to produce the PC/python_nt.def file
Guido van Rossum <guido@python.org>
parents:
diff changeset
81 # pass the filter
7d6813521f61 A script by Mark-Andre Lemburg to produce the PC/python_nt.def file
Guido van Rossum <guido@python.org>
parents:
diff changeset
82 SPECIALS = (
7d6813521f61 A script by Mark-Andre Lemburg to produce the PC/python_nt.def file
Guido van Rossum <guido@python.org>
parents:
diff changeset
83 )
7d6813521f61 A script by Mark-Andre Lemburg to produce the PC/python_nt.def file
Guido van Rossum <guido@python.org>
parents:
diff changeset
84
7d6813521f61 A script by Mark-Andre Lemburg to produce the PC/python_nt.def file
Guido van Rossum <guido@python.org>
parents:
diff changeset
85 def filter_Python(symbols,specials=SPECIALS):
7d6813521f61 A script by Mark-Andre Lemburg to produce the PC/python_nt.def file
Guido van Rossum <guido@python.org>
parents:
diff changeset
86
47100
893a4dc17a91 Ran 2to3 over scripts directory.
Georg Brandl <georg@python.org>
parents: 45471
diff changeset
87 for name in list(symbols.keys()):
9103
77a9b85f762a nannified
Guido van Rossum <guido@python.org>
parents: 8908
diff changeset
88 if name[:2] == 'Py' or name[:3] == '_Py':
77a9b85f762a nannified
Guido van Rossum <guido@python.org>
parents: 8908
diff changeset
89 pass
77a9b85f762a nannified
Guido van Rossum <guido@python.org>
parents: 8908
diff changeset
90 elif name not in specials:
77a9b85f762a nannified
Guido van Rossum <guido@python.org>
parents: 8908
diff changeset
91 del symbols[name]
8908
7d6813521f61 A script by Mark-Andre Lemburg to produce the PC/python_nt.def file
Guido van Rossum <guido@python.org>
parents:
diff changeset
92
7d6813521f61 A script by Mark-Andre Lemburg to produce the PC/python_nt.def file
Guido van Rossum <guido@python.org>
parents:
diff changeset
93 def main():
7d6813521f61 A script by Mark-Andre Lemburg to produce the PC/python_nt.def file
Guido van Rossum <guido@python.org>
parents:
diff changeset
94
7d6813521f61 A script by Mark-Andre Lemburg to produce the PC/python_nt.def file
Guido van Rossum <guido@python.org>
parents:
diff changeset
95 s = symbols(PYTHONLIB)
7d6813521f61 A script by Mark-Andre Lemburg to produce the PC/python_nt.def file
Guido van Rossum <guido@python.org>
parents:
diff changeset
96 filter_Python(s)
7d6813521f61 A script by Mark-Andre Lemburg to produce the PC/python_nt.def file
Guido van Rossum <guido@python.org>
parents:
diff changeset
97 exports = export_list(s)
7d6813521f61 A script by Mark-Andre Lemburg to produce the PC/python_nt.def file
Guido van Rossum <guido@python.org>
parents:
diff changeset
98 f = sys.stdout # open('PC/python_nt.def','w')
7d6813521f61 A script by Mark-Andre Lemburg to produce the PC/python_nt.def file
Guido van Rossum <guido@python.org>
parents:
diff changeset
99 f.write(DEF_TEMPLATE % (exports))
7d6813521f61 A script by Mark-Andre Lemburg to produce the PC/python_nt.def file
Guido van Rossum <guido@python.org>
parents:
diff changeset
100 f.close()
15930
14a27acc755a Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 9281
diff changeset
101
8908
7d6813521f61 A script by Mark-Andre Lemburg to produce the PC/python_nt.def file
Guido van Rossum <guido@python.org>
parents:
diff changeset
102 if __name__ == '__main__':
7d6813521f61 A script by Mark-Andre Lemburg to produce the PC/python_nt.def file
Guido van Rossum <guido@python.org>
parents:
diff changeset
103 main()