MALOC  0.1
maloc_base.h
Go to the documentation of this file.
1 
44 #ifndef _MALOC_BASE_H_
45 #define _MALOC_BASE_H_
46 
47 /*
48  * ***************************************************************************
49  * Proper ISO-C header setup (with a slight "signals" tweek for setjmp)
50  * ***************************************************************************
51  */
52 
53 /* Get the fifteen ISO-C headers (CAREFUL: POSIX/BSD flags delicate...) */
54 
55 /* Some compilers don't set this for you; GCC does with -ansi */
56 /*
57  * if !defined(__STDC__)
58  * define __STDC__ 1
59  * endif
60  */
61 
62 /* Old Sparc compilers need this to give you prototypes */
63 /*
64  * if !defined(__USE_FIXED_PROTOTYPES__)
65  * define __USE_FIXED_PROTOTYPES__
66  * endif
67  */
68 
69 /* Include 14 of the 15 ISO-C headers (postponing setjmp.h) */
70 #include <assert.h>
71 #include <ctype.h>
72 #include <errno.h>
73 #include <float.h>
74 #include <limits.h>
75 #include <locale.h>
76 #include <math.h>
77 #include <signal.h>
78 #include <stdarg.h>
79 #include <stddef.h>
80 #include <stdio.h>
81 #include <stdlib.h>
82 #include <string.h>
83 #include <time.h>
84 
88 #if !defined(CLOCKS_PER_SEC)
89 # define CLOCKS_PER_SEC 60
90 #endif
91 
115 #define __FAVOR_BSD
116 
140 #define _BSD_SIGNALS
141 
142 /* Now finally include the 15th header, setjmp.h */
143 #include <setjmp.h>
144 
145 #if defined(__cplusplus)
146 
147 # define VCXX
148 
149 # define extern "C"
150 #else
151 
152 # define VCC
153 
154 # define extern
155 #endif
156 
157 /*
158  * ***************************************************************************
159  * Private and Public type modifier simulation
160  * ***************************************************************************
161  */
162 
163 #define VPRIVATE static
164 #define VPUBLIC /*empty*/
168 #define VWARN1(file, lineno) (fprintf(stderr,"VWARN: ASSERTION FAILURE! filename %s, line %u\n", (file), (lineno)), 0)
169 
170 #define VASSERT1(file, lineno) (fprintf(stderr,"VASSERT: ASSERTION FAILURE! filename %s, line %u\n", (file), (lineno)), exit(1), 0)
171 
172 #define VASSERT2(file, lineno) (fprintf(stderr,"VASSERT: ASSERTION FAILURE! filename %s, line %u\n", (file), (lineno)), abort(), 0)
173 
174 #define VASSERT3(file, lineno, ex) (fprintf(stderr,"VASSERT: ASSERTION FAILURE! filename %s, line %u, (%s)\n", (file), (lineno), (#ex)), abort(), 0)
175 
177 #define VWARN(ex) ((void) ((ex) ? 0 : VWARN1(__FILE__, __LINE__)))
178 
179 #define VASSERT(ex) ((void) ((ex) ? 0 : VASSERT3(__FILE__, __LINE__, ex)))
180 
181 
183 #define VJMPERR0(x) if (!(x)) goto VERROR0
184 
185 #define VJMPERR1(x) if (!(x)) goto VERROR1
186 
187 #define VJMPERR2(x) if (!(x)) goto VERROR2
188 
189 #define VJMPERR3(x) if (!(x)) goto VERROR3
190 
191 #define VJMPERR4(x) if (!(x)) goto VERROR4
192 
193 #define VJMPERR5(x) if (!(x)) goto VERROR5
194 
195 #define VJMPERR6(x) if (!(x)) goto VERROR6
196 
197 #define VJMPERR7(x) if (!(x)) goto VERROR7
198 
199 #define VJMPERR8(x) if (!(x)) goto VERROR8
200 
201 #define VJMPERR9(x) if (!(x)) goto VERROR9
202 
203 /*
204  * ***************************************************************************
205  * Global constants
206  * ***************************************************************************
207  */
208 
210 #define VPI 3.14159265358979323846
211 
212 #define VLARGE 1.0e+9
213 
214 #define VSMALL 1.0e-9
215 
216 #define VVLARGE 1.0e+15
217 
218 #define VVSMALL 1.0e-15
219 
220 #define VPRTKEY 10000
221 
223 #define VPTRSIZE 4
224 
225 #define VMAX_ARGNUM 50
226 
227 #define VMAX_ARGLEN 1024
228 
229 #define VMAX_BUFSIZE 8192
230 
231 /*
232  * #define VMAX_OBJECTS 16777216 //(1<<24) = 2^24
233  * #define VBLOCK_POWER 12
234  */
235 
237 #define VMAX_OBJECTS 1073741824 /* (1<<31) = 2^31 */
238 
239 #define VBLOCK_POWER 14
240 
242 #define VNULL NULL
243 
244 #define VINULL -1
245 
246 #define VTRUE 1
247 
248 #define VFALSE 0
249 
250 #define VSTDMODE 0600
251 
253 #define VNULL_STRING "\0"
254 
255 #define VBLANK_STRING " "
256 
257 #define VNEWLINE_STRING "\n"
258 
260 #define VNULL_SYMBOL '\0'
261 
262 #define VBLANK_SYMBOL ' '
263 
264 #define VNEWLINE_SYMBOL '\n'
265 
266 #define VRDIN_SYMBOL '<'
267 
268 #define VRDOUT_SYMBOL '>'
269 
270 #define VPIPE_SYMBOL '|'
271 
272 #define VDELIM_SET " ><|&"
273 
274 
276 #define VABS(x) ((x) >= 0 ? (x) : -(x))
277 
278 #define VMIN2(x,y) ((x) <= (y) ? (x) : (y))
279 
280 #define VMAX2(x,y) ((x) >= (y) ? (x) : (y))
281 
282 #define VSIGN(x,y) ((y) >= 0 ? (VABS(x)) : (-VABS(x)))
283 
285 #define VODD(x) ((x)&1)
286 
287 #define VEVEN(x) (!((x)&1))
288 
289 #define VZERO(x) ((x)==0)
290 
291 #define VPOS(x) ((x)>0)
292 
293 #define VNEG(x) ((x)<0)
294 
295 #define VEVENP(x) (VEVEN(x) && VPOS(x))
296 
297 #define VEVENN(x) (VEVEN(x) && VNEG(x))
298 
300 #define VSQRT(x) (sqrt(x))
301 
302 #define VSQR(x) ((x)*(x))
303 
304 #define VSIN(x) (sin(x))
305 
306 #define VCOS(x) (cos(x))
307 
308 #define VTAN(x) (tan(x))
309 
310 #define VASIN(x) (asin(x))
311 
312 #define VACOS(x) (acos(x))
313 
314 #define VATAN(x) (atan(x))
315 
316 #define VSINH(x) (sinh(x))
317 
318 #define VCOSH(x) (cosh(x))
319 
320 #define VTANH(x) (tanh(x))
321 
322 #define VEXP(x) (exp(x))
323 
324 #define VLOG(x) (log(x))
325 
326 #define VPOW(x,y) (pow(x,y))
327 
328 #define VRINT(x) ((int)(floor((x)+0.5)))
329 
331 #define VRAND (rand())
332 
333 #define VRANDMAX (RAND_MAX)
334 
338 #if 1
339 # define VINLINE_MALOC
340 #endif
341 
342 #endif /* _MALOC_BASE_H_ */
343