DyLP
1.10.4
src
DylpStdLib
dylib_std.h
Go to the documentation of this file.
1
#ifndef _DYLIB_STD_H
2
#define _DYLIB_STD_H
3
4
/*
5
This file is part of the support library for the Dylp LP distribution.
6
7
Copyright (C) 2005 -- 2007 Lou Hafer
8
9
School of Computing Science
10
Simon Fraser University
11
Burnaby, B.C., V5A 1S6, Canada
12
lou@cs.sfu.ca
13
14
This code is licensed under the terms of the Eclipse Public License (EPL).
15
*/
16
17
/*
18
@(#)dylib_std.h 1.5 09/25/04
19
svn/cvs: $Id: dylib_std.h 407 2010-12-31 20:48:48Z lou $
20
*/
21
22
/*
23
This file contains common definitions.
24
25
First thing to do is haul in the Ansi C standard definitions. Takes care of
26
NULL plus a few more obscure definitions. Also haul in the standard library
27
declarations.
28
*/
29
30
#include <stddef.h>
31
#include <stdlib.h>
32
33
#include "
DylpConfig.h
"
34
35
/*
36
A utility definition which allows for easy suppression of unused variable
37
warnings from GCC. Useful when a variable is used only for assert()
38
statements, and for sccsid/cvsid strings.
39
*/
40
#ifndef UNUSED
41
# if defined(_GNU_SOURCE) || defined(__GNUC__)
42
# define UNUSED __attribute__((unused))
43
# else
44
# define UNUSED
45
# endif
46
#endif
47
48
/*
49
Memory copy functions --- memcpy, memset, and other less common ones.
50
*/
51
52
#include <string.h>
53
54
/*
55
We need a boolean type. Never could understand why C doesn't have this.
56
57
[Aug 10, 01] For compatibility with C++, TRUE and FALSE are defined to be
58
the corresponding C++ values. BOOL should be set in the compiler command
59
line to be the storage type (char/short/int/long) that matches the size of
60
a C++ "bool".
61
*/
62
63
#ifndef __cplusplus
64
#define FALSE 0
65
#define TRUE 1
66
# ifdef BOOL
67
typedef
BOOL
bool
;
68
# else
69
/*
70
You're in trouble. Normally a definition for BOOL is determined by the
71
configure script; apparently you're outside of whatever framework should
72
do this. If you're not worried about C++ compatibility, int is a good a
73
choice as anything. If you're concerned about C++ compatibility, write a
74
small C++ program that prints out sizeof(bool) and add the definition here.
75
*/
76
# warning The compile-time symbol BOOL is not defined (dylib_std.h)
77
typedef
int
bool
;
78
# endif
79
#endif
80
81
#ifdef __cplusplus
82
#ifndef FALSE
83
# define FALSE false
84
#endif
85
#ifndef TRUE
86
# define TRUE true
87
#endif
88
#endif
89
90
/*
91
flags is used to indicate a data type composed of one-bit flags. Manipulated
92
with the set of flag manipulation macros defined below.
93
*/
94
95
typedef
unsigned
int
flags
;
96
97
#define setflg(zz_flgs,zz_flg) ((zz_flgs) |= (zz_flg))
98
#define clrflg(zz_flgs,zz_flg) ((zz_flgs) &= ~(zz_flg))
99
#define comflg(zz_flgs,zz_flg) ((zz_flgs) ^= (zz_flg))
100
#define getflg(zz_flgs,zz_flg) ((zz_flgs)&(zz_flg))
101
#define flgon(zz_flgs,zz_flg) ((zz_flgs)&(zz_flg)?TRUE:FALSE)
102
#define flgoff(zz_flgs,zz_flg) ((zz_flgs)&(zz_flg)?FALSE:TRUE)
103
#define flgall(zz_flgs,zz_flg) ((((zz_flgs)&(zz_flg)) == (zz_flg))?TRUE:FALSE)
104
105
106
/*
107
lnk_struct is a general-purpose linked list structure.
108
109
Field Description
110
----- -----------
111
llnxt pointer to the next list element
112
llval pointer to the associated value
113
*/
114
115
typedef
struct
lnk_struct_tag
116
{
struct
lnk_struct_tag
*
llnxt
;
117
void
*
llval
; }
lnk_struct
;
118
119
#define lnk_in(qqlnk,qqval) ((qqlnk)->llval = (void *) (qqval))
120
#define lnk_out(qqlnk,qqtype) ((qqtype) (qqlnk)->llval)
121
122
123
/* Max and min macros */
124
125
#define minn(qa,qb) (((qa) > (qb))?(qb):(qa))
126
#define maxx(qa,qb) (((qa) > (qb))?(qa):(qb))
127
128
129
/*
130
Some macros to hide the memory allocation functions.
131
132
The serious debugging versions of these macros (MALLOC_DEBUG = 2) use
133
outfmt from the io library and assume the existence of a string, rtnnme
134
(typically the name of the current subroutine) that's used to identify the
135
origin of the message. There's enough information in the messages to track
136
the allocation and deallocation of blocks, should you not have access to an
137
interactive debugger with this capability.
138
139
The casual debugging versions (MALLOC_DEBUG = 1) only check for a return
140
value of 0 and print a message to stderr with the file and line number.
141
This at least tells you when your code has core dumped because it ran out
142
of space (as opposed to a bug you can actually fix).
143
*/
144
145
#if (MALLOC_DEBUG == 2)
146
147
#include "
dylib_io.h
"
148
149
void
*zz_ptr_zz ;
150
ioid
zz_chn_zz ;
151
152
#define MALLOC_DBG_INIT(chn) ( zz_chn_zz = chn )
153
154
#define MALLOC(zz_sze_zz) \
155
( zz_ptr_zz = (void *) malloc(zz_sze_zz), \
156
dyio_outfmt(zz_chn_zz,FALSE,":malloc: %d bytes at %#08x in %s.\n", \
157
zz_sze_zz,zz_ptr_zz,rtnnme), \
158
zz_ptr_zz )
159
160
#define CALLOC(zz_cnt_zz,zz_sze_zz) \
161
( zz_ptr_zz = (void *) calloc(zz_cnt_zz,zz_sze_zz), \
162
dyio_outfmt(zz_chn_zz,FALSE,":calloc: %d (%d*%d) bytes at %#08x in %s.\n", \
163
zz_cnt_zz*zz_sze_zz,zz_cnt_zz,zz_sze_zz,zz_ptr_zz,rtnnme), \
164
zz_ptr_zz )
165
166
#define REALLOC(zz_rptr_zz,zz_sze_zz) \
167
( zz_ptr_zz = (void *) realloc(zz_rptr_zz,zz_sze_zz), \
168
dyio_outfmt(zz_chn_zz,FALSE, \
169
":realloc: %#08x changed to %d bytes at %#08x in %s.\n", \
170
zz_rptr_zz,zz_sze_zz,zz_ptr_zz,rtnnme), \
171
zz_ptr_zz )
172
173
#define FREE(zz_fptr_zz) \
174
( dyio_outfmt(zz_chn_zz,FALSE,":free: %#08x in %s.\n",zz_fptr_zz,rtnnme), \
175
free((void *) zz_fptr_zz) )
176
177
#elif (MALLOC_DEBUG == 1)
178
179
#include <stdio.h>
180
void
*zz_ptr_zz ;
181
182
#define MALLOC(zz_sze_zz) \
183
( zz_ptr_zz = (void *) malloc(zz_sze_zz), \
184
(zz_ptr_zz != 0)?0:\
185
fprintf(stderr,":malloc: failed to get %d bytes at %s:%d.\n", \
186
zz_sze_zz,__FILE__,__LINE__), \
187
zz_ptr_zz )
188
189
#define CALLOC(zz_cnt_zz,zz_sze_zz) \
190
( zz_ptr_zz = (void *) calloc(zz_cnt_zz,zz_sze_zz), \
191
(zz_ptr_zz != 0)?0:\
192
fprintf(stderr,":calloc: failed to get %d bytes at %s:%d.\n", \
193
zz_sze_zz*zz_cnt_zz,__FILE__,__LINE__), \
194
zz_ptr_zz )
195
196
#define REALLOC(zz_rptr_zz,zz_sze_zz) \
197
( zz_ptr_zz = (void *) realloc(zz_rptr_zz,zz_sze_zz), \
198
(zz_ptr_zz != 0)?0:\
199
fprintf(stderr,":realloc: failed to get %d bytes at %s:%d.\n", \
200
zz_sze_zz,__FILE__,__LINE__), \
201
zz_ptr_zz )
202
203
#define FREE(zz_fptr_zz) free((void *) zz_fptr_zz)
204
205
#else
206
207
#define MALLOC_DBG_INIT(chn)
208
209
#define MALLOC(zz_sze_zz) malloc(zz_sze_zz)
210
211
#define CALLOC(zz_cnt_zz,zz_sze_zz) calloc(zz_cnt_zz,zz_sze_zz)
212
213
#define REALLOC(zz_rptr_zz,zz_sze_zz) realloc(zz_rptr_zz,zz_sze_zz)
214
215
#define FREE(zz_fptr_zz) free((void *) zz_fptr_zz)
216
217
#endif
218
219
220
#endif
/* _DYLIB_STD_H */
DylpConfig.h
dylib_io.h
lnk_struct
struct lnk_struct_tag lnk_struct
bool
BOOL bool
Definition:
dylib_std.h:67
lnk_struct_tag::llval
void * llval
Definition:
dylib_std.h:117
lnk_struct_tag::llnxt
struct lnk_struct_tag * llnxt
Definition:
dylib_std.h:116
lnk_struct_tag
Definition:
dylib_std.h:116
ioid
int ioid
Definition:
dylib_io.h:39
BOOL
#define BOOL
Definition:
config.h:6
flags
unsigned int flags
Definition:
dylib_std.h:95
Generated by
1.8.18