Pristine Ack-5.5
[Ack-5.5.git] / lang / cem / libcc.ansi / stdlib / malloc / impl.h
1 /* $Id: impl.h,v 1.3 1994/06/24 11:55:21 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 #error ALIGNMENT must be 4, 8 or 16
14 #elif ALIGNMENT % _EM_LSIZE
15 /* since calloc() does it's initialization in longs */
16 #error ALIGNMENT must be a multiple of the long size
17 #endif
18 #define align(n)        (((n) + (ALIGNMENT - 1)) & ~(ALIGNMENT - 1))
19
20 union _inf {
21         union _inf *ptr;
22         size_type ui;
23 };
24
25 typedef union _inf mallink;
26 #define MAL_NULL        ((mallink *)0)
27
28 /*      Access macros; only these macros know where to find values.
29         They are also lvalues.
30 */
31 #ifndef NON_STANDARD
32 #define OFF_SET 0
33 #else   /* def NON_STANDARD */
34 #define OFF_SET 2
35 #endif  /* NON_STANDARD */
36
37 #define _log_prev_of(ml)        ((ml)[-1+OFF_SET]).ptr
38 #define _log_next_of(ml)        ((ml)[-2+OFF_SET]).ptr
39 #define _phys_prev_of(ml)       ((ml)[-3+OFF_SET]).ptr
40 #define _this_size_of(ml)       ((ml)[-4+OFF_SET]).ui
41 #ifndef CHECK
42 #define N_WORDS                 4
43 #else   /* ifdef        CHECK */
44 #define _checksum_of(ml)        ((ml)[-5+OFF_SET]).ui
45 #define _print_of(ml)           ((ml)[-6+OFF_SET]).ui
46 #define _mark_of(ml)            ((ml)[-7+OFF_SET]).ui
47 #define N_WORDS                 7
48 #endif  /* CHECK */
49
50 #define mallink_size()          (size_t) \
51         align((N_WORDS - OFF_SET) * sizeof (mallink))
52
53 #ifdef  CHECK
54 #define set_mark(ml,e)          (_mark_of(ml) = (e))
55 #define mark_of(ml)             (_mark_of(ml))
56
57 #define set_checksum(ml,e)      (_checksum_of(ml) = (e))
58 #define checksum_of(ml)         (_checksum_of(ml))
59 #endif  /* CHECK */
60
61 #define new_mallink(ml)         ( _log_prev_of(ml) = 0, \
62                                   _log_next_of(ml) = 0, \
63                                   _phys_prev_of(ml) = 0, \
64                                   _this_size_of(ml) = 0 )
65
66 #define block_of_mallink(ml)    ((void *)ml)
67 #define mallink_of_block(addr)  ((mallink *)addr)
68
69 #define public  extern
70 #define publicdata      extern
71 #ifndef EXTERN
72 #define private static
73 #define privatedata     static
74 #else   /* def  EXTERN */
75 #define private extern
76 #define privatedata
77 #endif  /* EXTERN */
78
79 #ifdef  ASSERT
80 public m_assert(const char *fn, int ln);
81 #define assert(b)               (!(b) ? m_assert(__FILE__, __LINE__) : 0)
82 #else   /* ndef ASSERT */
83 #define assert(b)               0
84 #endif  /* ASSERT */