annotate Tools/scripts/nm2def.py @ 56121:ea697cde6882 3.1

Merged revisions 74881-74885,74888,74891-74895,74900,74905-74906,74931-74932,74934,74941-74942,74944,74956 via svnmerge from svn+ssh://pythondev@svn.python.org/python/branches/py3k ........ r74881 | r.david.murray | 2009-09-17 15:12:49 -0400 (Thu, 17 Sep 2009) | 2 lines Check in first draft of maintainers.rst. ........ r74882 | eric.smith | 2009-09-17 15:22:30 -0400 (Thu, 17 Sep 2009) | 1 line Typo. ........ r74883 | mark.dickinson | 2009-09-17 15:37:28 -0400 (Thu, 17 Sep 2009) | 1 line Add some more module maintainers. ........ r74884 | mark.dickinson | 2009-09-17 15:39:12 -0400 (Thu, 17 Sep 2009) | 1 line Revert accidental changes to Objects/longobject.c ........ r74885 | mark.dickinson | 2009-09-17 16:20:01 -0400 (Thu, 17 Sep 2009) | 1 line Add decimal maintainers ........ r74888 | r.david.murray | 2009-09-17 18:10:48 -0400 (Thu, 17 Sep 2009) | 2 lines Maintainer additions from MAL. ........ r74891 | georg.brandl | 2009-09-17 18:18:01 -0400 (Thu, 17 Sep 2009) | 1 line Some more maintainers. ........ r74892 | r.david.murray | 2009-09-17 19:23:56 -0400 (Thu, 17 Sep 2009) | 2 lines Add a couple interest areas for Nick per his request. ........ r74893 | r.david.murray | 2009-09-17 19:43:20 -0400 (Thu, 17 Sep 2009) | 2 lines Benajmin is also compiler-knowledgeable. ........ r74894 | alexandre.vassalotti | 2009-09-17 20:59:05 -0400 (Thu, 17 Sep 2009) | 2 lines Added myself to my areas of interest. ........ r74895 | brett.cannon | 2009-09-17 21:03:35 -0400 (Thu, 17 Sep 2009) | 1 line Add myself to a couple places as maintainer. ........ r74900 | georg.brandl | 2009-09-18 05:06:37 -0400 (Fri, 18 Sep 2009) | 1 line Add myself in interest areas. ........ r74905 | ezio.melotti | 2009-09-18 05:58:43 -0400 (Fri, 18 Sep 2009) | 1 line Add myself in interest areas and mark effbot as inactive in winsound ........ r74906 | antoine.pitrou | 2009-09-18 09:15:23 -0400 (Fri, 18 Sep 2009) | 3 lines Add myself in a couple of places ........ r74931 | r.david.murray | 2009-09-18 17:25:36 -0400 (Fri, 18 Sep 2009) | 5 lines Add some names gleaned from the "Tracker Archeology" thread on python-dev from back in February. Also consolidate the autoconf and makefiles topics into one, and add tracker and svn/hg topics. ........ r74932 | r.david.murray | 2009-09-18 17:32:16 -0400 (Fri, 18 Sep 2009) | 2 lines Remove non-committer mistakenly added. ........ r74934 | r.david.murray | 2009-09-18 17:40:30 -0400 (Fri, 18 Sep 2009) | 2 lines More descriptive/generic name for the svn/hg entry (version control) ........ r74941 | benjamin.peterson | 2009-09-18 18:45:59 -0400 (Fri, 18 Sep 2009) | 1 line add a new category for myself ........ r74942 | benjamin.peterson | 2009-09-18 18:50:55 -0400 (Fri, 18 Sep 2009) | 1 line add myself for symtable ........ r74944 | georg.brandl | 2009-09-19 03:39:05 -0400 (Sat, 19 Sep 2009) | 1 line I would like to maintain the token module! ........ r74956 | r.david.murray | 2009-09-19 14:40:08 -0400 (Sat, 19 Sep 2009) | 3 lines Add everyone who we know has been a release manager as a resource for the 'release management' topic. ........
author R. David Murray <rdmurray@bitdance.com>
date Sat, 19 Sep 2009 19:04:37 +0000
parents 893a4dc17a91
children fcfe324663a6
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
9281
809dcc1bbc21 Added #! line
Guido van Rossum <guido@python.org>
parents: 9103
diff changeset
1 #! /usr/bin/env python
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()