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)
147# define VCXX
149# define extern "C"
150#else
152# define VCC
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)
170#define VASSERT1(file, lineno) (fprintf(stderr,"VASSERT: ASSERTION FAILURE! filename %s, line %u\n", (file), (lineno)), exit(1), 0)
172#define VASSERT2(file, lineno) (fprintf(stderr,"VASSERT: ASSERTION FAILURE! filename %s, line %u\n", (file), (lineno)), abort(), 0)
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__)))
179#define VASSERT(ex) ((void) ((ex) ? 0 : VASSERT3(__FILE__, __LINE__, ex)))
180
181
183#define VJMPERR0(x) if (!(x)) goto VERROR0
185#define VJMPERR1(x) if (!(x)) goto VERROR1
187#define VJMPERR2(x) if (!(x)) goto VERROR2
189#define VJMPERR3(x) if (!(x)) goto VERROR3
191#define VJMPERR4(x) if (!(x)) goto VERROR4
193#define VJMPERR5(x) if (!(x)) goto VERROR5
195#define VJMPERR6(x) if (!(x)) goto VERROR6
197#define VJMPERR7(x) if (!(x)) goto VERROR7
199#define VJMPERR8(x) if (!(x)) goto VERROR8
201#define VJMPERR9(x) if (!(x)) goto VERROR9
202
203/*
204 * ***************************************************************************
205 * Global constants
206 * ***************************************************************************
207 */
208
210#define VPI 3.14159265358979323846
212#define VLARGE 1.0e+9
214#define VSMALL 1.0e-9
216#define VVLARGE 1.0e+15
218#define VVSMALL 1.0e-15
220#define VPRTKEY 10000
221
223#define VPTRSIZE 4
225#define VMAX_ARGNUM 50
227#define VMAX_ARGLEN 1024
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 */
239#define VBLOCK_POWER 14
240
242#define VNULL NULL
244#define VINULL -1
246#define VTRUE 1
248#define VFALSE 0
250#define VSTDMODE 0600
251
253#define VNULL_STRING "\0"
255#define VBLANK_STRING " "
257#define VNEWLINE_STRING "\n"
258
260#define VNULL_SYMBOL '\0'
262#define VBLANK_SYMBOL ' '
264#define VNEWLINE_SYMBOL '\n'
266#define VRDIN_SYMBOL '<'
268#define VRDOUT_SYMBOL '>'
270#define VPIPE_SYMBOL '|'
272#define VDELIM_SET " ><|&"
273
274
276#define VABS(x) ((x) >= 0 ? (x) : -(x))
278#define VMIN2(x,y) ((x) <= (y) ? (x) : (y))
280#define VMAX2(x,y) ((x) >= (y) ? (x) : (y))
282#define VSIGN(x,y) ((y) >= 0 ? (VABS(x)) : (-VABS(x)))
283
285#define VODD(x) ((x)&1)
287#define VEVEN(x) (!((x)&1))
289#define VZERO(x) ((x)==0)
291#define VPOS(x) ((x)>0)
293#define VNEG(x) ((x)<0)
295#define VEVENP(x) (VEVEN(x) && VPOS(x))
297#define VEVENN(x) (VEVEN(x) && VNEG(x))
298
300#define VSQRT(x) (sqrt(x))
302#define VSQR(x) ((x)*(x))
304#define VSIN(x) (sin(x))
306#define VCOS(x) (cos(x))
308#define VTAN(x) (tan(x))
310#define VASIN(x) (asin(x))
312#define VACOS(x) (acos(x))
314#define VATAN(x) (atan(x))
316#define VSINH(x) (sinh(x))
318#define VCOSH(x) (cosh(x))
320#define VTANH(x) (tanh(x))
322#define VEXP(x) (exp(x))
324#define VLOG(x) (log(x))
326#define VPOW(x,y) (pow(x,y))
328#define VRINT(x) ((int)(floor((x)+0.5)))
329
331#define VRAND (rand())
333#define VRANDMAX (RAND_MAX)
334
338#if 1
339# define VINLINE_MALOC
340#endif
341
342#endif /* _MALOC_BASE_H_ */
343