@@ -200,20 +200,130 @@ GDO_DECL gdo_char_t *gdo_lib_origin(void)
200200 */
201201#define GDO_ALIAS_ %%func_symbol_pad%% gdo_hndl.ptr.%%func_symbol%%
202202#define GDO_ALIAS_ %%obj_symbol_pad%% *gdo_hndl.ptr.%%obj_symbol%%
203+ %PARAM_SKIP_REMOVE_BEGIN %
203204
204205
206+ /*****************************************************************************/
207+ /* wrap code */
208+ /*****************************************************************************/
209+ #if defined(GDO_WRAP_FUNCTIONS ) || defined(GDO_ENABLE_AUTOLOAD )
210+
211+ /* #define empty hooks by default */
212+ #ifndef GDO_HOOK_ %%func_symbol %%@
213+ #define GDO_HOOK_ %%func_symbol%%(...) /**/ @
214+ #endif
215+
216+
217+ /* set visibility of wrapped functions */
218+ #ifdef GDO_WRAP_IS_VISIBLE
219+ /* visible as regular functions */
220+ # define GDO_WRAP_DECL /**/
221+ # define GDO_WRAP (x ) x
222+ # else
223+ /* declare as prefixed inline functions by default */
224+ # define GDO_WRAP_DECL static inline
225+ # define GDO_WRAP (x ) GDO_WRAP_##x
226+ #endif
227+
228+
229+ #ifdef GDO_ENABLE_AUTOLOAD
230+ /* autoload function */
231+ GDO_DECL void _gdo_quick_load (int symbol_num , const gdo_char_t * sym );
232+ # define GDO_WRAP_CHECK (x ) _gdo_quick_load(GDO_LOAD_##x, GDO_T(#x))
233+ #else
234+ /* check if function was loaded */
235+ GDO_DECL void _gdo_wrap_check_if_loaded (bool sym_loaded , const gdo_char_t * sym );
236+ # define GDO_WRAP_CHECK (x ) _gdo_wrap_check_if_loaded((gdo_hndl.ptr.x != NULL), GDO_T(#x))
237+ #endif
238+
239+
240+ /* create a wrapper function */
241+ #define GDO_MAKE_FUNCTION (RETURN , TYPE , SYMBOL , ARGS , ...) \
242+ GDO_WRAP_DECL \
243+ TYPE GDO_WRAP(SYMBOL) ARGS { \
244+ GDO_WRAP_CHECK(SYMBOL); \
245+ GDO_HOOK_##SYMBOL(__VA_ARGS__); \
246+ RETURN gdo_hndl.ptr.SYMBOL(__VA_ARGS__); \
247+ }
248+
205249/**
206- * Disable aliasing if we saved into separate files and the
207- * header file was included from the body file.
250+ * create a GNU inline wrapper function for use with variable arguments
251+ * https://gcc.gnu.org/onlinedocs/gcc/Constructing-Calls.html
208252 */
209- #if defined(GDO_SEPARATE ) && !defined(GDO_INCLUDED_IN_BODY ) && !defined(GDO_DISABLE_ALIASING )
253+ #define GDO_MAKE_VA_ARG_FUNCTION (RETURN , TYPE , SYMBOL , ARGS , ...) \
254+ extern inline __attribute__((__gnu_inline__)) \
255+ TYPE GDO_WRAP(SYMBOL) ARGS { \
256+ GDO_WRAP_CHECK(SYMBOL); \
257+ GDO_HOOK_##SYMBOL(__VA_ARGS__, __builtin_va_arg_pack()); \
258+ RETURN gdo_hndl.ptr.SYMBOL(__VA_ARGS__, __builtin_va_arg_pack()); \
259+ }
260+
261+
262+ /* diagnostic warnings on variable arguments functions */
263+ #if !defined(GDO_DISABLE_WARNINGS )
264+
265+ #ifdef GDO_HAS_VA_ARGS_ %%func_symbol %%@
266+ # ifdef GDO_HAS_BUILTIN_VA_ARG_PACK @
267+ # ifdef GDO_WRAP_IS_VISIBLE @
268+ # warning "%%func_symbol%%: GDO_WRAP_IS_VISIBLE defined but function can only be used inlined"@
269+ # endif @
270+ # else @
271+ # warning "%%func_symbol%%: __builtin_va_arg_pack() required to use variable arguments wrapper"@
272+ # endif @
273+ #endif
274+
275+ #endif //!GDO_DISABLE_WARNINGS
276+
277+ @
278+ /* %%func_symbol%%() */ @
279+ #ifdef GDO_HAS_VA_ARGS_ %%func_symbol %%@
280+ # ifdef GDO_HAS_BUILTIN_VA_ARG_PACK @
281+ GDO_MAKE_VA_ARG_FUNCTION (%%return %%, %%type %%,@
282+ %%func_symbol %%, (%%args %%),@
283+ %%notype_args %%)@
284+ # endif @
285+ #else @
286+ GDO_MAKE_FUNCTION (%%return %%, %%type %%,@
287+ %%func_symbol %%, (%%args %%),@
288+ %%notype_args %%)@
289+ #endif //!GDO_HAS_VA_ARGS_%%func_symbol%%@
290+
291+
292+ #undef GDO_WRAP_DECL
293+ #undef GDO_WRAP
294+ #undef GDO_WRAP_CHECK
295+ #undef GDO_MAKE_FUNCTION
296+ #undef GDO_MAKE_VA_ARG_FUNCTION
297+
298+ #endif //GDO_WRAP_FUNCTIONS ...
299+ /***************************** end of wrap code ******************************/
300+ %PARAM_SKIP_END %
301+
302+
303+ /**
304+ * Set function name alias prefix.
305+ */
306+ #if defined(GDO_WRAP_FUNCTIONS ) || defined(GDO_ENABLE_AUTOLOAD )
307+ # define GDO_FUNC_ALIAS (x ) GDO_WRAP_##x
308+ #else
309+ # define GDO_FUNC_ALIAS (x ) GDO_ALIAS_##x
310+ #endif
311+
210312
211313/**
212- * Aliases to raw pointers
314+ * Disable aliasing if we saved into separate files and the
315+ * header file was included from the body file.
213316 */
214- #if !defined(GDO_WRAP_FUNCTIONS ) && !defined(GDO_ENABLE_AUTOLOAD )
215- #define %%func_symbol_pad %% GDO_ALIAS_%%func_symbol%%
317+ #if defined(GDO_SEPARATE ) && \
318+ !defined(GDO_INCLUDED_IN_BODY ) && \
319+ !defined(GDO_DISABLE_ALIASING )
320+
321+ /* aliases to raw function pointers */
322+ #if !defined(GDO_WRAP_IS_VISIBLE )
323+ # define %%func_symbol_pad %% GDO_FUNC_ALIAS(%%func_symbol%%)
216324#endif
325+
326+ /* aliases to raw object pointers */
217327#define %%obj_symbol_pad %% GDO_ALIAS_%%obj_symbol%%
218328
219329#endif //GDO_SEPARATE ...
0 commit comments