]> git.cworth.org Git - apitrace/blob - dl.py
Cleanup files.
[apitrace] / dl.py
1 ##########################################################################
2 #
3 # Copyright 2008-2010 VMware, Inc.
4 # All Rights Reserved.
5 #
6 # Permission is hereby granted, free of charge, to any person obtaining a copy
7 # of this software and associated documentation files (the "Software"), to deal
8 # in the Software without restriction, including without limitation the rights
9 # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10 # copies of the Software, and to permit persons to whom the Software is
11 # furnished to do so, subject to the following conditions:
12 #
13 # The above copyright notice and this permission notice shall be included in
14 # all copies or substantial portions of the Software.
15 #
16 # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19 # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20 # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21 # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
22 # THE SOFTWARE.
23 #
24 ##########################################################################/
25
26 """dl"""
27
28 from base import *
29
30 class DllFunction(Function):
31
32     def __init__(self, type, name, args, call = '', fail = None):
33         Function.__init__(self, type, name, args, call=call, fail=fail)
34         
35     def exit_impl(self):
36         print '            exit(0);'
37
38     def get_true_pointer(self):
39         ptype = self.pointer_type()
40         pvalue = self.pointer_value()
41         print '    if(!%s) {' % (pvalue,)
42         print '        %s = (%s)dlsym(RTLD_NEXT, "%s");' % (pvalue, ptype, self.name)
43         print '        if(!%s)' % (pvalue,)
44         self.fail_impl()
45         print '    }'
46
47
48 class Dll:
49
50     def __init__(self, name):
51         self.name = name
52         self.functions = []
53         if self not in towrap:
54             towrap.append(self)
55
56     def wrap_name(self):
57         return "Wrap" + self.name
58
59     def wrap_pre_decl(self):
60         pass
61
62     def wrap_decl(self):
63         for function in self.functions:
64             function.wrap_decl()
65         print
66
67     def wrap_impl(self):
68         for function in self.functions:
69             function.wrap_impl()
70         print
71         print '''
72 static void _init(void) __attribute__((constructor));
73 static void _init(void) {'''
74         print r'        Log::Open("%s");' % self.name
75         print '''}
76
77 static void _uninit(void) __attribute__((destructor));
78 static void _uninit(void) {
79     Log::Close();
80 }
81 '''
82