xf.li | bdd93d5 | 2023-05-12 07:10:14 -0700 | [diff] [blame] | 1 | /* Macros for using symbol sets for running lists of functions. |
| 2 | Copyright (C) 1994-2016 Free Software Foundation, Inc. |
| 3 | This file is part of the GNU C Library. |
| 4 | |
| 5 | The GNU C Library is free software; you can redistribute it and/or |
| 6 | modify it under the terms of the GNU Lesser General Public |
| 7 | License as published by the Free Software Foundation; either |
| 8 | version 2.1 of the License, or (at your option) any later version. |
| 9 | |
| 10 | The GNU C Library is distributed in the hope that it will be useful, |
| 11 | but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
| 13 | Lesser General Public License for more details. |
| 14 | |
| 15 | You should have received a copy of the GNU Lesser General Public |
| 16 | License along with the GNU C Library; if not, see |
| 17 | <http://www.gnu.org/licenses/>. */ |
| 18 | |
| 19 | #ifndef _SET_HOOKS_H |
| 20 | #define _SET_HOOKS_H 1 |
| 21 | |
| 22 | #define __need_size_t |
| 23 | #include <stddef.h> |
| 24 | #include <sys/cdefs.h> |
| 25 | |
| 26 | #ifdef symbol_set_define |
| 27 | /* Define a hook variable called NAME. Functions put on this hook take |
| 28 | arguments described by PROTO. Use `text_set_element (NAME, FUNCTION)' |
| 29 | from gnu-stabs.h to add a function to the hook. */ |
| 30 | |
| 31 | # define DEFINE_HOOK(NAME, PROTO) \ |
| 32 | typedef void __##NAME##_hook_function_t PROTO; \ |
| 33 | symbol_set_define (NAME) |
| 34 | |
| 35 | # define DECLARE_HOOK(NAME, PROTO) \ |
| 36 | typedef void __##NAME##_hook_function_t PROTO;\ |
| 37 | symbol_set_declare (NAME) |
| 38 | |
| 39 | /* Run all the functions hooked on the set called NAME. |
| 40 | Each function is called like this: `function ARGS'. */ |
| 41 | |
| 42 | # define RUN_HOOK(NAME, ARGS) \ |
| 43 | do { \ |
| 44 | void *const *ptr; \ |
| 45 | for (ptr = (void *const *) symbol_set_first_element (NAME); \ |
| 46 | ! symbol_set_end_p (NAME, ptr); ++ptr) \ |
| 47 | (*(__##NAME##_hook_function_t *) *ptr) ARGS; \ |
| 48 | } while (0) |
| 49 | |
| 50 | /* Define a hook variable with NAME and PROTO, and a function called RUNNER |
| 51 | which calls each function on the hook in turn, with ARGS. */ |
| 52 | |
| 53 | # define DEFINE_HOOK_RUNNER(name, runner, proto, args) \ |
| 54 | DEFINE_HOOK (name, proto); \ |
| 55 | extern void runner proto; void runner proto { RUN_HOOK (name, args); } |
| 56 | |
| 57 | #else |
| 58 | |
| 59 | /* The system does not provide necessary support for this. */ |
| 60 | # define DEFINE_HOOK(NAME, PROTO) |
| 61 | |
| 62 | # define DECLARE_HOOK(NAME, PROTO) |
| 63 | |
| 64 | # define RUN_HOOK(NAME, ARGS) |
| 65 | |
| 66 | # define DEFINE_HOOK_RUNNER(name, runner, proto, args) |
| 67 | |
| 68 | #endif |
| 69 | |
| 70 | #endif /* set-hooks.h */ |