common.c 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. /* Common code for wrappers.
  2. Copyright (C) 2008 Free Software Foundation, Inc.
  3. Written by FlÃvio Cruz <flaviocruz@gmail.com>
  4. This program is free software; you can redistribute it and/or
  5. modify it under the terms of the GNU General Public License as
  6. published by the Free Software Foundation; either version 2, or (at
  7. your option) any later version.
  8. This program is distributed in the hope that it will be useful, but
  9. WITHOUT ANY WARRANTY; without even the implied warranty of
  10. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  11. General Public License for more details.
  12. You should have received a copy of the GNU General Public License
  13. along with this program; if not, write to the Free Software
  14. Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */
  15. inline static void
  16. _set_routine (const unsigned what, void *fun)
  17. {
  18. assert (what < _NUMBER_OF_ROUTINES);
  19. if (routines[what] != NULL)
  20. {
  21. fprintf (stderr, "Warning: redefining routine %s\n",
  22. routine_to_str (what));
  23. }
  24. routines[what] = fun;
  25. }
  26. inline static void
  27. _get_module_info (void)
  28. {
  29. int i;
  30. for (i = 0; i != _NUMBER_OF_ROUTINES; ++i)
  31. {
  32. if (routines[i] != NULL)
  33. {
  34. printf ("Routine #%d (%s): set to address %x\n", i,
  35. routine_to_str (i), (vm_size_t) routines[i]);
  36. }
  37. }
  38. }
  39. #define COMMON_FUNCTIONS(module) \
  40. void get_ ## module ## _info(void) { \
  41. _get_module_info(); \
  42. } \
  43. void set_ ## module ## _routine(const unsigned what, void *fun) { \
  44. _set_routine(what, fun); \
  45. }