zmc
2023-12-22 9fdbf60165db0400c2e8e6be2dc6e88138ac719a
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
U
O±d¢ã@sddlZddlZddlZdZdZdeejdd…ƒZddgZdeZ    e 
d    eej ¡Z e 
d
eej ¡Z d d „Zddd egdfdd„Zdd„Zejfdd„Zedkreƒ\ZZedkrÄejZn
eedƒZeeeƒgZeeddZeeƒ\ZZeeee    eƒdS)éNaÔThis module generates a DEF file from the symbols in
an MSVC-compiled DLL import library.  It correctly discriminates between
data and functions.  The data is collected from the output of the program
nm(1).
 
Usage:
    python lib2def.py [libname.lib] [output.def]
or
    python lib2def.py [libname.lib] > output.def
 
libname.lib defaults to python<py_ver>.lib and output.def defaults to stdout
 
Author: Robert Kern <kernr@mail.ncifcrf.gov>
Last Update: April 30, 1999
z0.1az%d%déÚnmz-CszrLIBRARY         python%s.dll
;CODE           PRELOAD MOVEABLE DISCARDABLE
;DATA           PRELOAD SINGLE
 
EXPORTS
z^(.*) in python%s\.dllz^_imp__(.*) in python%s\.dllcCsttjƒdkr tjddd…dkrNtjddd…dkrNtjdd…\}}nPtjddd…dkrŽtjddd…dkrŽtjdd…\}}ntdƒtd    ƒnjttjƒdkrþtjddd…dkrØtjd}d
t}n$tjddd…dkrüd}tjd}n d
t}d}||fS) zBParses the command-line arguments.
 
libfile, deffile = parse_cmd()éééüÿÿÿNz.librz.defz4I'm assuming that your first argument is the libraryzand the second is the DEF file.ú python%s.lib)ÚlenÚsysÚargvÚprintÚpy_ver)ÚlibfileÚdeffile©rúNd:\z\workplace\vscode\pyvenv\venv\Lib\site-packages\numpy/distutils/lib2def.pyÚ    parse_cmd&s",,
 
 
 rrTcCsHtj||tjtjdd}| ¡\}}|jdkrDtdd |¡|fƒ‚|S)zUReturns the output of nm_cmd via a pipe.
 
nm_output = getnm(nm_cmd = 'nm -Cs py_lib')T)ÚshellÚstdoutÚstderrÚtextrzfailed to run "%s": "%s"ú )Ú
subprocessÚPopenÚPIPEÚ communicateÚ
returncodeÚ RuntimeErrorÚjoin)Únm_cmdrÚpÚ    nm_outputZnm_errrrrÚgetnm>s ÿ 
ÿr!cCs¼t |¡}t |¡}g}|D]F}||kr|dd…dksX|dd…dksX|dd…dkr| |¡qg}|D]6}||krl|dd…dks˜|dd…dkrl| |¡ql| ¡| ¡||fS)zŒReturns a tuple of lists: dlist for the list of data
symbols and flist for the list of function symbols.
 
dlist, flist = parse_nm(nm_output)NrZPyrZ_PyéÚinit)ÚDATA_REÚfindallÚFUNC_REÚappendÚsort)r ÚdataÚfuncÚflistÚsymÚdlistrrrÚparse_nmJs
 
8 ( r.cCsB|D]}|d|}q|d}|D]}|d|}q"| |¡dS)zoOutputs the final DEF file to a file defaulting to stdout.
 
output_def(dlist, flist, header, file = sys.stdout)z        %s DATA
Ú
z    %s
N)Úwrite)r-r+ÚheaderÚfileZdata_symZfunc_symrrrÚ
output_def`s r3Ú__main__ÚwF)r)Úrer    rÚ__doc__Ú __version__ÚtupleÚ version_infor Z
DEFAULT_NMZ
DEF_HEADERÚcompileÚ    MULTILINEr&r$rr!r.rr3Ú__name__r rÚopenÚstrrr r-r+rrrrÚ<module>s0û