My Project
debian-1:4.1.2-p1+ds-2
omalloc
omError.c
Go to the documentation of this file.
1
/*******************************************************************
2
* File: omError.c
3
* Purpose: implementation of Error handling routines
4
* Author: obachman (Olaf Bachmann)
5
* Created: 11/99
6
*******************************************************************/
7
8
#include <stdarg.h>
9
#include "
omalloc.h
"
10
11
#ifdef HAVE_OMALLOC
12
13
omError_t
om_ErrorStatus
=
omError_NoError
;
14
omError_t
om_InternalErrorStatus
=
omError_NoError
;
15
16
struct
omErrorString_s
17
{
18
omError_t
error
;
19
char
*
s_error
;
20
char
*
string
;
21
};
22
23
/* strings describing omErrors */
24
static
const
struct
omErrorString_s
om_ErrorStrings
[] =
25
{
26
{
omError_NoError
,
"omError_NoError"
,
"no error"
},
27
{
omError_Unknown
,
"omError_Unknown"
,
"unknown error"
},
28
{
omError_MemoryCorrupted
,
"omError_MemoryCorrupted"
,
"memory corrupted"
},
29
{
omError_InternalBug
,
"omError_InternalBug"
,
"internal omalloc bug"
},
30
{
omError_NullAddr
,
"omError_NullAddr"
,
"addr is NULL"
},
31
{
omError_InvalidRangeAddr
,
"omError_InvalidRangeAddr"
,
"addr not in valid range"
},
32
{
omError_FalseAddr
,
"omError_FalseAddr"
,
"addr not as returned by omalloc"
},
33
{
omError_FalseAddrOrMemoryCorrupted
,
"omError_FalseAddrOrMemoryCorrupted"
,
"addr not as returned by omalloc or memory corrupted"
, },
34
{
omError_WrongSize
,
"omError_WrongSize"
,
"wrong size specification of addr"
},
35
{
omError_FreedAddr
,
"omError_FreedAddr"
,
"addr had previosuly been freed"
},
36
{
omError_FreedAddrOrMemoryCorrupted
,
"omError_FreedAddrOrMemoryCorrupted"
,
"addr had previosuly been freed or memory corrupted"
},
37
{
omError_WrongBin
,
"omError_WrongBin"
,
"addr is not from given Bin"
},
38
{
omError_UnknownBin
,
"omError_UnknownBin"
,
"given Bin is unknown"
},
39
{
omError_NotBinAddr
,
"omError_NotBinAddr"
,
"addr is not a BinAddr"
},
40
{
omError_UnalignedAddr
,
"omError_UnalignedAddr"
,
"addr is unaligned"
},
41
{
omError_NullSizeAlloc
,
"omError_NullSizeAlloc"
,
"alloc of size 0"
},
42
{
omError_ListCycleError
,
"omError_ListCycleError"
,
"list has cycles"
},
43
{
omError_SortedListError
,
"omError_SortedListError"
,
"sorted list is unsorted"
},
44
{
omError_KeptAddrListCorrupted
,
"omError_KeptAddrListCorrupted"
,
"list of kept addresses are corrupted"
},
45
{
omError_FrontPattern
,
"omError_FrontPattern"
,
"written to front of addr"
},
46
{
omError_BackPattern
,
"omError_BackPattern"
,
"written after end of addr"
},
47
{
omError_FreePattern
,
"omError_FreePattern"
,
"written into freed memory"
},
48
{
omError_NotString
,
"omError_NotString"
,
"string not null terminated"
},
49
{
omError_StickyBin
,
"omError_StickyBin"
,
"wrong handling of sticky bins"
},
50
51
{
omError_MaxError
,
NULL
}
/* this needs to be the last entry */
52
};
53
54
const
char
*
omError2String
(
omError_t
error
)
55
{
56
int
i
= 0;
57
while
(! (
om_ErrorStrings
[
i
].
string
==
NULL
&&
om_ErrorStrings
[
i
].
error
==
omError_MaxError
))
58
{
59
if
(
om_ErrorStrings
[
i
].
error
==
error
)
return
om_ErrorStrings
[
i
].
string
;
60
i
++;
61
}
62
return
"undocumented error"
;
63
}
64
65
const
char
*
omError2Serror
(
omError_t
error
)
66
{
67
int
i
= 0;
68
while
(! (
om_ErrorStrings
[
i
].
string
==
NULL
&&
om_ErrorStrings
[
i
].
error
==
omError_MaxError
))
69
{
70
if
(
om_ErrorStrings
[
i
].
error
==
error
)
return
om_ErrorStrings
[
i
].
s_error
;
71
i
++;
72
}
73
return
"omError_UnKnown"
;
74
}
75
76
#ifndef OM_NDEBUG
77
int
om_CallErrorHook
= 1;
78
#endif
79
80
omError_t
omReportError
(
omError_t
error
,
omError_t
report_error, OM_FLR_DECL,
81
const
char
* fmt, ...)
82
{
83
int
max_check, max_track;
84
85
if
(report_error ==
omError_MaxError
)
return
error
;
86
/* reset MaxTrack and MaxCheck to prevent infinite loop, in case
87
printf allocates memory */
88
max_check =
om_Opts
.MaxCheck;
89
max_track =
om_Opts
.MaxTrack;
90
om_Opts
.MaxCheck = 0;
91
om_Opts
.MaxTrack = 0;
92
93
om_InternalErrorStatus
=
error
;
94
om_ErrorStatus
= (report_error ==
omError_NoError
?
error
: report_error);
95
96
if
(
om_Opts
.HowToReportErrors &&
om_ErrorStatus
!=
omError_NoError
)
97
{
98
/* to avoid spurious error msg in 64 bit mode*/
99
if
(
om_ErrorStatus
==
omError_StickyBin
)
return
error
;
100
fprintf(stderr,
"***%s: %s"
,
omError2Serror
(
om_ErrorStatus
),
omError2String
(
om_ErrorStatus
));
101
102
#ifdef OM_INTERNAL_DEBUG
103
if
(
om_ErrorStatus
!=
error
)
104
fprintf(stderr,
"\n___%s: %s"
,
omError2Serror
(
error
),
omError2String
(
error
));
105
#endif
106
107
if
(
om_Opts
.HowToReportErrors > 2 && fmt !=
NULL
&& *fmt !=
'\0'
)
108
{
109
va_list
ap
;
110
va_start(
ap
, fmt);
111
fputs(
": "
,stderr);
112
vfprintf(stderr, fmt,
ap
);
113
va_end(
ap
);
114
}
115
116
if
(
om_Opts
.HowToReportErrors > 1)
117
{
118
#ifndef OM_NDEBUG
119
fputs(
"\n occurred at: "
,stderr);
120
if
(!
_omPrintCurrentBackTrace
(stderr, OM_FLR_VAL))
121
fputs(
" ??"
,stderr);
122
#endif
123
}
124
fputc(
'\n'
,stderr);
125
fflush(stderr);
126
}
127
if
(
om_CallErrorHook
)
128
om_Opts
.ErrorHook();
129
130
om_Opts
.MaxCheck = max_check;
131
om_Opts
.MaxTrack = max_track;
132
return
error
;
133
}
134
135
136
/* this is a dummy function and used as default for om_Opts.ErrorHook */
137
extern
void
omErrorBreak
()
138
{}
139
#endif
omError_FrontPattern
Definition:
omError.h:44
error
void error(const char *fmt,...)
Definition:
emacs.cc:54
omalloc.h
omErrorBreak
void omErrorBreak()
Definition:
omError.c:136
omErrorString_s::s_error
char * s_error
Definition:
omError.c:18
omError_SortedListError
Definition:
omError.h:40
omError_BackPattern
Definition:
omError.h:43
omErrorString_s
Definition:
omError.c:15
omErrorString_s::error
omError_t error
Definition:
omError.c:17
omError_FreePattern
Definition:
omError.h:42
omError2String
const char * omError2String(omError_t error)
Definition:
omError.c:53
omReportError
omError_t omReportError(omError_t error, omError_t report_error, OM_FLR_DECL, const char *fmt,...)
Definition:
omError.c:79
_omPrintCurrentBackTrace
int _omPrintCurrentBackTrace(FILE *fd, OM_FLR_DECL)
Definition:
omRet2Info.c:267
omError_InvalidRangeAddr
Definition:
omError.h:28
ap
Definition:
ap.h:35
omError_UnalignedAddr
Definition:
omError.h:37
om_ErrorStrings
static const struct omErrorString_s om_ErrorStrings[]
Definition:
omError.c:23
om_InternalErrorStatus
omError_t om_InternalErrorStatus
Definition:
omError.c:13
omError2Serror
const char * omError2Serror(omError_t error)
Definition:
omError.c:64
i
int i
Definition:
cfEzgcd.cc:125
om_ErrorStatus
omError_t om_ErrorStatus
Definition:
omError.c:12
omError_NullAddr
Definition:
omError.h:27
omError_WrongBin
Definition:
omError.h:34
omError_FalseAddrOrMemoryCorrupted
Definition:
omError.h:30
omError_NoError
Definition:
omError.h:23
omError_FreedAddr
Definition:
omError.h:32
omError_WrongSize
Definition:
omError.h:31
omError_Unknown
Definition:
omError.h:24
omErrorString_s::string
char * string
Definition:
omError.c:19
omError_NotString
Definition:
omError.h:45
omError_KeptAddrListCorrupted
Definition:
omError.h:41
om_CallErrorHook
int om_CallErrorHook
Definition:
omError.c:76
omError_FreedAddrOrMemoryCorrupted
Definition:
omError.h:33
omError_UnknownBin
Definition:
omError.h:35
om_Opts
omOpts_t om_Opts
Definition:
omOpts.c:12
omError_ListCycleError
Definition:
omError.h:39
NULL
#define NULL
Definition:
omList.c:11
omError_NotBinAddr
Definition:
omError.h:36
omError_MaxError
Definition:
omError.h:47
omError_FalseAddr
Definition:
omError.h:29
omError_StickyBin
Definition:
omError.h:46
omError_NullSizeAlloc
Definition:
omError.h:38
omError_InternalBug
Definition:
omError.h:25
omError_t
enum omError_e omError_t
Definition:
omError.h:42
omError_MemoryCorrupted
Definition:
omError.h:26
Generated on Thu Jan 9 2020 20:32:43 for My Project by
doxygen 1.8.16
for
Singular debian-1:4.1.2-p1+ds-2