Pristine Ack-5.5
[Ack-5.5.git] / modules / src / malloc / impl.h
1 /* $Id: impl.h,v 1.11 1994/06/24 11:17:49 ceriel Exp $ */
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
10 #define MIN_SIZE        (1<<LOG_MIN_SIZE)
11 #define MAX_FLIST       (LOG_MAX_SIZE - LOG_MIN_SIZE)
12 #if ALIGNMENT != 4 && ALIGNMENT != 8 && ALIGNMENT != 16
13 ALIGNMENT must be 4, 8, or 16
14 #endif
15 #if MIN_SIZE % ALIGNMENT
16 ALIGNMENT must be a dividor of MIN_SIZE
17 #endif
18 #if ALIGNMENT == 4
19 #define LOG_ALIGNMENT 2
20 #endif
21 #if ALIGNMENT == 8
22 #define LOG_ALIGNMENT 3
23 #endif
24 #if ALIGNMENT == 16
25 #define LOG_ALIGNMENT 4
26 #endif
27 #define align(n)        (((n) + (ALIGNMENT - 1)) & ~(ALIGNMENT - 1))
28
29 union _inf {
30         union _inf *ptr;
31         size_type ui;
32 };
33
34 typedef union _inf mallink;
35 #define MAL_NULL        ((mallink *)0)
36
37 /*      Access macros; only these macros know where to find values.
38         They are also lvalues.
39 */
40 #ifndef NON_STANDARD
41 #define OFF_SET 0
42 #else   /* def NON_STANDARD */
43 #define OFF_SET 2
44 #endif  /* NON_STANDARD */
45
46 #define _log_prev_of(ml)        ((ml)[-1+OFF_SET]).ptr
47 #define _log_next_of(ml)        ((ml)[-2+OFF_SET]).ptr
48 #define _phys_prev_of(ml)       ((ml)[-3+OFF_SET]).ptr
49 #define _this_size_of(ml)       ((ml)[-4+OFF_SET]).ui
50 #ifndef CHECK
51 #define N_WORDS                 4
52 #else   /* ifdef        CHECK */
53 #define _checksum_of(ml)        ((ml)[-5+OFF_SET]).ui
54 #define _print_of(ml)           ((ml)[-6+OFF_SET]).ui
55 #define _mark_of(ml)            ((ml)[-7+OFF_SET]).ui
56 #define N_WORDS                 7
57 #endif  /* CHECK */
58
59 #define mallink_size()          (unsigned int) \
60         align((N_WORDS - OFF_SET) * sizeof (mallink))
61
62 #ifdef  CHECK
63 #define set_mark(ml,e)          (_mark_of(ml) = (e))
64 #define mark_of(ml)             (_mark_of(ml))
65
66 #define set_checksum(ml,e)      (_checksum_of(ml) = (e))
67 #define checksum_of(ml)         (_checksum_of(ml))
68 #endif  /* CHECK */
69
70 #define new_mallink(ml)         ( _log_prev_of(ml) = 0, \
71                                   _log_next_of(ml) = 0, \
72                                   _phys_prev_of(ml) = 0, \
73                                   _this_size_of(ml) = 0 )
74
75 #define block_of_mallink(ml)    ((char *)ml)
76 #define mallink_of_block(addr)  ((mallink *)addr)
77
78 #define public  extern
79 #define publicdata      extern
80 #ifndef EXTERN
81 #define private static
82 #define privatedata     static
83 #else   /* def  EXTERN */
84 #define private extern
85 #define privatedata
86 #endif  /* EXTERN */
87
88 #ifdef  ASSERT
89 public m_assert();
90 #define assert(b)               (!(b) ? m_assert(__FILE__, __LINE__) : 0)
91 #else   /* ndef ASSERT */
92 #define assert(b)               0
93 #endif  /* ASSERT */