3 # Generate wrapper macros: hybris/include/hybris/internal/binding.h
6 # python utils/generate_wrapper_macros.py >hybris/include/hybris/internal/binding.h
8 # Copyright (C) 2013 Jolla Ltd.
9 # Contact: Thomas Perl <thomas.perl@jollamobile.com>
11 # Redistribution and use in source and binary forms, with or without
12 # modification, are permitted provided that the following conditions are met:
14 # 1. Redistributions of source code must retain the above copyright notice, this
15 # list of conditions and the following disclaimer.
16 # 2. Redistributions in binary form must reproduce the above copyright notice,
17 # this list of conditions and the following disclaimer in the documentation
18 # and/or other materials provided with the distribution.
20 # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
21 # ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
22 # WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
23 # DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
24 # ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
25 # (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
26 # LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
27 # ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
28 # (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
29 # SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
32 # Maximum number of arguments to generate wrapper macros for
37 AUTO_GENERATED_WARNING
= """
39 * XXX AUTO-GENERATED FILE XXX
41 * Do not edit this file directly, but update the templates in
42 * utils/generate_wrapper_macros.py and run it again to build
43 * an updated version of this header file:
45 * python utils/generate_wrapper_macros.py > \\
46 * hybris/include/hybris/internal/binding.h
48 * If you need macros with more arguments, just customize the
49 * MAX_ARGS variable in generate_wrapper_macros.py.
51 * XXX AUTO-GENERATED FILE XXX
57 * Copyright (C) 2013 Simon Busch <morphis@gravedo.de>
61 * Auto-generated via "generate_wrapper_macros.py"
63 * Licensed under the Apache License, Version 2.0 (the "License");
64 * you may not use this file except in compliance with the License.
65 * You may obtain a copy of the License at
67 * http://www.apache.org/licenses/LICENSE-2.0
69 * Unless required by applicable law or agreed to in writing, software
70 * distributed under the License is distributed on an "AS IS" BASIS,
71 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
72 * See the License for the specific language governing permissions and
73 * limitations under the License.
76 #ifndef HYBRIS_BINDING_H_
77 #define HYBRIS_BINDING_H_
79 /* floating_point_abi.h defines FP_ATTRIB */
80 #include <hybris/internal/floating_point_abi.h>
82 void *android_dlopen(const char *filename, int flag);
83 void *android_dlsym(void *name, const char *symbol);
84 int android_dlclose(void *handle);
85 const char *android_dlerror(void);
86 int android_dladdr(const void *addr, void *info);
89 print AUTO_GENERATED_WARNING
92 #define HYBRIS_DLSYSM(name, fptr, sym) \\
93 if (!name##_handle) \\
94 hybris_##name##_initialize(); \\
95 if (*(fptr) == NULL) \\
97 *(fptr) = (void *) android_dlsym(name##_handle, sym); \\
100 #define HYBRIS_LIBRARY_INITIALIZE(name, path) \\
101 void *name##_handle; \\
102 void hybris_##name##_initialize() \\
104 name##_handle = android_dlopen(path, RTLD_LAZY); \\
109 for count
in range(MAX_ARGS
):
110 args
= ['a%d' % (x
+1) for x
in range(count
)]
111 names
= ['n%d' % (x
+1) for x
in range(count
)]
112 wrapper_signature
= ', '.join(['name', 'return_type', 'symbol'] + args
)
113 signature
= ', '.join(args
)
114 signature_with_names
= ', '.join(' '.join(x
) for x
in zip(args
, names
))
115 call_names
= ', '.join(names
)
118 #define HYBRIS_IMPLEMENT_FUNCTION{count}({wrapper_signature}) \\
119 return_type symbol({signature_with_names}) \\
121 static return_type (*f)({signature}) FP_ATTRIB = NULL; \\
122 HYBRIS_DLSYSM(name, &f, #symbol); \\
123 return f({call_names}); \\
125 """.format(**locals())
127 for count
in range(MAX_ARGS
):
128 args
= ['a%d' % (x
+1) for x
in range(count
)]
129 names
= ['n%d' % (x
+1) for x
in range(count
)]
130 wrapper_signature
= ', '.join(['name', 'symbol'] + args
)
131 signature
= ', '.join(args
)
132 signature_with_names
= ', '.join(' '.join(x
) for x
in zip(args
, names
))
133 call_names
= ', '.join(names
)
135 #define HYBRIS_IMPLEMENT_VOID_FUNCTION{count}({wrapper_signature}) \\
136 void symbol({signature_with_names}) \\
138 static void (*f)({signature}) FP_ATTRIB = NULL; \\
139 HYBRIS_DLSYSM(name, &f, #symbol); \\
142 """.format(**locals())
144 # Print it again, so people wanting to append new macros will see it
145 print AUTO_GENERATED_WARNING
148 #endif /* HYBRIS_BINDING_H_ */