Blame include/set-hooks.h

Packit 6c4009
/* Macros for using symbol sets for running lists of functions.
Packit 6c4009
   Copyright (C) 1994-2018 Free Software Foundation, Inc.
Packit 6c4009
   This file is part of the GNU C Library.
Packit 6c4009
Packit 6c4009
   The GNU C Library is free software; you can redistribute it and/or
Packit 6c4009
   modify it under the terms of the GNU Lesser General Public
Packit 6c4009
   License as published by the Free Software Foundation; either
Packit 6c4009
   version 2.1 of the License, or (at your option) any later version.
Packit 6c4009
Packit 6c4009
   The GNU C Library is distributed in the hope that it will be useful,
Packit 6c4009
   but WITHOUT ANY WARRANTY; without even the implied warranty of
Packit 6c4009
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
Packit 6c4009
   Lesser General Public License for more details.
Packit 6c4009
Packit 6c4009
   You should have received a copy of the GNU Lesser General Public
Packit 6c4009
   License along with the GNU C Library; if not, see
Packit 6c4009
   <http://www.gnu.org/licenses/>.  */
Packit 6c4009
Packit 6c4009
#ifndef _SET_HOOKS_H
Packit 6c4009
#define _SET_HOOKS_H 1
Packit 6c4009
Packit 6c4009
#define __need_size_t
Packit 6c4009
#include <stddef.h>
Packit 6c4009
#include <sys/cdefs.h>
Packit 6c4009
#include <libc-symbols.h>
Packit 6c4009
Packit 6c4009
#ifdef symbol_set_define
Packit 6c4009
/* Define a hook variable called NAME.  Functions put on this hook take
Packit 6c4009
   arguments described by PROTO.  Use `text_set_element (NAME, FUNCTION)'
Packit 6c4009
   from include/libc-symbols.h to add a function to the hook.  */
Packit 6c4009
Packit 6c4009
# define DEFINE_HOOK(NAME, PROTO)		\
Packit 6c4009
  typedef void __##NAME##_hook_function_t PROTO; \
Packit 6c4009
  symbol_set_define (NAME)
Packit 6c4009
Packit 6c4009
# define DECLARE_HOOK(NAME, PROTO)		\
Packit 6c4009
  typedef void __##NAME##_hook_function_t PROTO;\
Packit 6c4009
  symbol_set_declare (NAME)
Packit 6c4009
Packit 6c4009
/* Run all the functions hooked on the set called NAME.
Packit 6c4009
   Each function is called like this: `function ARGS'.  */
Packit 6c4009
Packit 6c4009
# define RUN_HOOK(NAME, ARGS)						      \
Packit 6c4009
do {									      \
Packit 6c4009
  void *const *ptr;						      \
Packit 6c4009
  for (ptr = (void *const *) symbol_set_first_element (NAME);		      \
Packit 6c4009
       ! symbol_set_end_p (NAME, ptr); ++ptr)				      \
Packit 6c4009
    (*(__##NAME##_hook_function_t *) *ptr) ARGS;			      \
Packit 6c4009
} while (0)
Packit 6c4009
Packit 6c4009
/* Define a hook variable with NAME and PROTO, and a function called RUNNER
Packit 6c4009
   which calls each function on the hook in turn, with ARGS.  */
Packit 6c4009
Packit 6c4009
# define DEFINE_HOOK_RUNNER(name, runner, proto, args) \
Packit 6c4009
DEFINE_HOOK (name, proto); \
Packit 6c4009
extern void runner proto; void runner proto { RUN_HOOK (name, args); }
Packit 6c4009
Packit 6c4009
#else
Packit 6c4009
Packit 6c4009
/* The system does not provide necessary support for this.  */
Packit 6c4009
# define DEFINE_HOOK(NAME, PROTO)
Packit 6c4009
Packit 6c4009
# define DECLARE_HOOK(NAME, PROTO)
Packit 6c4009
Packit 6c4009
# define RUN_HOOK(NAME, ARGS)
Packit 6c4009
Packit 6c4009
# define DEFINE_HOOK_RUNNER(name, runner, proto, args)
Packit 6c4009
Packit 6c4009
#endif
Packit 6c4009
Packit 6c4009
#endif /* set-hooks.h */