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