]> git.cworth.org Git - apitrace/blob - dl.py
Unify GL specs.
[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
29 from base import *
30
31
32 class DllFunction(Function):
33
34     def __init__(self, type, name, args, call = '', fail = None):
35         Function.__init__(self, type, name, args, call=call, fail=fail)
36         
37     def get_true_pointer(self):
38         ptype = self.pointer_type()
39         pvalue = self.pointer_value()
40         print '    if(!%s) {' % (pvalue,)
41         print '        %s = (%s)dlsym(RTLD_NEXT, "%s");' % (pvalue, ptype, self.name)
42         print '        if(!%s)' % (pvalue,)
43         self.fail_impl()
44         print '    }'
45
46
47 class Dll:
48
49     def __init__(self, name):
50         self.name = name
51         self.functions = []
52         if self not in towrap:
53             towrap.append(self)
54
55     def wrap_name(self):
56         return "Wrap" + self.name
57
58     def wrap_pre_decl(self):
59         pass
60
61     def wrap_decl(self):
62         for function in self.functions:
63             function.wrap_decl()
64         print
65
66     def wrap_impl(self):
67         for function in self.functions:
68             function.wrap_impl()
69         print
70         print '''
71 static void _init(void) __attribute__((constructor));
72 static void _init(void) {'''
73         print r'        Log::Open("%s");' % self.name
74         print '''}
75
76 static void _uninit(void) __attribute__((destructor));
77 static void _uninit(void) {
78     Log::Close();
79 }
80 '''
81