0875b58f |
1 | /* -*-c-*- |
2 | * |
8c6d948b |
3 | * $Id: sub.h,v 1.4 1999/05/13 22:48:55 mdw Exp $ |
0875b58f |
4 | * |
5 | * Allocation of known-size blocks |
6 | * |
7 | * (c) 1998 Straylight/Edgeware |
8 | */ |
9 | |
c846879c |
10 | /*----- Licensing notice --------------------------------------------------* |
0875b58f |
11 | * |
12 | * This file is part of the mLib utilities library. |
13 | * |
14 | * mLib is free software; you can redistribute it and/or modify |
c846879c |
15 | * it under the terms of the GNU Library General Public License as |
16 | * published by the Free Software Foundation; either version 2 of the |
17 | * License, or (at your option) any later version. |
18 | * |
0875b58f |
19 | * mLib is distributed in the hope that it will be useful, |
20 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
21 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
c846879c |
22 | * GNU Library General Public License for more details. |
23 | * |
24 | * You should have received a copy of the GNU Library General Public |
0bd98442 |
25 | * License along with mLib; if not, write to the Free |
26 | * Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, |
27 | * MA 02111-1307, USA. |
0875b58f |
28 | */ |
29 | |
30 | /*----- Revision history --------------------------------------------------* |
31 | * |
32 | * $Log: sub.h,v $ |
8c6d948b |
33 | * Revision 1.4 1999/05/13 22:48:55 mdw |
34 | * Change `-ise' to `-ize' throughout. |
35 | * |
0bd98442 |
36 | * Revision 1.3 1999/05/06 19:51:35 mdw |
37 | * Reformatted the LGPL notice a little bit. |
38 | * |
c846879c |
39 | * Revision 1.2 1999/05/05 18:50:31 mdw |
40 | * Change licensing conditions to LGPL. |
41 | * |
42 | * Revision 1.1.1.1 1998/06/17 23:44:42 mdw |
43 | * Initial version of mLib |
0875b58f |
44 | * |
45 | */ |
46 | |
47 | #ifndef SUB_H |
48 | #define SUB_H |
49 | |
50 | #ifdef __cplusplus |
51 | extern "C" { |
52 | #endif |
53 | |
54 | /*----- Required header files ---------------------------------------------*/ |
55 | |
56 | #include <stdlib.h> |
57 | |
58 | #ifndef ALLOC_H |
59 | # include "alloc.h" |
60 | #endif |
61 | |
62 | /*----- Functions provided ------------------------------------------------*/ |
63 | |
64 | /* --- @sub_alloc@ --- * |
65 | * |
66 | * Arguments: @size_t s@ = size of chunk wanted |
67 | * |
68 | * Returns: Pointer to a block at least as large as the one wanted. |
69 | * |
70 | * Use: Allocates a small block of memory. If there is no more |
71 | * memory left, the exception @EXC_NOMEM@ is raised. |
72 | */ |
73 | |
74 | #ifdef TRACK_ENABLE |
75 | # define sub_alloc(s) xmalloc(s) |
76 | #else |
77 | void *sub_alloc(size_t s); |
78 | #endif |
79 | |
80 | /* --- @sub_free@ --- * |
81 | * |
82 | * Arguments: @void *p@ = address of block to free |
83 | * @size_t s@ = size of block |
84 | * |
85 | * Returns: --- |
86 | * |
87 | * Use: Frees a block allocated by @sub_alloc@. |
88 | */ |
89 | |
90 | #ifdef TRACK_ENABLE |
91 | # define sub_free(p, s) free(p) |
92 | #else |
93 | void sub_free(void *p, size_t s); |
94 | #endif |
95 | |
96 | /* --- @CREATE@ --- * |
97 | * |
98 | * Arguments: @type@ = type of object required; must be passable to |
99 | * @sizeof@ |
100 | * |
101 | * Returns: Pointer to a block sufficiently big to hold an object of the |
102 | * named type. |
103 | * |
104 | * Use: Allocates a block of the required type. |
105 | */ |
106 | |
107 | #define CREATE(type) sub_alloc(sizeof(type)) |
108 | |
109 | /* --- @DESTROY@ --- * |
110 | * |
111 | * Arguments: @void *p@ = pointer to an object |
112 | * |
113 | * Returns: --- |
114 | * |
115 | * Use: Frees the thing pointed to by @p@. |
116 | */ |
117 | |
118 | #define DESTROY(p) sub_free(p, sizeof(*p)) |
119 | |
120 | /* --- @sub_init@ --- * |
121 | * |
122 | * Arguments: --- |
123 | * |
124 | * Returns: --- |
125 | * |
8c6d948b |
126 | * Use: Initializes the magic allocator. |
0875b58f |
127 | */ |
128 | |
129 | void sub_init(void); |
130 | |
131 | /*----- That's all, folks -------------------------------------------------*/ |
132 | |
133 | #ifdef __cplusplus |
134 | } |
135 | #endif |
136 | |
137 | #endif |