impl.h 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  1. /* $Id$ */
  2. /*
  3. * (c) copyright 1987 by the Vrije Universiteit, Amsterdam, The Netherlands.
  4. * See the copyright notice in the ACK home directory, in the file "Copyright".
  5. */
  6. /* This file essentially describes how the mallink info block
  7. is implemented.
  8. */
  9. #define MIN_SIZE (1<<LOG_MIN_SIZE)
  10. #define MAX_FLIST (LOG_MAX_SIZE - LOG_MIN_SIZE)
  11. #if ALIGNMENT != 4 && ALIGNMENT != 8 && ALIGNMENT != 16
  12. #error ALIGNMENT must be 4, 8 or 16
  13. #elif ALIGNMENT % _EM_LSIZE
  14. /* since calloc() does it's initialization in longs */
  15. #error ALIGNMENT must be a multiple of the long size
  16. #endif
  17. #define align(n) (((n) + (ALIGNMENT - 1)) & ~(ALIGNMENT - 1))
  18. union _inf {
  19. union _inf *ptr;
  20. size_type ui;
  21. };
  22. typedef union _inf mallink;
  23. #define MAL_NULL ((mallink *)0)
  24. /* Access macros; only these macros know where to find values.
  25. They are also lvalues.
  26. */
  27. #ifndef NON_STANDARD
  28. #define OFF_SET 0
  29. #else /* def NON_STANDARD */
  30. #define OFF_SET 2
  31. #endif /* NON_STANDARD */
  32. #define _log_prev_of(ml) ((ml)[-1+OFF_SET]).ptr
  33. #define _log_next_of(ml) ((ml)[-2+OFF_SET]).ptr
  34. #define _phys_prev_of(ml) ((ml)[-3+OFF_SET]).ptr
  35. #define _this_size_of(ml) ((ml)[-4+OFF_SET]).ui
  36. #ifndef CHECK
  37. #define N_WORDS 4
  38. #else /* ifdef CHECK */
  39. #define _checksum_of(ml) ((ml)[-5+OFF_SET]).ui
  40. #define _print_of(ml) ((ml)[-6+OFF_SET]).ui
  41. #define _mark_of(ml) ((ml)[-7+OFF_SET]).ui
  42. #define N_WORDS 7
  43. #endif /* CHECK */
  44. #define mallink_size() (size_t) \
  45. align((N_WORDS - OFF_SET) * sizeof (mallink))
  46. #ifdef CHECK
  47. #define set_mark(ml,e) (_mark_of(ml) = (e))
  48. #define mark_of(ml) (_mark_of(ml))
  49. #define set_checksum(ml,e) (_checksum_of(ml) = (e))
  50. #define checksum_of(ml) (_checksum_of(ml))
  51. #endif /* CHECK */
  52. #define new_mallink(ml) ( _log_prev_of(ml) = 0, \
  53. _log_next_of(ml) = 0, \
  54. _phys_prev_of(ml) = 0, \
  55. _this_size_of(ml) = 0 )
  56. #define block_of_mallink(ml) ((void *)ml)
  57. #define mallink_of_block(addr) ((mallink *)addr)
  58. #define public extern
  59. #define publicdata extern
  60. #ifndef EXTERN
  61. #define private static
  62. #define privatedata static
  63. #else /* def EXTERN */
  64. #define private extern
  65. #define privatedata
  66. #endif /* EXTERN */
  67. #ifdef ASSERT
  68. public m_assert(const char *fn, int ln);
  69. #define assert(b) (!(b) ? m_assert(__FILE__, __LINE__) : 0)
  70. #else /* ndef ASSERT */
  71. #define assert(b) 0
  72. #endif /* ASSERT */