1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395
|
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html><head><meta http-equiv="Content-Type" content="text/html;charset=UTF-8">
<title>polylib: errors.c Source File</title>
<link href="doxygen.css" rel="stylesheet" type="text/css">
<link href="tabs.css" rel="stylesheet" type="text/css">
</head><body>
<!-- Generated by Doxygen 1.5.6 -->
<div class="navigation" id="top">
<div class="tabs">
<ul>
<li><a href="main.html"><span>Main Page</span></a></li>
<li><a href="annotated.html"><span>Classes</span></a></li>
<li class="current"><a href="files.html"><span>Files</span></a></li>
</ul>
</div>
<h1>errors.c</h1><a href="errors_8c.html">Go to the documentation of this file.</a><div class="fragment"><pre class="fragment"><a name="l00001"></a>00001 <span class="comment">/*</span>
<a name="l00002"></a>00002 <span class="comment"> $Id: errors.c,v 1.6 2006/03/15 19:59:37 verdoolaege Exp $</span>
<a name="l00003"></a>00003 <span class="comment"></span>
<a name="l00004"></a>00004 <span class="comment"> Exception management.</span>
<a name="l00005"></a>00005 <span class="comment"> See "arithmetic_errors.h".</span>
<a name="l00006"></a>00006 <span class="comment"></span>
<a name="l00007"></a>00007 <span class="comment"> $Log: errors.c,v $</span>
<a name="l00008"></a>00008 <span class="comment"> Revision 1.6 2006/03/15 19:59:37 verdoolaege</span>
<a name="l00009"></a>00009 <span class="comment"> arith: add some missing consts</span>
<a name="l00010"></a>00010 <span class="comment"></span>
<a name="l00011"></a>00011 <span class="comment"> Revision 1.5 2004/08/31 18:01:56 verdoolaege</span>
<a name="l00012"></a>00012 <span class="comment"> remove warning</span>
<a name="l00013"></a>00013 <span class="comment"></span>
<a name="l00014"></a>00014 <span class="comment"> Revision 1.4 2004/02/11 10:19:54 verdoolaege</span>
<a name="l00015"></a>00015 <span class="comment"> add const qualifier</span>
<a name="l00016"></a>00016 <span class="comment"></span>
<a name="l00017"></a>00017 <span class="comment"> Revision 1.3 2004/02/08 21:53:27 kienhuis</span>
<a name="l00018"></a>00018 <span class="comment"> Update from Fabien Coelho, via Bart Kienhuis</span>
<a name="l00019"></a>00019 <span class="comment"></span>
<a name="l00020"></a>00020 <span class="comment"> I've updated here in the C3/Linear library the arithmetic_error</span>
<a name="l00021"></a>00021 <span class="comment"> package that I developped (with others) to handle exceptions in C.</span>
<a name="l00022"></a>00022 <span class="comment"> It adds a simple callback feature which is needed for pips here.</span>
<a name="l00023"></a>00023 <span class="comment"> If you do not use it, it should not harm;-)</span>
<a name="l00024"></a>00024 <span class="comment"></span>
<a name="l00025"></a>00025 <span class="comment"> Revision 1.27 2003/09/04 09:40:37 coelho</span>
<a name="l00026"></a>00026 <span class="comment"> init added.</span>
<a name="l00027"></a>00027 <span class="comment"> verbosity mask added.</span>
<a name="l00028"></a>00028 <span class="comment"></span>
<a name="l00029"></a>00029 <span class="comment"> Revision 1.26 2003/09/03 14:05:20 coelho</span>
<a name="l00030"></a>00030 <span class="comment"> push/pop callbacks called.</span>
<a name="l00031"></a>00031 <span class="comment"></span>
<a name="l00032"></a>00032 <span class="comment"> Revision 1.20 2003/08/18 09:55:09 coelho</span>
<a name="l00033"></a>00033 <span class="comment"> get_exception_name added...</span>
<a name="l00034"></a>00034 <span class="comment"></span>
<a name="l00035"></a>00035 <span class="comment"> Revision 1.19 2003/06/13 13:59:07 coelho</span>
<a name="l00036"></a>00036 <span class="comment"> const out.</span>
<a name="l00037"></a>00037 <span class="comment"></span>
<a name="l00038"></a>00038 <span class="comment"> Revision 1.18 2003/06/13 13:54:47 coelho</span>
<a name="l00039"></a>00039 <span class="comment"> hop.</span>
<a name="l00040"></a>00040 <span class="comment"></span>
<a name="l00041"></a>00041 <span class="comment"> Revision 1.17 2002/04/02 08:44:54 coelho</span>
<a name="l00042"></a>00042 <span class="comment"> timeout_error ajoute.</span>
<a name="l00043"></a>00043 <span class="comment"></span>
<a name="l00044"></a>00044 <span class="comment"> Revision 1.16 2000/10/27 13:26:03 ancourt</span>
<a name="l00045"></a>00045 <span class="comment"> exception_thrown -> linear_number_of_exception_thrown</span>
<a name="l00046"></a>00046 <span class="comment"></span>
<a name="l00047"></a>00047 <span class="comment"> Revision 1.15 2000/07/27 15:21:55 coelho</span>
<a name="l00048"></a>00048 <span class="comment"> message++</span>
<a name="l00049"></a>00049 <span class="comment"></span>
<a name="l00050"></a>00050 <span class="comment"> Revision 1.14 2000/07/27 14:59:59 coelho</span>
<a name="l00051"></a>00051 <span class="comment"> trace added.</span>
<a name="l00052"></a>00052 <span class="comment"></span>
<a name="l00053"></a>00053 <span class="comment"> Revision 1.13 2000/07/26 08:41:23 coelho</span>
<a name="l00054"></a>00054 <span class="comment"> the_last_just_thrown_exception management added.</span>
<a name="l00055"></a>00055 <span class="comment"></span>
<a name="l00056"></a>00056 <span class="comment"> Revision 1.12 1998/10/26 18:48:34 coelho</span>
<a name="l00057"></a>00057 <span class="comment"> message++.</span>
<a name="l00058"></a>00058 <span class="comment"></span>
<a name="l00059"></a>00059 <span class="comment"> Revision 1.11 1998/10/26 14:38:06 coelho</span>
<a name="l00060"></a>00060 <span class="comment"> constants back in.</span>
<a name="l00061"></a>00061 <span class="comment"></span>
<a name="l00062"></a>00062 <span class="comment"> Revision 1.10 1998/10/26 14:35:47 coelho</span>
<a name="l00063"></a>00063 <span class="comment"> constants in .h.</span>
<a name="l00064"></a>00064 <span class="comment"></span>
<a name="l00065"></a>00065 <span class="comment"> Revision 1.9 1998/10/24 15:36:22 coelho</span>
<a name="l00066"></a>00066 <span class="comment"> better exception error messages...</span>
<a name="l00067"></a>00067 <span class="comment"></span>
<a name="l00068"></a>00068 <span class="comment"> Revision 1.8 1998/10/24 15:19:17 coelho</span>
<a name="l00069"></a>00069 <span class="comment"> more verbose throw...</span>
<a name="l00070"></a>00070 <span class="comment"></span>
<a name="l00071"></a>00071 <span class="comment"> Revision 1.7 1998/10/24 14:31:13 coelho</span>
<a name="l00072"></a>00072 <span class="comment"> new stack implementation.</span>
<a name="l00073"></a>00073 <span class="comment"> checks for matching catch/uncatch.</span>
<a name="l00074"></a>00074 <span class="comment"> debug mode.</span>
<a name="l00075"></a>00075 <span class="comment"></span>
<a name="l00076"></a>00076 <span class="comment"> Revision 1.6 1998/10/24 09:31:06 coelho</span>
<a name="l00077"></a>00077 <span class="comment"> RCS headers.</span>
<a name="l00078"></a>00078 <span class="comment"> 'const' tried.</span>
<a name="l00079"></a>00079 <span class="comment"></span>
<a name="l00080"></a>00080 <span class="comment">*/</span>
<a name="l00081"></a>00081
<a name="l00082"></a>00082 <span class="preprocessor">#include <stdio.h></span>
<a name="l00083"></a>00083 <span class="preprocessor">#include <stdlib.h></span>
<a name="l00084"></a>00084 <span class="preprocessor">#include <string.h></span>
<a name="l00085"></a>00085
<a name="l00086"></a>00086 <span class="preprocessor">#include "<a class="code" href="source_2arith_2arithmetique_8h.html">arithmetique.h</a>"</span>
<a name="l00087"></a>00087
<a name="l00088"></a>00088 <span class="comment">/* global constants to designate exceptions.</span>
<a name="l00089"></a>00089 <span class="comment"> to be put in the type field bellow.</span>
<a name="l00090"></a>00090 <span class="comment"> cproto 4.6 does not line 'const'...</span>
<a name="l00091"></a>00091 <span class="comment">*/</span>
<a name="l00092"></a><a class="code" href="include_2polylib_2arithmetique_8h.html#f74135a8750c28205f819842ae8be9c9">00092</a> <span class="keywordtype">unsigned</span> <span class="keywordtype">int</span> <a class="code" href="source_2arith_2arithmetique_8h.html#f74135a8750c28205f819842ae8be9c9">overflow_error</a> = 1;
<a name="l00093"></a><a class="code" href="include_2polylib_2arithmetique_8h.html#381d67b7ee03ff84c242d6f342fa063c">00093</a> <span class="keywordtype">unsigned</span> <span class="keywordtype">int</span> <a class="code" href="source_2arith_2arithmetique_8h.html#381d67b7ee03ff84c242d6f342fa063c">simplex_arithmetic_error</a> = 2;
<a name="l00094"></a><a class="code" href="include_2polylib_2arithmetique_8h.html#18b35523d2702706b86f2ab8ae2393d2">00094</a> <span class="keywordtype">unsigned</span> <span class="keywordtype">int</span> <a class="code" href="source_2arith_2arithmetique_8h.html#18b35523d2702706b86f2ab8ae2393d2">user_exception_error</a> = 4;
<a name="l00095"></a><a class="code" href="include_2polylib_2arithmetique_8h.html#3806d9a2c0134fd8bef8c192341a8954">00095</a> <span class="keywordtype">unsigned</span> <span class="keywordtype">int</span> <a class="code" href="source_2arith_2arithmetique_8h.html#3806d9a2c0134fd8bef8c192341a8954">parser_exception_error</a> = 8;
<a name="l00096"></a><a class="code" href="errors_8c.html#3cae90a91b95e5365e192179877cccf9">00096</a> <span class="keywordtype">unsigned</span> <span class="keywordtype">int</span> <a class="code" href="errors_8c.html#3cae90a91b95e5365e192179877cccf9">timeout_error</a> = 16;
<a name="l00097"></a>00097
<a name="l00098"></a>00098 <span class="comment">/* catch all */</span>
<a name="l00099"></a><a class="code" href="include_2polylib_2arithmetique_8h.html#3fbedc713824754a33dd94278851fe70">00099</a> <span class="keywordtype">unsigned</span> <span class="keywordtype">int</span> <a class="code" href="source_2arith_2arithmetique_8h.html#3fbedc713824754a33dd94278851fe70">any_exception_error</a> = ~0;
<a name="l00100"></a>00100
<a name="l00101"></a>00101
<a name="l00102"></a>00102 <span class="comment">/*</span>
<a name="l00103"></a>00103 <span class="comment"> * On a few systems, type boolean and/or its values FALSE, TRUE may appear</span>
<a name="l00104"></a>00104 <span class="comment"> * in standard header files. Or you may have conflicts with application-</span>
<a name="l00105"></a>00105 <span class="comment"> * specific header files that you want to include together with these files.</span>
<a name="l00106"></a>00106 <span class="comment"> * Defining HAVE_BOOLEAN before including jpeglib.h should make it work.</span>
<a name="l00107"></a>00107 <span class="comment"> */</span>
<a name="l00108"></a>00108
<a name="l00109"></a>00109 <span class="preprocessor">#ifndef HAVE_BOOLEAN</span>
<a name="l00110"></a><a class="code" href="errors_8c.html#621c38f1f10a1c565d897e3178b16d6e">00110</a> <span class="preprocessor"></span><span class="keyword">typedef</span> <span class="keywordtype">int</span> <a class="code" href="errors_8c.html#621c38f1f10a1c565d897e3178b16d6e">boolean</a>;
<a name="l00111"></a>00111 <span class="preprocessor">#endif</span>
<a name="l00112"></a>00112 <span class="preprocessor"></span><span class="preprocessor">#ifndef FALSE </span><span class="comment">/* in case these macros already exist */</span>
<a name="l00113"></a><a class="code" href="errors_8c.html#a93f0eb578d23995850d61f7d61c55c1">00113</a> <span class="preprocessor">#define FALSE 0 </span><span class="comment">/* values of boolean */</span>
<a name="l00114"></a>00114 <span class="preprocessor">#endif</span>
<a name="l00115"></a>00115 <span class="preprocessor"></span><span class="preprocessor">#ifndef TRUE</span>
<a name="l00116"></a><a class="code" href="errors_8c.html#a8cecfc5c5c054d2875c03e77b7be15d">00116</a> <span class="preprocessor"></span><span class="preprocessor">#define TRUE 1</span>
<a name="l00117"></a>00117 <span class="preprocessor"></span><span class="preprocessor">#endif</span>
<a name="l00118"></a>00118 <span class="preprocessor"></span>
<a name="l00119"></a><a class="code" href="errors_8c.html#79edc2c9a0ce7b3159417f9130a14def">00119</a> <span class="keyword">const</span> <span class="keywordtype">char</span> *<a class="code" href="errors_8c.html#79edc2c9a0ce7b3159417f9130a14def">get_exception_name</a>(<span class="keywordtype">unsigned</span> <span class="keywordtype">int</span> exception)
<a name="l00120"></a>00120 {
<a name="l00121"></a>00121 <span class="keywordflow">if</span> (exception==<a class="code" href="source_2arith_2arithmetique_8h.html#f74135a8750c28205f819842ae8be9c9">overflow_error</a>)
<a name="l00122"></a>00122 <span class="keywordflow">return</span> <span class="stringliteral">"overflow_error exception"</span>;
<a name="l00123"></a>00123 <span class="keywordflow">if</span> (exception==<a class="code" href="source_2arith_2arithmetique_8h.html#381d67b7ee03ff84c242d6f342fa063c">simplex_arithmetic_error</a>)
<a name="l00124"></a>00124 <span class="keywordflow">return</span> <span class="stringliteral">"simplex_arithmetic_error exception"</span>;
<a name="l00125"></a>00125 <span class="keywordflow">if</span> (exception==<a class="code" href="source_2arith_2arithmetique_8h.html#18b35523d2702706b86f2ab8ae2393d2">user_exception_error</a>)
<a name="l00126"></a>00126 <span class="keywordflow">return</span> <span class="stringliteral">"user_exception_error exception"</span>;
<a name="l00127"></a>00127 <span class="keywordflow">if</span> (exception==<a class="code" href="source_2arith_2arithmetique_8h.html#3806d9a2c0134fd8bef8c192341a8954">parser_exception_error</a>)
<a name="l00128"></a>00128 <span class="keywordflow">return</span> <span class="stringliteral">"parser_exception_error exception"</span>;
<a name="l00129"></a>00129 <span class="keywordflow">if</span> (exception==<a class="code" href="errors_8c.html#3cae90a91b95e5365e192179877cccf9">timeout_error</a>)
<a name="l00130"></a>00130 <span class="keywordflow">return</span> <span class="stringliteral">"timeout_error exception"</span>;
<a name="l00131"></a>00131 <span class="keywordflow">if</span> (exception==<a class="code" href="source_2arith_2arithmetique_8h.html#3fbedc713824754a33dd94278851fe70">any_exception_error</a>)
<a name="l00132"></a>00132 <span class="keywordflow">return</span> <span class="stringliteral">"all exceptions mask"</span>;
<a name="l00133"></a>00133
<a name="l00134"></a>00134 <span class="keywordflow">return</span> <span class="stringliteral">"unknown or mixed exception"</span>;
<a name="l00135"></a>00135 }
<a name="l00136"></a>00136
<a name="l00137"></a>00137 <span class="comment">/* keep track of last thrown exception for RETHROW()</span>
<a name="l00138"></a>00138 <span class="comment"> */</span>
<a name="l00139"></a><a class="code" href="include_2polylib_2arithmetique_8h.html#9dbd1094abce0128b2995c91d701349d">00139</a> <span class="keywordtype">unsigned</span> <span class="keywordtype">int</span> <a class="code" href="source_2arith_2arithmetic__errors_8h.html#9dbd1094abce0128b2995c91d701349d">the_last_just_thrown_exception</a> = 0;
<a name="l00140"></a>00140
<a name="l00141"></a>00141 <span class="comment">/* whether to run in debug mode (that is to trace catch/uncatch/throw)</span>
<a name="l00142"></a>00142 <span class="comment"> */</span>
<a name="l00143"></a><a class="code" href="errors_8c.html#0471cbbdd66a5ee1fa3a459878c756be">00143</a> <span class="keyword">static</span> <span class="keywordtype">int</span> <a class="code" href="errors_8c.html#0471cbbdd66a5ee1fa3a459878c756be">linear_exception_debug_mode</a> = <a class="code" href="errors_8c.html#a93f0eb578d23995850d61f7d61c55c1">FALSE</a>;
<a name="l00144"></a><a class="code" href="errors_8c.html#3e54f04e8bd9d204f2ad4dcd32ac744f">00144</a> <span class="keyword">static</span> <span class="keywordtype">unsigned</span> <span class="keywordtype">int</span> <a class="code" href="errors_8c.html#3e54f04e8bd9d204f2ad4dcd32ac744f">linear_exception_verbose</a> = 1 | 2 | 16 ;
<a name="l00145"></a>00145
<a name="l00146"></a>00146 <span class="comment">/* A structure for the exception stack.</span>
<a name="l00147"></a>00147 <span class="comment"> */</span>
<a name="l00148"></a><a class="code" href="structlinear__exception__holder.html">00148</a> <span class="keyword">typedef</span> <span class="keyword">struct </span>
<a name="l00149"></a>00149 {
<a name="l00150"></a>00150 <span class="comment">/* exception type.</span>
<a name="l00151"></a>00151 <span class="comment"> */</span>
<a name="l00152"></a><a class="code" href="structlinear__exception__holder.html#f58917e56c6831b227e006673710fe5d">00152</a> <span class="keywordtype">int</span> what;
<a name="l00153"></a>00153
<a name="l00154"></a>00154 <span class="comment">/* where to jump to.</span>
<a name="l00155"></a>00155 <span class="comment"> */</span>
<a name="l00156"></a><a class="code" href="structlinear__exception__holder.html#d9a2b584f896181a0578b05c6cb7cc3e">00156</a> jmp_buf where;
<a name="l00157"></a>00157
<a name="l00158"></a>00158 <span class="comment">/* location of the CATCH to be matched against the UNCATCH.</span>
<a name="l00159"></a>00159 <span class="comment"> */</span>
<a name="l00160"></a><a class="code" href="structlinear__exception__holder.html#fcc50c683b77f6a21e07b49ac2bc81f3">00160</a> <span class="keyword">const</span> <span class="keywordtype">char</span> * function;
<a name="l00161"></a><a class="code" href="structlinear__exception__holder.html#4da979c2531ecea486a511e6540c031a">00161</a> <span class="keyword">const</span> <span class="keywordtype">char</span> * file;
<a name="l00162"></a><a class="code" href="structlinear__exception__holder.html#03fe66cae813ea2b3328f04878aec61b">00162</a> <span class="keywordtype">int</span> line;
<a name="l00163"></a>00163 }
<a name="l00164"></a>00164 <a class="code" href="structlinear__exception__holder.html">linear_exception_holder</a>;
<a name="l00165"></a>00165
<a name="l00166"></a>00166 <span class="comment">/* exception stack.</span>
<a name="l00167"></a>00167 <span class="comment"> maximum extension.</span>
<a name="l00168"></a>00168 <span class="comment"> current index (next available bucket)</span>
<a name="l00169"></a>00169 <span class="comment"> */</span>
<a name="l00170"></a><a class="code" href="errors_8c.html#aec70e82a04c1102db5789b0c8092055">00170</a> <span class="preprocessor">#define MAX_STACKED_CONTEXTS 64</span>
<a name="l00171"></a><a class="code" href="errors_8c.html#e7d6c7530e7505f175ee1efaf0dd33e1">00171</a> <span class="preprocessor"></span><span class="keyword">static</span> <a class="code" href="structlinear__exception__holder.html">linear_exception_holder</a> <a class="code" href="errors_8c.html#e7d6c7530e7505f175ee1efaf0dd33e1">exception_stack</a>[<a class="code" href="errors_8c.html#aec70e82a04c1102db5789b0c8092055">MAX_STACKED_CONTEXTS</a>];
<a name="l00172"></a><a class="code" href="errors_8c.html#d63e2e9e42900784d7f912727fc90af3">00172</a> <span class="keyword">static</span> <span class="keywordtype">int</span> <a class="code" href="errors_8c.html#d63e2e9e42900784d7f912727fc90af3">exception_index</a> = 0;
<a name="l00173"></a>00173
<a name="l00174"></a>00174 <span class="comment">/* callbacks...</span>
<a name="l00175"></a>00175 <span class="comment"> */</span>
<a name="l00176"></a><a class="code" href="errors_8c.html#949dce609af01654ccefedf9473eac29">00176</a> <span class="keyword">static</span> <a class="code" href="source_2arith_2arithmetic__errors_8h.html#afc39b4cb7a07fefadbdaeb9f8753679">exception_callback_t</a> <a class="code" href="errors_8c.html#949dce609af01654ccefedf9473eac29">push_callback</a> = NULL;
<a name="l00177"></a><a class="code" href="errors_8c.html#5cb3be87cd274e085213bafc6eca475f">00177</a> <span class="keyword">static</span> <a class="code" href="source_2arith_2arithmetic__errors_8h.html#afc39b4cb7a07fefadbdaeb9f8753679">exception_callback_t</a> <a class="code" href="errors_8c.html#5cb3be87cd274e085213bafc6eca475f">pop_callback</a> = NULL;
<a name="l00178"></a>00178
<a name="l00179"></a><a class="code" href="errors_8c.html#93de4c04224b53c462a8bd9242edd3ed">00179</a> <span class="keywordtype">void</span> <a class="code" href="errors_8c.html#93de4c04224b53c462a8bd9242edd3ed">set_exception_callbacks</a>(<a class="code" href="source_2arith_2arithmetic__errors_8h.html#afc39b4cb7a07fefadbdaeb9f8753679">exception_callback_t</a> push,
<a name="l00180"></a>00180 <a class="code" href="source_2arith_2arithmetic__errors_8h.html#afc39b4cb7a07fefadbdaeb9f8753679">exception_callback_t</a> pop)
<a name="l00181"></a>00181 {
<a name="l00182"></a>00182 <span class="keywordflow">if</span> (<a class="code" href="errors_8c.html#949dce609af01654ccefedf9473eac29">push_callback</a>!=NULL || <a class="code" href="errors_8c.html#5cb3be87cd274e085213bafc6eca475f">pop_callback</a>!=NULL)
<a name="l00183"></a>00183 {
<a name="l00184"></a>00184 fprintf(stderr, <span class="stringliteral">"exception callbacks already defined! (%p, %p)\n"</span>,
<a name="l00185"></a>00185 <a class="code" href="errors_8c.html#949dce609af01654ccefedf9473eac29">push_callback</a>, <a class="code" href="errors_8c.html#5cb3be87cd274e085213bafc6eca475f">pop_callback</a>);
<a name="l00186"></a>00186 abort();
<a name="l00187"></a>00187 }
<a name="l00188"></a>00188
<a name="l00189"></a>00189 <a class="code" href="errors_8c.html#949dce609af01654ccefedf9473eac29">push_callback</a> = push;
<a name="l00190"></a>00190 <a class="code" href="errors_8c.html#5cb3be87cd274e085213bafc6eca475f">pop_callback</a> = pop;
<a name="l00191"></a>00191 }
<a name="l00192"></a>00192
<a name="l00193"></a>00193 <span class="comment">/* total number of exceptions thrown, for statistics.</span>
<a name="l00194"></a>00194 <span class="comment"> */</span>
<a name="l00195"></a><a class="code" href="errors_8c.html#3313c41a656ee03e88a9d00234cfc5ec">00195</a> <span class="keywordtype">int</span> <a class="code" href="errors_8c.html#3313c41a656ee03e88a9d00234cfc5ec">linear_number_of_exception_thrown</a> = 0;
<a name="l00196"></a>00196
<a name="l00197"></a>00197 <span class="comment">/* dump stack</span>
<a name="l00198"></a>00198 <span class="comment"> */</span>
<a name="l00199"></a><a class="code" href="include_2polylib_2arithmetique_8h.html#95032703f9a53198ae5f188a05836557">00199</a> <span class="keywordtype">void</span> <a class="code" href="source_2arith_2arithmetique_8h.html#95032703f9a53198ae5f188a05836557">dump_exception_stack_to_file</a>(FILE * f)
<a name="l00200"></a>00200 {
<a name="l00201"></a>00201 <span class="keywordtype">int</span> i;
<a name="l00202"></a>00202 fprintf(f, <span class="stringliteral">"[dump_exception_stack_to_file] size=%d\n"</span>, <a class="code" href="errors_8c.html#d63e2e9e42900784d7f912727fc90af3">exception_index</a>);
<a name="l00203"></a>00203 <span class="keywordflow">for</span> (i=0; i<<a class="code" href="errors_8c.html#d63e2e9e42900784d7f912727fc90af3">exception_index</a>; i++)
<a name="l00204"></a>00204 {
<a name="l00205"></a>00205 fprintf(f,
<a name="l00206"></a>00206 <span class="stringliteral">"%d: [%s:%d in %s (%d)]\n"</span>,
<a name="l00207"></a>00207 i,
<a name="l00208"></a>00208 exception_stack[i].file,
<a name="l00209"></a>00209 exception_stack[i].line,
<a name="l00210"></a>00210 exception_stack[i].function,
<a name="l00211"></a>00211 exception_stack[i].what);
<a name="l00212"></a>00212 }
<a name="l00213"></a>00213 fprintf(f, <span class="stringliteral">"\n"</span>);
<a name="l00214"></a>00214 }
<a name="l00215"></a>00215
<a name="l00216"></a><a class="code" href="include_2polylib_2arithmetique_8h.html#5d0d562c4394d6711b3d105487cfa229">00216</a> <span class="keywordtype">void</span> <a class="code" href="source_2arith_2arithmetique_8h.html#5d0d562c4394d6711b3d105487cfa229">dump_exception_stack</a>()
<a name="l00217"></a>00217 {
<a name="l00218"></a>00218 <a class="code" href="source_2arith_2arithmetique_8h.html#95032703f9a53198ae5f188a05836557">dump_exception_stack_to_file</a>(stderr);
<a name="l00219"></a>00219 }
<a name="l00220"></a>00220
<a name="l00221"></a><a class="code" href="errors_8c.html#8d4a2127a1edadca61c0631735922769">00221</a> <span class="preprocessor">#define exception_debug_message(type) \</span>
<a name="l00222"></a>00222 <span class="preprocessor"> fprintf(stderr, "%s[%s:%d %s (%d)/%d]\n", \</span>
<a name="l00223"></a>00223 <span class="preprocessor"> type, file, line, function, what, exception_index) </span>
<a name="l00224"></a>00224 <span class="preprocessor"></span>
<a name="l00225"></a><a class="code" href="errors_8c.html#82fa865508693149b63d670fa7d7c438">00225</a> <span class="preprocessor">#define exception_debug_trace(type) \</span>
<a name="l00226"></a>00226 <span class="preprocessor"> if (linear_exception_debug_mode) { exception_debug_message(type); }</span>
<a name="l00227"></a>00227 <span class="preprocessor"></span>
<a name="l00228"></a>00228
<a name="l00229"></a>00229 <span class="comment">/* push a what exception on stack.</span>
<a name="l00230"></a>00230 <span class="comment"> */</span>
<a name="l00231"></a>00231 jmp_buf *
<a name="l00232"></a><a class="code" href="include_2polylib_2arithmetique_8h.html#6c4868122de3ac9f2dddafc35d583021">00232</a> <a class="code" href="source_2arith_2arithmetique_8h.html#6c4868122de3ac9f2dddafc35d583021">push_exception_on_stack</a>(
<a name="l00233"></a>00233 <span class="keywordtype">int</span> what,
<a name="l00234"></a>00234 <span class="keyword">const</span> <span class="keywordtype">char</span> * function,
<a name="l00235"></a>00235 <span class="keyword">const</span> <span class="keywordtype">char</span> * file,
<a name="l00236"></a>00236 <span class="keywordtype">int</span> line)
<a name="l00237"></a>00237 {
<a name="l00238"></a>00238 <a class="code" href="errors_8c.html#82fa865508693149b63d670fa7d7c438">exception_debug_trace</a>(<span class="stringliteral">"PUSH "</span>);
<a name="l00239"></a>00239
<a name="l00240"></a>00240 <span class="keywordflow">if</span> (<a class="code" href="errors_8c.html#d63e2e9e42900784d7f912727fc90af3">exception_index</a>==<a class="code" href="errors_8c.html#aec70e82a04c1102db5789b0c8092055">MAX_STACKED_CONTEXTS</a>)
<a name="l00241"></a>00241 {
<a name="l00242"></a>00242 <a class="code" href="errors_8c.html#8d4a2127a1edadca61c0631735922769">exception_debug_message</a>(<span class="stringliteral">"push"</span>);
<a name="l00243"></a>00243 fprintf(stderr, <span class="stringliteral">"exception stack overflow\n"</span>);
<a name="l00244"></a>00244 <a class="code" href="source_2arith_2arithmetique_8h.html#5d0d562c4394d6711b3d105487cfa229">dump_exception_stack</a>();
<a name="l00245"></a>00245 abort();
<a name="l00246"></a>00246 }
<a name="l00247"></a>00247
<a name="l00248"></a>00248 <span class="keywordflow">if</span> (<a class="code" href="errors_8c.html#949dce609af01654ccefedf9473eac29">push_callback</a>) <a class="code" href="errors_8c.html#949dce609af01654ccefedf9473eac29">push_callback</a>(file, function, line);
<a name="l00249"></a>00249
<a name="l00250"></a>00250 <a class="code" href="source_2arith_2arithmetic__errors_8h.html#9dbd1094abce0128b2995c91d701349d">the_last_just_thrown_exception</a> = 0;
<a name="l00251"></a>00251
<a name="l00252"></a>00252 exception_stack[<a class="code" href="errors_8c.html#d63e2e9e42900784d7f912727fc90af3">exception_index</a>].<a class="code" href="structlinear__exception__holder.html#f58917e56c6831b227e006673710fe5d">what</a> = what;
<a name="l00253"></a>00253 exception_stack[<a class="code" href="errors_8c.html#d63e2e9e42900784d7f912727fc90af3">exception_index</a>].<a class="code" href="structlinear__exception__holder.html#fcc50c683b77f6a21e07b49ac2bc81f3">function</a> = function;
<a name="l00254"></a>00254 exception_stack[<a class="code" href="errors_8c.html#d63e2e9e42900784d7f912727fc90af3">exception_index</a>].<a class="code" href="structlinear__exception__holder.html#4da979c2531ecea486a511e6540c031a">file</a> = file;
<a name="l00255"></a>00255 exception_stack[<a class="code" href="errors_8c.html#d63e2e9e42900784d7f912727fc90af3">exception_index</a>].<a class="code" href="structlinear__exception__holder.html#03fe66cae813ea2b3328f04878aec61b">line</a> = line;
<a name="l00256"></a>00256
<a name="l00257"></a>00257 <span class="keywordflow">return</span> & exception_stack[<a class="code" href="errors_8c.html#d63e2e9e42900784d7f912727fc90af3">exception_index</a>++].<a class="code" href="structlinear__exception__holder.html#d9a2b584f896181a0578b05c6cb7cc3e">where</a>;
<a name="l00258"></a>00258 }
<a name="l00259"></a>00259
<a name="l00260"></a>00260 <span class="preprocessor">#if !defined(same_string_p)</span>
<a name="l00261"></a><a class="code" href="errors_8c.html#c32f3590ee78925a812d8718f28e9a2b">00261</a> <span class="preprocessor"></span><span class="preprocessor">#define same_string_p(s1, s2) (strcmp((s1),(s2))==0)</span>
<a name="l00262"></a>00262 <span class="preprocessor"></span><span class="preprocessor">#endif</span>
<a name="l00263"></a>00263 <span class="preprocessor"></span>
<a name="l00264"></a>00264 <span class="comment">/* pop a what exception.</span>
<a name="l00265"></a>00265 <span class="comment"> check for any mismatch!</span>
<a name="l00266"></a>00266 <span class="comment"> */</span>
<a name="l00267"></a>00267 <span class="keywordtype">void</span>
<a name="l00268"></a><a class="code" href="include_2polylib_2arithmetique_8h.html#66795100cf9a30f6cf85a7c67d7c8050">00268</a> <a class="code" href="source_2arith_2arithmetique_8h.html#66795100cf9a30f6cf85a7c67d7c8050">pop_exception_from_stack</a>(
<a name="l00269"></a>00269 <span class="keywordtype">int</span> what,
<a name="l00270"></a>00270 <span class="keyword">const</span> <span class="keywordtype">char</span> * function,
<a name="l00271"></a>00271 <span class="keyword">const</span> <span class="keywordtype">char</span> * file,
<a name="l00272"></a>00272 <span class="keywordtype">int</span> line)
<a name="l00273"></a>00273 {
<a name="l00274"></a>00274 <a class="code" href="errors_8c.html#82fa865508693149b63d670fa7d7c438">exception_debug_trace</a>(<span class="stringliteral">"POP "</span>);
<a name="l00275"></a>00275
<a name="l00276"></a>00276 <span class="keywordflow">if</span> (<a class="code" href="errors_8c.html#d63e2e9e42900784d7f912727fc90af3">exception_index</a>==0)
<a name="l00277"></a>00277 {
<a name="l00278"></a>00278 <a class="code" href="errors_8c.html#8d4a2127a1edadca61c0631735922769">exception_debug_message</a>(<span class="stringliteral">"pop"</span>);
<a name="l00279"></a>00279 fprintf(stderr, <span class="stringliteral">"exception stack underflow\n"</span>);
<a name="l00280"></a>00280 <a class="code" href="source_2arith_2arithmetique_8h.html#5d0d562c4394d6711b3d105487cfa229">dump_exception_stack</a>();
<a name="l00281"></a>00281 abort();
<a name="l00282"></a>00282 }
<a name="l00283"></a>00283
<a name="l00284"></a>00284 <span class="keywordflow">if</span> (<a class="code" href="errors_8c.html#5cb3be87cd274e085213bafc6eca475f">pop_callback</a>) <a class="code" href="errors_8c.html#5cb3be87cd274e085213bafc6eca475f">pop_callback</a>(file, function, line);
<a name="l00285"></a>00285
<a name="l00286"></a>00286 <a class="code" href="errors_8c.html#d63e2e9e42900784d7f912727fc90af3">exception_index</a>--;
<a name="l00287"></a>00287 <a class="code" href="source_2arith_2arithmetic__errors_8h.html#9dbd1094abce0128b2995c91d701349d">the_last_just_thrown_exception</a> = 0;
<a name="l00288"></a>00288
<a name="l00289"></a>00289 <span class="keywordflow">if</span> ((exception_stack[<a class="code" href="errors_8c.html#d63e2e9e42900784d7f912727fc90af3">exception_index</a>].what != what) ||
<a name="l00290"></a>00290 !<a class="code" href="errors_8c.html#c32f3590ee78925a812d8718f28e9a2b">same_string_p</a>(exception_stack[<a class="code" href="errors_8c.html#d63e2e9e42900784d7f912727fc90af3">exception_index</a>].file, file) ||
<a name="l00291"></a>00291 !<a class="code" href="errors_8c.html#c32f3590ee78925a812d8718f28e9a2b">same_string_p</a>(exception_stack[<a class="code" href="errors_8c.html#d63e2e9e42900784d7f912727fc90af3">exception_index</a>].function, function))
<a name="l00292"></a>00292 {
<a name="l00293"></a>00293 <a class="code" href="errors_8c.html#8d4a2127a1edadca61c0631735922769">exception_debug_message</a>(<span class="stringliteral">"pop"</span>);
<a name="l00294"></a>00294 fprintf(stderr,
<a name="l00295"></a>00295 <span class="stringliteral">"exception stack mismatch at depth=%d:\n"</span>
<a name="l00296"></a>00296 <span class="stringliteral">" CATCH: %s:%d in %s (%d)\n"</span>
<a name="l00297"></a>00297 <span class="stringliteral">" UNCATCH: %s:%d in %s (%d)\n"</span>,
<a name="l00298"></a>00298 <a class="code" href="errors_8c.html#d63e2e9e42900784d7f912727fc90af3">exception_index</a>,
<a name="l00299"></a>00299 exception_stack[<a class="code" href="errors_8c.html#d63e2e9e42900784d7f912727fc90af3">exception_index</a>].file,
<a name="l00300"></a>00300 exception_stack[<a class="code" href="errors_8c.html#d63e2e9e42900784d7f912727fc90af3">exception_index</a>].line,
<a name="l00301"></a>00301 exception_stack[<a class="code" href="errors_8c.html#d63e2e9e42900784d7f912727fc90af3">exception_index</a>].function,
<a name="l00302"></a>00302 exception_stack[<a class="code" href="errors_8c.html#d63e2e9e42900784d7f912727fc90af3">exception_index</a>].what,
<a name="l00303"></a>00303 file, line, function, what);
<a name="l00304"></a>00304 <a class="code" href="source_2arith_2arithmetique_8h.html#5d0d562c4394d6711b3d105487cfa229">dump_exception_stack</a>();
<a name="l00305"></a>00305 abort();
<a name="l00306"></a>00306 }
<a name="l00307"></a>00307 }
<a name="l00308"></a>00308
<a name="l00309"></a>00309 <span class="comment">/* throws an exception of a given type by searching for </span>
<a name="l00310"></a>00310 <span class="comment"> the specified 'what' in the current exception stack.</span>
<a name="l00311"></a>00311 <span class="comment">*/</span>
<a name="l00312"></a><a class="code" href="include_2polylib_2arithmetique_8h.html#904f0eb5107e737736e3992a6c0dc90f">00312</a> <span class="keywordtype">void</span> <a class="code" href="source_2arith_2arithmetique_8h.html#904f0eb5107e737736e3992a6c0dc90f">throw_exception</a>(
<a name="l00313"></a>00313 <span class="keywordtype">int</span> what,
<a name="l00314"></a>00314 <span class="keyword">const</span> <span class="keywordtype">char</span> * function,
<a name="l00315"></a>00315 <span class="keyword">const</span> <span class="keywordtype">char</span> * file,
<a name="l00316"></a>00316 <span class="keywordtype">int</span> line)
<a name="l00317"></a>00317 {
<a name="l00318"></a>00318 <span class="keywordtype">int</span> i;
<a name="l00319"></a>00319
<a name="l00320"></a>00320 <a class="code" href="errors_8c.html#82fa865508693149b63d670fa7d7c438">exception_debug_trace</a>(<span class="stringliteral">"THROW"</span>);
<a name="l00321"></a>00321
<a name="l00322"></a>00322 <a class="code" href="source_2arith_2arithmetic__errors_8h.html#9dbd1094abce0128b2995c91d701349d">the_last_just_thrown_exception</a> = what; <span class="comment">/* for rethrow */</span>
<a name="l00323"></a>00323
<a name="l00324"></a>00324 <span class="keywordflow">for</span> (i=<a class="code" href="errors_8c.html#d63e2e9e42900784d7f912727fc90af3">exception_index</a>-1; i>=0; i--)
<a name="l00325"></a>00325 {
<a name="l00326"></a>00326 <span class="keywordflow">if</span> (<a class="code" href="errors_8c.html#5cb3be87cd274e085213bafc6eca475f">pop_callback</a>)
<a name="l00327"></a>00327 <span class="comment">/* pop with push parameters! */</span>
<a name="l00328"></a>00328 <a class="code" href="errors_8c.html#5cb3be87cd274e085213bafc6eca475f">pop_callback</a>(exception_stack[i].file,
<a name="l00329"></a>00329 exception_stack[i].function,
<a name="l00330"></a>00330 exception_stack[i].line);
<a name="l00331"></a>00331
<a name="l00332"></a>00332 <span class="keywordflow">if</span> (exception_stack[i].what & what)
<a name="l00333"></a>00333 {
<a name="l00334"></a>00334 <a class="code" href="errors_8c.html#d63e2e9e42900784d7f912727fc90af3">exception_index</a> = i;
<a name="l00335"></a>00335 <a class="code" href="errors_8c.html#3313c41a656ee03e88a9d00234cfc5ec">linear_number_of_exception_thrown</a>++;
<a name="l00336"></a>00336
<a name="l00337"></a>00337 <span class="keywordflow">if</span> (<a class="code" href="errors_8c.html#0471cbbdd66a5ee1fa3a459878c756be">linear_exception_debug_mode</a>)
<a name="l00338"></a>00338 fprintf(stderr, <span class="stringliteral">"---->[%s:%d %s (%d)/%d]\n"</span>,
<a name="l00339"></a>00339 exception_stack[i].file,
<a name="l00340"></a>00340 exception_stack[i].line,
<a name="l00341"></a>00341 exception_stack[i].function,
<a name="l00342"></a>00342 exception_stack[i].what,
<a name="l00343"></a>00343 i);
<a name="l00344"></a>00344
<a name="l00345"></a>00345 <span class="comment">/* trace some exceptions... */</span>
<a name="l00346"></a>00346 <span class="keywordflow">if</span> (<a class="code" href="errors_8c.html#3e54f04e8bd9d204f2ad4dcd32ac744f">linear_exception_verbose</a> & what)
<a name="l00347"></a>00347 fprintf(stderr, <span class="stringliteral">"exception %d/%d: %s(%s:%d) -> %s(%s:%d)\n"</span>,
<a name="l00348"></a>00348 what, exception_stack[i].what,
<a name="l00349"></a>00349 function, file, line,
<a name="l00350"></a>00350 exception_stack[i].function,
<a name="l00351"></a>00351 exception_stack[i].file,
<a name="l00352"></a>00352 exception_stack[i].line);
<a name="l00353"></a>00353
<a name="l00354"></a>00354 longjmp(exception_stack[i].where, 0);
<a name="l00355"></a>00355 }
<a name="l00356"></a>00356 }
<a name="l00357"></a>00357
<a name="l00358"></a>00358 <span class="comment">/* error. */</span>
<a name="l00359"></a>00359 <a class="code" href="errors_8c.html#8d4a2127a1edadca61c0631735922769">exception_debug_message</a>(<span class="stringliteral">"throw"</span>);
<a name="l00360"></a>00360 fprintf(stderr,
<a name="l00361"></a>00361 <span class="stringliteral">"exception not found in stack:\n"</span>
<a name="l00362"></a>00362 <span class="stringliteral">"an exception was THROWN without a proper matching CATCH\n"</span>);
<a name="l00363"></a>00363 <a class="code" href="source_2arith_2arithmetique_8h.html#5d0d562c4394d6711b3d105487cfa229">dump_exception_stack</a>();
<a name="l00364"></a>00364 abort();
<a name="l00365"></a>00365 }
<a name="l00366"></a>00366
<a name="l00367"></a><a class="code" href="errors_8c.html#0b645a3ab909b237aebbf6b31560705c">00367</a> <span class="keywordtype">void</span> <a class="code" href="errors_8c.html#0b645a3ab909b237aebbf6b31560705c">linear_initialize_exception_stack</a>(
<a name="l00368"></a>00368 <span class="keywordtype">unsigned</span> <span class="keywordtype">int</span> verbose_exceptions,
<a name="l00369"></a>00369 <a class="code" href="source_2arith_2arithmetic__errors_8h.html#afc39b4cb7a07fefadbdaeb9f8753679">exception_callback_t</a> push,
<a name="l00370"></a>00370 <a class="code" href="source_2arith_2arithmetic__errors_8h.html#afc39b4cb7a07fefadbdaeb9f8753679">exception_callback_t</a> pop)
<a name="l00371"></a>00371 {
<a name="l00372"></a>00372 <a class="code" href="errors_8c.html#3e54f04e8bd9d204f2ad4dcd32ac744f">linear_exception_verbose</a> = verbose_exceptions;
<a name="l00373"></a>00373 <a class="code" href="errors_8c.html#93de4c04224b53c462a8bd9242edd3ed">set_exception_callbacks</a>(push, pop);
<a name="l00374"></a>00374 }
</pre></div></div>
<hr size="1"><address style="text-align: right;"><small>Generated on Tue Sep 15 18:33:59 2009 for polylib by
<a href="http://www.doxygen.org/index.html">
<img src="doxygen.png" alt="doxygen" align="middle" border="0"></a> 1.5.6 </small></address>
</body>
</html>
|