FreeWRL / FreeX3D
4.3.0
internal.h
1
/*******************************************************************
2
*
3
* FreeWRL main program
4
*
5
* internal header - internal.h
6
*
7
* Version embedded.
8
*
9
*
10
*******************************************************************/
11
12
/****************************************************************************
13
This file is part of the FreeWRL/FreeX3D Distribution.
14
15
Copyright 2009 CRC Canada. (http://www.crc.gc.ca)
16
17
FreeWRL/FreeX3D is free software: you can redistribute it and/or modify
18
it under the terms of the GNU Lesser Public License as published by
19
the Free Software Foundation, either version 3 of the License, or
20
(at your option) any later version.
21
22
FreeWRL/FreeX3D is distributed in the hope that it will be useful,
23
but WITHOUT ANY WARRANTY; without even the implied warranty of
24
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
25
GNU General Public License for more details.
26
27
You should have received a copy of the GNU General Public License
28
along with FreeWRL/FreeX3D. If not, see <http://www.gnu.org/licenses/>.
29
****************************************************************************/
30
31
32
33
#ifndef __FREEWRL_INTERNAL_H__
34
#define __FREEWRL_INTERNAL_H__
35
36
37
extern
const
char
*freewrl_get_version();
38
39
/* Useful to suppress things from non-debug builds */
40
#if defined(FW_DEBUG)
41
# define DEBUG_(_expr) _expr
42
#else
43
# define DEBUG_(_expr)
44
#endif
45
46
/* To conform C99 ISO C (do not use GCC extension) */
47
#define DEBUG_MSG(...) DEBUG_(fprintf(stdout, __VA_ARGS__))
48
#define TRACE_MSG(...) DEBUG_(fprintf(stdout, __VA_ARGS__))
49
#define WARN_MSG(...) DEBUG_(fprintf(stdout, __VA_ARGS__))
50
/* Error message should always be printed */
51
#define ERROR_MSG(...) fprintf(stderr, __VA_ARGS__)
52
53
#ifdef VERBOSE
54
#define DEBUG_FW(...) DEBUG_(printf("FW: "
__VA_ARGS__))
55
#else
56
#define DEBUG_FW(...)
57
#endif
58
59
#ifdef ARGSVERBOSE
60
#define DEBUG_ARGS(...) DEBUG_(printf("TEXT: "
__VA_ARGS__))
61
#else
62
#define DEBUG_ARGS(...)
63
#endif
64
68
#if defined(FW_DEBUG) && defined(DEBUG_MALLOC)
69
70
# define MALLOC(t,_sz) ((t)freewrlMalloc(__LINE__,__FILE__,_sz,FALSE))
71
# define REALLOC(_a,_b) freewrlRealloc(__LINE__,__FILE__,_a,_b)
72
# define FREE(_ptr) freewrlFree(__LINE__,__FILE__,_ptr)
73
# define STRDUP(_a) freewrlStrdup(__LINE__,__FILE__,_a)
74
#include <stdlib.h>
75
void
*freewrlMalloc(
int
line,
char
*file,
size_t
sz,
int
zeroData);
76
void
*freewrlRealloc(
int
line,
char
*file,
void
*ptr,
size_t
size);
77
void
freewrlFree(
int
line,
char
*file,
void
*a);
78
void
*freewrlStrdup(
int
line,
char
*file,
char
*str);
79
80
# define UNLINK(_fdd) do { \
81
TRACE_MSG("TRACE: unlink %s at %s:%d\n"
,_fdd,__FILE__,__LINE__); \
82
unlink (_fdd); \
83
} while (0)
84
85
# define ASSERT(_ptr) do { if (!(_ptr)) { \
86
ERROR_MSG("ERROR: assert failed: %s (%s:%d)\n"
, #_ptr, __FILE__, __LINE__); } \
87
} while (0)
88
89
#else
/* defined(FW_DEBUG) && defined(DEBUG_MALLOC) */
90
91
# define MALLOC(t,sz) ((t)malloc(sz))
92
# define REALLOC realloc
93
# define FREE free
94
#if defined(_MSC_VER)
95
# define STRDUP _strdup
96
# define UNLINK _unlink
97
# define TEMPNAM _tempnam
98
#else
99
# define STRDUP strdup
100
# define UNLINK unlink
101
# define TEMPNAM tempnam
102
#endif
103
# define ASSERT(_whatever)
104
105
#endif
/* defined(FW_DEBUG) && defined(DEBUG_MALLOC) */
106
107
/* This get always defined, but ERROR_MSG is no-op without _DEBUG */
108
109
#define FREE_IF_NZ(_ptr) if (_ptr) { \
110
FREE(_ptr); \
111
_ptr = 0; } \
112
else { \
113
DEBUG_MEM("free, pointer is already null at %s:%d\n"
, __FILE__, __LINE__); \
114
}
115
116
117
#endif
/* __FREEWRL_INTERNAL_H__ */
src
bin
internal.h
Generated by
1.9.5