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 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421
|
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/xhtml;charset=UTF-8"/>
<title>polylib: errors.c Source File</title>
<link href="tabs.css" rel="stylesheet" type="text/css"/>
<link href="doxygen.css" rel="stylesheet" type="text/css"/>
</head>
<body>
<!-- Generated by Doxygen 1.6.1 -->
<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>
<div class="tabs">
<ul>
<li><a href="files.html"><span>File List</span></a></li>
<li><a href="globals.html"><span>File Members</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"> This file is part of PolyLib.</span>
<a name="l00003"></a>00003 <span class="comment"></span>
<a name="l00004"></a>00004 <span class="comment"> PolyLib is free software: you can redistribute it and/or modify</span>
<a name="l00005"></a>00005 <span class="comment"> it under the terms of the GNU General Public License as published by</span>
<a name="l00006"></a>00006 <span class="comment"> the Free Software Foundation, either version 3 of the License, or</span>
<a name="l00007"></a>00007 <span class="comment"> (at your option) any later version.</span>
<a name="l00008"></a>00008 <span class="comment"></span>
<a name="l00009"></a>00009 <span class="comment"> PolyLib is distributed in the hope that it will be useful,</span>
<a name="l00010"></a>00010 <span class="comment"> but WITHOUT ANY WARRANTY; without even the implied warranty of</span>
<a name="l00011"></a>00011 <span class="comment"> MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the</span>
<a name="l00012"></a>00012 <span class="comment"> GNU General Public License for more details.</span>
<a name="l00013"></a>00013 <span class="comment"></span>
<a name="l00014"></a>00014 <span class="comment"> You should have received a copy of the GNU General Public License</span>
<a name="l00015"></a>00015 <span class="comment"> along with PolyLib. If not, see <http://www.gnu.org/licenses/>.</span>
<a name="l00016"></a>00016 <span class="comment">*/</span>
<a name="l00017"></a>00017
<a name="l00018"></a>00018 <span class="comment">/*</span>
<a name="l00019"></a>00019 <span class="comment"> $Id: errors.c,v 1.6 2006/03/15 19:59:37 verdoolaege Exp $</span>
<a name="l00020"></a>00020 <span class="comment"></span>
<a name="l00021"></a>00021 <span class="comment"> Exception management.</span>
<a name="l00022"></a>00022 <span class="comment"> See "arithmetic_errors.h".</span>
<a name="l00023"></a>00023 <span class="comment"></span>
<a name="l00024"></a>00024 <span class="comment"> $Log: errors.c,v $</span>
<a name="l00025"></a>00025 <span class="comment"> Revision 1.6 2006/03/15 19:59:37 verdoolaege</span>
<a name="l00026"></a>00026 <span class="comment"> arith: add some missing consts</span>
<a name="l00027"></a>00027 <span class="comment"></span>
<a name="l00028"></a>00028 <span class="comment"> Revision 1.5 2004/08/31 18:01:56 verdoolaege</span>
<a name="l00029"></a>00029 <span class="comment"> remove warning</span>
<a name="l00030"></a>00030 <span class="comment"></span>
<a name="l00031"></a>00031 <span class="comment"> Revision 1.4 2004/02/11 10:19:54 verdoolaege</span>
<a name="l00032"></a>00032 <span class="comment"> add const qualifier</span>
<a name="l00033"></a>00033 <span class="comment"></span>
<a name="l00034"></a>00034 <span class="comment"> Revision 1.3 2004/02/08 21:53:27 kienhuis</span>
<a name="l00035"></a>00035 <span class="comment"> Update from Fabien Coelho, via Bart Kienhuis</span>
<a name="l00036"></a>00036 <span class="comment"></span>
<a name="l00037"></a>00037 <span class="comment"> I've updated here in the C3/Linear library the arithmetic_error</span>
<a name="l00038"></a>00038 <span class="comment"> package that I developped (with others) to handle exceptions in C.</span>
<a name="l00039"></a>00039 <span class="comment"> It adds a simple callback feature which is needed for pips here.</span>
<a name="l00040"></a>00040 <span class="comment"> If you do not use it, it should not harm;-)</span>
<a name="l00041"></a>00041 <span class="comment"></span>
<a name="l00042"></a>00042 <span class="comment"> Revision 1.27 2003/09/04 09:40:37 coelho</span>
<a name="l00043"></a>00043 <span class="comment"> init added.</span>
<a name="l00044"></a>00044 <span class="comment"> verbosity mask added.</span>
<a name="l00045"></a>00045 <span class="comment"></span>
<a name="l00046"></a>00046 <span class="comment"> Revision 1.26 2003/09/03 14:05:20 coelho</span>
<a name="l00047"></a>00047 <span class="comment"> push/pop callbacks called.</span>
<a name="l00048"></a>00048 <span class="comment"></span>
<a name="l00049"></a>00049 <span class="comment"> Revision 1.20 2003/08/18 09:55:09 coelho</span>
<a name="l00050"></a>00050 <span class="comment"> get_exception_name added...</span>
<a name="l00051"></a>00051 <span class="comment"></span>
<a name="l00052"></a>00052 <span class="comment"> Revision 1.19 2003/06/13 13:59:07 coelho</span>
<a name="l00053"></a>00053 <span class="comment"> const out.</span>
<a name="l00054"></a>00054 <span class="comment"></span>
<a name="l00055"></a>00055 <span class="comment"> Revision 1.18 2003/06/13 13:54:47 coelho</span>
<a name="l00056"></a>00056 <span class="comment"> hop.</span>
<a name="l00057"></a>00057 <span class="comment"></span>
<a name="l00058"></a>00058 <span class="comment"> Revision 1.17 2002/04/02 08:44:54 coelho</span>
<a name="l00059"></a>00059 <span class="comment"> timeout_error ajoute.</span>
<a name="l00060"></a>00060 <span class="comment"></span>
<a name="l00061"></a>00061 <span class="comment"> Revision 1.16 2000/10/27 13:26:03 ancourt</span>
<a name="l00062"></a>00062 <span class="comment"> exception_thrown -> linear_number_of_exception_thrown</span>
<a name="l00063"></a>00063 <span class="comment"></span>
<a name="l00064"></a>00064 <span class="comment"> Revision 1.15 2000/07/27 15:21:55 coelho</span>
<a name="l00065"></a>00065 <span class="comment"> message++</span>
<a name="l00066"></a>00066 <span class="comment"></span>
<a name="l00067"></a>00067 <span class="comment"> Revision 1.14 2000/07/27 14:59:59 coelho</span>
<a name="l00068"></a>00068 <span class="comment"> trace added.</span>
<a name="l00069"></a>00069 <span class="comment"></span>
<a name="l00070"></a>00070 <span class="comment"> Revision 1.13 2000/07/26 08:41:23 coelho</span>
<a name="l00071"></a>00071 <span class="comment"> the_last_just_thrown_exception management added.</span>
<a name="l00072"></a>00072 <span class="comment"></span>
<a name="l00073"></a>00073 <span class="comment"> Revision 1.12 1998/10/26 18:48:34 coelho</span>
<a name="l00074"></a>00074 <span class="comment"> message++.</span>
<a name="l00075"></a>00075 <span class="comment"></span>
<a name="l00076"></a>00076 <span class="comment"> Revision 1.11 1998/10/26 14:38:06 coelho</span>
<a name="l00077"></a>00077 <span class="comment"> constants back in.</span>
<a name="l00078"></a>00078 <span class="comment"></span>
<a name="l00079"></a>00079 <span class="comment"> Revision 1.10 1998/10/26 14:35:47 coelho</span>
<a name="l00080"></a>00080 <span class="comment"> constants in .h.</span>
<a name="l00081"></a>00081 <span class="comment"></span>
<a name="l00082"></a>00082 <span class="comment"> Revision 1.9 1998/10/24 15:36:22 coelho</span>
<a name="l00083"></a>00083 <span class="comment"> better exception error messages...</span>
<a name="l00084"></a>00084 <span class="comment"></span>
<a name="l00085"></a>00085 <span class="comment"> Revision 1.8 1998/10/24 15:19:17 coelho</span>
<a name="l00086"></a>00086 <span class="comment"> more verbose throw...</span>
<a name="l00087"></a>00087 <span class="comment"></span>
<a name="l00088"></a>00088 <span class="comment"> Revision 1.7 1998/10/24 14:31:13 coelho</span>
<a name="l00089"></a>00089 <span class="comment"> new stack implementation.</span>
<a name="l00090"></a>00090 <span class="comment"> checks for matching catch/uncatch.</span>
<a name="l00091"></a>00091 <span class="comment"> debug mode.</span>
<a name="l00092"></a>00092 <span class="comment"></span>
<a name="l00093"></a>00093 <span class="comment"> Revision 1.6 1998/10/24 09:31:06 coelho</span>
<a name="l00094"></a>00094 <span class="comment"> RCS headers.</span>
<a name="l00095"></a>00095 <span class="comment"> 'const' tried.</span>
<a name="l00096"></a>00096 <span class="comment"></span>
<a name="l00097"></a>00097 <span class="comment">*/</span>
<a name="l00098"></a>00098
<a name="l00099"></a>00099 <span class="preprocessor">#include <stdio.h></span>
<a name="l00100"></a>00100 <span class="preprocessor">#include <stdlib.h></span>
<a name="l00101"></a>00101 <span class="preprocessor">#include <string.h></span>
<a name="l00102"></a>00102
<a name="l00103"></a>00103 <span class="preprocessor">#include "<a class="code" href="include_2polylib_2arithmetique_8h.html">arithmetique.h</a>"</span>
<a name="l00104"></a>00104
<a name="l00105"></a>00105 <span class="comment">/* global constants to designate exceptions.</span>
<a name="l00106"></a>00106 <span class="comment"> to be put in the type field bellow.</span>
<a name="l00107"></a>00107 <span class="comment"> cproto 4.6 does not line 'const'...</span>
<a name="l00108"></a>00108 <span class="comment">*/</span>
<a name="l00109"></a><a class="code" href="include_2polylib_2arithmetique_8h.html#af74135a8750c28205f819842ae8be9c9">00109</a> <span class="keywordtype">unsigned</span> <span class="keywordtype">int</span> <a class="code" href="source_2arith_2arithmetique_8h.html#af74135a8750c28205f819842ae8be9c9">overflow_error</a> = 1;
<a name="l00110"></a><a class="code" href="include_2polylib_2arithmetique_8h.html#a381d67b7ee03ff84c242d6f342fa063c">00110</a> <span class="keywordtype">unsigned</span> <span class="keywordtype">int</span> <a class="code" href="source_2arith_2arithmetique_8h.html#a381d67b7ee03ff84c242d6f342fa063c">simplex_arithmetic_error</a> = 2;
<a name="l00111"></a><a class="code" href="include_2polylib_2arithmetique_8h.html#a18b35523d2702706b86f2ab8ae2393d2">00111</a> <span class="keywordtype">unsigned</span> <span class="keywordtype">int</span> <a class="code" href="source_2arith_2arithmetique_8h.html#a18b35523d2702706b86f2ab8ae2393d2">user_exception_error</a> = 4;
<a name="l00112"></a><a class="code" href="include_2polylib_2arithmetique_8h.html#a3806d9a2c0134fd8bef8c192341a8954">00112</a> <span class="keywordtype">unsigned</span> <span class="keywordtype">int</span> <a class="code" href="source_2arith_2arithmetique_8h.html#a3806d9a2c0134fd8bef8c192341a8954">parser_exception_error</a> = 8;
<a name="l00113"></a><a class="code" href="errors_8c.html#a3cae90a91b95e5365e192179877cccf9">00113</a> <span class="keywordtype">unsigned</span> <span class="keywordtype">int</span> <a class="code" href="errors_8c.html#a3cae90a91b95e5365e192179877cccf9">timeout_error</a> = 16;
<a name="l00114"></a>00114
<a name="l00115"></a>00115 <span class="comment">/* catch all */</span>
<a name="l00116"></a><a class="code" href="include_2polylib_2arithmetique_8h.html#a3fbedc713824754a33dd94278851fe70">00116</a> <span class="keywordtype">unsigned</span> <span class="keywordtype">int</span> <a class="code" href="source_2arith_2arithmetique_8h.html#a3fbedc713824754a33dd94278851fe70">any_exception_error</a> = ~0;
<a name="l00117"></a>00117
<a name="l00118"></a>00118
<a name="l00119"></a>00119 <span class="comment">/*</span>
<a name="l00120"></a>00120 <span class="comment"> * On a few systems, type boolean and/or its values FALSE, TRUE may appear</span>
<a name="l00121"></a>00121 <span class="comment"> * in standard header files. Or you may have conflicts with application-</span>
<a name="l00122"></a>00122 <span class="comment"> * specific header files that you want to include together with these files.</span>
<a name="l00123"></a>00123 <span class="comment"> * Defining HAVE_BOOLEAN before including jpeglib.h should make it work.</span>
<a name="l00124"></a>00124 <span class="comment"> */</span>
<a name="l00125"></a>00125
<a name="l00126"></a>00126 <span class="preprocessor">#ifndef HAVE_BOOLEAN</span>
<a name="l00127"></a><a class="code" href="errors_8c.html#a621c38f1f10a1c565d897e3178b16d6e">00127</a> <span class="preprocessor"></span><span class="keyword">typedef</span> <span class="keywordtype">int</span> <a class="code" href="errors_8c.html#a621c38f1f10a1c565d897e3178b16d6e">boolean</a>;
<a name="l00128"></a>00128 <span class="preprocessor">#endif</span>
<a name="l00129"></a>00129 <span class="preprocessor"></span><span class="preprocessor">#ifndef FALSE </span><span class="comment">/* in case these macros already exist */</span>
<a name="l00130"></a><a class="code" href="errors_8c.html#aa93f0eb578d23995850d61f7d61c55c1">00130</a> <span class="preprocessor">#define FALSE 0 </span><span class="comment">/* values of boolean */</span>
<a name="l00131"></a>00131 <span class="preprocessor">#endif</span>
<a name="l00132"></a>00132 <span class="preprocessor"></span><span class="preprocessor">#ifndef TRUE</span>
<a name="l00133"></a><a class="code" href="errors_8c.html#aa8cecfc5c5c054d2875c03e77b7be15d">00133</a> <span class="preprocessor"></span><span class="preprocessor">#define TRUE 1</span>
<a name="l00134"></a>00134 <span class="preprocessor"></span><span class="preprocessor">#endif</span>
<a name="l00135"></a>00135 <span class="preprocessor"></span>
<a name="l00136"></a><a class="code" href="errors_8c.html#a79edc2c9a0ce7b3159417f9130a14def">00136</a> <span class="keyword">const</span> <span class="keywordtype">char</span> *<a class="code" href="errors_8c.html#a79edc2c9a0ce7b3159417f9130a14def">get_exception_name</a>(<span class="keywordtype">unsigned</span> <span class="keywordtype">int</span> exception)
<a name="l00137"></a>00137 {
<a name="l00138"></a>00138 <span class="keywordflow">if</span> (exception==<a class="code" href="source_2arith_2arithmetique_8h.html#af74135a8750c28205f819842ae8be9c9">overflow_error</a>)
<a name="l00139"></a>00139 <span class="keywordflow">return</span> <span class="stringliteral">"overflow_error exception"</span>;
<a name="l00140"></a>00140 <span class="keywordflow">if</span> (exception==<a class="code" href="source_2arith_2arithmetique_8h.html#a381d67b7ee03ff84c242d6f342fa063c">simplex_arithmetic_error</a>)
<a name="l00141"></a>00141 <span class="keywordflow">return</span> <span class="stringliteral">"simplex_arithmetic_error exception"</span>;
<a name="l00142"></a>00142 <span class="keywordflow">if</span> (exception==<a class="code" href="source_2arith_2arithmetique_8h.html#a18b35523d2702706b86f2ab8ae2393d2">user_exception_error</a>)
<a name="l00143"></a>00143 <span class="keywordflow">return</span> <span class="stringliteral">"user_exception_error exception"</span>;
<a name="l00144"></a>00144 <span class="keywordflow">if</span> (exception==<a class="code" href="source_2arith_2arithmetique_8h.html#a3806d9a2c0134fd8bef8c192341a8954">parser_exception_error</a>)
<a name="l00145"></a>00145 <span class="keywordflow">return</span> <span class="stringliteral">"parser_exception_error exception"</span>;
<a name="l00146"></a>00146 <span class="keywordflow">if</span> (exception==<a class="code" href="errors_8c.html#a3cae90a91b95e5365e192179877cccf9">timeout_error</a>)
<a name="l00147"></a>00147 <span class="keywordflow">return</span> <span class="stringliteral">"timeout_error exception"</span>;
<a name="l00148"></a>00148 <span class="keywordflow">if</span> (exception==<a class="code" href="source_2arith_2arithmetique_8h.html#a3fbedc713824754a33dd94278851fe70">any_exception_error</a>)
<a name="l00149"></a>00149 <span class="keywordflow">return</span> <span class="stringliteral">"all exceptions mask"</span>;
<a name="l00150"></a>00150
<a name="l00151"></a>00151 <span class="keywordflow">return</span> <span class="stringliteral">"unknown or mixed exception"</span>;
<a name="l00152"></a>00152 }
<a name="l00153"></a>00153
<a name="l00154"></a>00154 <span class="comment">/* keep track of last thrown exception for RETHROW()</span>
<a name="l00155"></a>00155 <span class="comment"> */</span>
<a name="l00156"></a><a class="code" href="include_2polylib_2arithmetique_8h.html#a9dbd1094abce0128b2995c91d701349d">00156</a> <span class="keywordtype">unsigned</span> <span class="keywordtype">int</span> <a class="code" href="source_2arith_2arithmetic__errors_8h.html#a9dbd1094abce0128b2995c91d701349d">the_last_just_thrown_exception</a> = 0;
<a name="l00157"></a>00157
<a name="l00158"></a>00158 <span class="comment">/* whether to run in debug mode (that is to trace catch/uncatch/throw)</span>
<a name="l00159"></a>00159 <span class="comment"> */</span>
<a name="l00160"></a><a class="code" href="errors_8c.html#a0471cbbdd66a5ee1fa3a459878c756be">00160</a> <span class="keyword">static</span> <span class="keywordtype">int</span> <a class="code" href="errors_8c.html#a0471cbbdd66a5ee1fa3a459878c756be">linear_exception_debug_mode</a> = <a class="code" href="errors_8c.html#aa93f0eb578d23995850d61f7d61c55c1">FALSE</a>;
<a name="l00161"></a><a class="code" href="errors_8c.html#a3e54f04e8bd9d204f2ad4dcd32ac744f">00161</a> <span class="keyword">static</span> <span class="keywordtype">unsigned</span> <span class="keywordtype">int</span> <a class="code" href="errors_8c.html#a3e54f04e8bd9d204f2ad4dcd32ac744f">linear_exception_verbose</a> = 1 | 2 | 16 ;
<a name="l00162"></a>00162
<a name="l00163"></a>00163 <span class="comment">/* A structure for the exception stack.</span>
<a name="l00164"></a>00164 <span class="comment"> */</span>
<a name="l00165"></a><a class="code" href="structlinear__exception__holder.html">00165</a> <span class="keyword">typedef</span> <span class="keyword">struct </span>
<a name="l00166"></a>00166 {
<a name="l00167"></a>00167 <span class="comment">/* exception type.</span>
<a name="l00168"></a>00168 <span class="comment"> */</span>
<a name="l00169"></a><a class="code" href="structlinear__exception__holder.html#af58917e56c6831b227e006673710fe5d">00169</a> <span class="keywordtype">int</span> what;
<a name="l00170"></a>00170
<a name="l00171"></a>00171 <span class="comment">/* where to jump to.</span>
<a name="l00172"></a>00172 <span class="comment"> */</span>
<a name="l00173"></a><a class="code" href="structlinear__exception__holder.html#ad9a2b584f896181a0578b05c6cb7cc3e">00173</a> jmp_buf where;
<a name="l00174"></a>00174
<a name="l00175"></a>00175 <span class="comment">/* location of the CATCH to be matched against the UNCATCH.</span>
<a name="l00176"></a>00176 <span class="comment"> */</span>
<a name="l00177"></a><a class="code" href="structlinear__exception__holder.html#afcc50c683b77f6a21e07b49ac2bc81f3">00177</a> <span class="keyword">const</span> <span class="keywordtype">char</span> * function;
<a name="l00178"></a><a class="code" href="structlinear__exception__holder.html#a4da979c2531ecea486a511e6540c031a">00178</a> <span class="keyword">const</span> <span class="keywordtype">char</span> * file;
<a name="l00179"></a><a class="code" href="structlinear__exception__holder.html#a03fe66cae813ea2b3328f04878aec61b">00179</a> <span class="keywordtype">int</span> line;
<a name="l00180"></a>00180 }
<a name="l00181"></a>00181 <a class="code" href="structlinear__exception__holder.html">linear_exception_holder</a>;
<a name="l00182"></a>00182
<a name="l00183"></a>00183 <span class="comment">/* exception stack.</span>
<a name="l00184"></a>00184 <span class="comment"> maximum extension.</span>
<a name="l00185"></a>00185 <span class="comment"> current index (next available bucket)</span>
<a name="l00186"></a>00186 <span class="comment"> */</span>
<a name="l00187"></a><a class="code" href="errors_8c.html#aaec70e82a04c1102db5789b0c8092055">00187</a> <span class="preprocessor">#define MAX_STACKED_CONTEXTS 64</span>
<a name="l00188"></a><a class="code" href="errors_8c.html#ae7d6c7530e7505f175ee1efaf0dd33e1">00188</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#ae7d6c7530e7505f175ee1efaf0dd33e1">exception_stack</a>[<a class="code" href="errors_8c.html#aaec70e82a04c1102db5789b0c8092055">MAX_STACKED_CONTEXTS</a>];
<a name="l00189"></a><a class="code" href="errors_8c.html#ad63e2e9e42900784d7f912727fc90af3">00189</a> <span class="keyword">static</span> <span class="keywordtype">int</span> <a class="code" href="errors_8c.html#ad63e2e9e42900784d7f912727fc90af3">exception_index</a> = 0;
<a name="l00190"></a>00190
<a name="l00191"></a>00191 <span class="comment">/* callbacks...</span>
<a name="l00192"></a>00192 <span class="comment"> */</span>
<a name="l00193"></a><a class="code" href="errors_8c.html#a949dce609af01654ccefedf9473eac29">00193</a> <span class="keyword">static</span> <a class="code" href="source_2arith_2arithmetic__errors_8h.html#aafc39b4cb7a07fefadbdaeb9f8753679">exception_callback_t</a> <a class="code" href="errors_8c.html#a949dce609af01654ccefedf9473eac29">push_callback</a> = NULL;
<a name="l00194"></a><a class="code" href="errors_8c.html#a5cb3be87cd274e085213bafc6eca475f">00194</a> <span class="keyword">static</span> <a class="code" href="source_2arith_2arithmetic__errors_8h.html#aafc39b4cb7a07fefadbdaeb9f8753679">exception_callback_t</a> <a class="code" href="errors_8c.html#a5cb3be87cd274e085213bafc6eca475f">pop_callback</a> = NULL;
<a name="l00195"></a>00195
<a name="l00196"></a><a class="code" href="errors_8c.html#a93de4c04224b53c462a8bd9242edd3ed">00196</a> <span class="keywordtype">void</span> <a class="code" href="errors_8c.html#a93de4c04224b53c462a8bd9242edd3ed">set_exception_callbacks</a>(<a class="code" href="source_2arith_2arithmetic__errors_8h.html#aafc39b4cb7a07fefadbdaeb9f8753679">exception_callback_t</a> push,
<a name="l00197"></a>00197 <a class="code" href="source_2arith_2arithmetic__errors_8h.html#aafc39b4cb7a07fefadbdaeb9f8753679">exception_callback_t</a> pop)
<a name="l00198"></a>00198 {
<a name="l00199"></a>00199 <span class="keywordflow">if</span> (<a class="code" href="errors_8c.html#a949dce609af01654ccefedf9473eac29">push_callback</a>!=NULL || <a class="code" href="errors_8c.html#a5cb3be87cd274e085213bafc6eca475f">pop_callback</a>!=NULL)
<a name="l00200"></a>00200 {
<a name="l00201"></a>00201 fprintf(stderr, <span class="stringliteral">"exception callbacks already defined! (%p, %p)\n"</span>,
<a name="l00202"></a>00202 <a class="code" href="errors_8c.html#a949dce609af01654ccefedf9473eac29">push_callback</a>, <a class="code" href="errors_8c.html#a5cb3be87cd274e085213bafc6eca475f">pop_callback</a>);
<a name="l00203"></a>00203 abort();
<a name="l00204"></a>00204 }
<a name="l00205"></a>00205
<a name="l00206"></a>00206 <a class="code" href="errors_8c.html#a949dce609af01654ccefedf9473eac29">push_callback</a> = push;
<a name="l00207"></a>00207 <a class="code" href="errors_8c.html#a5cb3be87cd274e085213bafc6eca475f">pop_callback</a> = pop;
<a name="l00208"></a>00208 }
<a name="l00209"></a>00209
<a name="l00210"></a>00210 <span class="comment">/* total number of exceptions thrown, for statistics.</span>
<a name="l00211"></a>00211 <span class="comment"> */</span>
<a name="l00212"></a><a class="code" href="errors_8c.html#a3313c41a656ee03e88a9d00234cfc5ec">00212</a> <span class="keywordtype">int</span> <a class="code" href="errors_8c.html#a3313c41a656ee03e88a9d00234cfc5ec">linear_number_of_exception_thrown</a> = 0;
<a name="l00213"></a>00213
<a name="l00214"></a>00214 <span class="comment">/* dump stack</span>
<a name="l00215"></a>00215 <span class="comment"> */</span>
<a name="l00216"></a><a class="code" href="include_2polylib_2arithmetique_8h.html#a95032703f9a53198ae5f188a05836557">00216</a> <span class="keywordtype">void</span> <a class="code" href="source_2arith_2arithmetique_8h.html#a95032703f9a53198ae5f188a05836557">dump_exception_stack_to_file</a>(FILE * f)
<a name="l00217"></a>00217 {
<a name="l00218"></a>00218 <span class="keywordtype">int</span> i;
<a name="l00219"></a>00219 fprintf(f, <span class="stringliteral">"[dump_exception_stack_to_file] size=%d\n"</span>, <a class="code" href="errors_8c.html#ad63e2e9e42900784d7f912727fc90af3">exception_index</a>);
<a name="l00220"></a>00220 <span class="keywordflow">for</span> (i=0; i<<a class="code" href="errors_8c.html#ad63e2e9e42900784d7f912727fc90af3">exception_index</a>; i++)
<a name="l00221"></a>00221 {
<a name="l00222"></a>00222 fprintf(f,
<a name="l00223"></a>00223 <span class="stringliteral">"%d: [%s:%d in %s (%d)]\n"</span>,
<a name="l00224"></a>00224 i,
<a name="l00225"></a>00225 exception_stack[i].file,
<a name="l00226"></a>00226 exception_stack[i].line,
<a name="l00227"></a>00227 exception_stack[i].function,
<a name="l00228"></a>00228 exception_stack[i].what);
<a name="l00229"></a>00229 }
<a name="l00230"></a>00230 fprintf(f, <span class="stringliteral">"\n"</span>);
<a name="l00231"></a>00231 }
<a name="l00232"></a>00232
<a name="l00233"></a><a class="code" href="include_2polylib_2arithmetique_8h.html#a5d0d562c4394d6711b3d105487cfa229">00233</a> <span class="keywordtype">void</span> <a class="code" href="source_2arith_2arithmetique_8h.html#a5d0d562c4394d6711b3d105487cfa229">dump_exception_stack</a>()
<a name="l00234"></a>00234 {
<a name="l00235"></a>00235 <a class="code" href="source_2arith_2arithmetique_8h.html#a95032703f9a53198ae5f188a05836557">dump_exception_stack_to_file</a>(stderr);
<a name="l00236"></a>00236 }
<a name="l00237"></a>00237
<a name="l00238"></a><a class="code" href="errors_8c.html#a8d4a2127a1edadca61c0631735922769">00238</a> <span class="preprocessor">#define exception_debug_message(type) \</span>
<a name="l00239"></a>00239 <span class="preprocessor"> fprintf(stderr, "%s[%s:%d %s (%d)/%d]\n", \</span>
<a name="l00240"></a>00240 <span class="preprocessor"> type, file, line, function, what, exception_index) </span>
<a name="l00241"></a>00241 <span class="preprocessor"></span>
<a name="l00242"></a><a class="code" href="errors_8c.html#a82fa865508693149b63d670fa7d7c438">00242</a> <span class="preprocessor">#define exception_debug_trace(type) \</span>
<a name="l00243"></a>00243 <span class="preprocessor"> if (linear_exception_debug_mode) { exception_debug_message(type); }</span>
<a name="l00244"></a>00244 <span class="preprocessor"></span>
<a name="l00245"></a>00245
<a name="l00246"></a>00246 <span class="comment">/* push a what exception on stack.</span>
<a name="l00247"></a>00247 <span class="comment"> */</span>
<a name="l00248"></a>00248 jmp_buf *
<a name="l00249"></a><a class="code" href="include_2polylib_2arithmetique_8h.html#a6c4868122de3ac9f2dddafc35d583021">00249</a> <a class="code" href="source_2arith_2arithmetique_8h.html#a6c4868122de3ac9f2dddafc35d583021">push_exception_on_stack</a>(
<a name="l00250"></a>00250 <span class="keywordtype">int</span> what,
<a name="l00251"></a>00251 <span class="keyword">const</span> <span class="keywordtype">char</span> * function,
<a name="l00252"></a>00252 <span class="keyword">const</span> <span class="keywordtype">char</span> * file,
<a name="l00253"></a>00253 <span class="keywordtype">int</span> line)
<a name="l00254"></a>00254 {
<a name="l00255"></a>00255 <a class="code" href="errors_8c.html#a82fa865508693149b63d670fa7d7c438">exception_debug_trace</a>(<span class="stringliteral">"PUSH "</span>);
<a name="l00256"></a>00256
<a name="l00257"></a>00257 <span class="keywordflow">if</span> (<a class="code" href="errors_8c.html#ad63e2e9e42900784d7f912727fc90af3">exception_index</a>==<a class="code" href="errors_8c.html#aaec70e82a04c1102db5789b0c8092055">MAX_STACKED_CONTEXTS</a>)
<a name="l00258"></a>00258 {
<a name="l00259"></a>00259 <a class="code" href="errors_8c.html#a8d4a2127a1edadca61c0631735922769">exception_debug_message</a>(<span class="stringliteral">"push"</span>);
<a name="l00260"></a>00260 fprintf(stderr, <span class="stringliteral">"exception stack overflow\n"</span>);
<a name="l00261"></a>00261 <a class="code" href="source_2arith_2arithmetique_8h.html#a5d0d562c4394d6711b3d105487cfa229">dump_exception_stack</a>();
<a name="l00262"></a>00262 abort();
<a name="l00263"></a>00263 }
<a name="l00264"></a>00264
<a name="l00265"></a>00265 <span class="keywordflow">if</span> (<a class="code" href="errors_8c.html#a949dce609af01654ccefedf9473eac29">push_callback</a>) <a class="code" href="errors_8c.html#a949dce609af01654ccefedf9473eac29">push_callback</a>(file, function, line);
<a name="l00266"></a>00266
<a name="l00267"></a>00267 <a class="code" href="source_2arith_2arithmetic__errors_8h.html#a9dbd1094abce0128b2995c91d701349d">the_last_just_thrown_exception</a> = 0;
<a name="l00268"></a>00268
<a name="l00269"></a>00269 exception_stack[<a class="code" href="errors_8c.html#ad63e2e9e42900784d7f912727fc90af3">exception_index</a>].<a class="code" href="structlinear__exception__holder.html#af58917e56c6831b227e006673710fe5d">what</a> = what;
<a name="l00270"></a>00270 exception_stack[<a class="code" href="errors_8c.html#ad63e2e9e42900784d7f912727fc90af3">exception_index</a>].<a class="code" href="structlinear__exception__holder.html#afcc50c683b77f6a21e07b49ac2bc81f3">function</a> = function;
<a name="l00271"></a>00271 exception_stack[<a class="code" href="errors_8c.html#ad63e2e9e42900784d7f912727fc90af3">exception_index</a>].<a class="code" href="structlinear__exception__holder.html#a4da979c2531ecea486a511e6540c031a">file</a> = file;
<a name="l00272"></a>00272 exception_stack[<a class="code" href="errors_8c.html#ad63e2e9e42900784d7f912727fc90af3">exception_index</a>].<a class="code" href="structlinear__exception__holder.html#a03fe66cae813ea2b3328f04878aec61b">line</a> = line;
<a name="l00273"></a>00273
<a name="l00274"></a>00274 <span class="keywordflow">return</span> & exception_stack[<a class="code" href="errors_8c.html#ad63e2e9e42900784d7f912727fc90af3">exception_index</a>++].<a class="code" href="structlinear__exception__holder.html#ad9a2b584f896181a0578b05c6cb7cc3e">where</a>;
<a name="l00275"></a>00275 }
<a name="l00276"></a>00276
<a name="l00277"></a>00277 <span class="preprocessor">#if !defined(same_string_p)</span>
<a name="l00278"></a><a class="code" href="errors_8c.html#ac32f3590ee78925a812d8718f28e9a2b">00278</a> <span class="preprocessor"></span><span class="preprocessor">#define same_string_p(s1, s2) (strcmp((s1),(s2))==0)</span>
<a name="l00279"></a>00279 <span class="preprocessor"></span><span class="preprocessor">#endif</span>
<a name="l00280"></a>00280 <span class="preprocessor"></span>
<a name="l00281"></a>00281 <span class="comment">/* pop a what exception.</span>
<a name="l00282"></a>00282 <span class="comment"> check for any mismatch!</span>
<a name="l00283"></a>00283 <span class="comment"> */</span>
<a name="l00284"></a>00284 <span class="keywordtype">void</span>
<a name="l00285"></a><a class="code" href="include_2polylib_2arithmetique_8h.html#a66795100cf9a30f6cf85a7c67d7c8050">00285</a> <a class="code" href="source_2arith_2arithmetique_8h.html#a66795100cf9a30f6cf85a7c67d7c8050">pop_exception_from_stack</a>(
<a name="l00286"></a>00286 <span class="keywordtype">int</span> what,
<a name="l00287"></a>00287 <span class="keyword">const</span> <span class="keywordtype">char</span> * function,
<a name="l00288"></a>00288 <span class="keyword">const</span> <span class="keywordtype">char</span> * file,
<a name="l00289"></a>00289 <span class="keywordtype">int</span> line)
<a name="l00290"></a>00290 {
<a name="l00291"></a>00291 <a class="code" href="errors_8c.html#a82fa865508693149b63d670fa7d7c438">exception_debug_trace</a>(<span class="stringliteral">"POP "</span>);
<a name="l00292"></a>00292
<a name="l00293"></a>00293 <span class="keywordflow">if</span> (<a class="code" href="errors_8c.html#ad63e2e9e42900784d7f912727fc90af3">exception_index</a>==0)
<a name="l00294"></a>00294 {
<a name="l00295"></a>00295 <a class="code" href="errors_8c.html#a8d4a2127a1edadca61c0631735922769">exception_debug_message</a>(<span class="stringliteral">"pop"</span>);
<a name="l00296"></a>00296 fprintf(stderr, <span class="stringliteral">"exception stack underflow\n"</span>);
<a name="l00297"></a>00297 <a class="code" href="source_2arith_2arithmetique_8h.html#a5d0d562c4394d6711b3d105487cfa229">dump_exception_stack</a>();
<a name="l00298"></a>00298 abort();
<a name="l00299"></a>00299 }
<a name="l00300"></a>00300
<a name="l00301"></a>00301 <span class="keywordflow">if</span> (<a class="code" href="errors_8c.html#a5cb3be87cd274e085213bafc6eca475f">pop_callback</a>) <a class="code" href="errors_8c.html#a5cb3be87cd274e085213bafc6eca475f">pop_callback</a>(file, function, line);
<a name="l00302"></a>00302
<a name="l00303"></a>00303 <a class="code" href="errors_8c.html#ad63e2e9e42900784d7f912727fc90af3">exception_index</a>--;
<a name="l00304"></a>00304 <a class="code" href="source_2arith_2arithmetic__errors_8h.html#a9dbd1094abce0128b2995c91d701349d">the_last_just_thrown_exception</a> = 0;
<a name="l00305"></a>00305
<a name="l00306"></a>00306 <span class="keywordflow">if</span> ((exception_stack[<a class="code" href="errors_8c.html#ad63e2e9e42900784d7f912727fc90af3">exception_index</a>].what != what) ||
<a name="l00307"></a>00307 !<a class="code" href="errors_8c.html#ac32f3590ee78925a812d8718f28e9a2b">same_string_p</a>(exception_stack[<a class="code" href="errors_8c.html#ad63e2e9e42900784d7f912727fc90af3">exception_index</a>].file, file) ||
<a name="l00308"></a>00308 !<a class="code" href="errors_8c.html#ac32f3590ee78925a812d8718f28e9a2b">same_string_p</a>(exception_stack[<a class="code" href="errors_8c.html#ad63e2e9e42900784d7f912727fc90af3">exception_index</a>].function, function))
<a name="l00309"></a>00309 {
<a name="l00310"></a>00310 <a class="code" href="errors_8c.html#a8d4a2127a1edadca61c0631735922769">exception_debug_message</a>(<span class="stringliteral">"pop"</span>);
<a name="l00311"></a>00311 fprintf(stderr,
<a name="l00312"></a>00312 <span class="stringliteral">"exception stack mismatch at depth=%d:\n"</span>
<a name="l00313"></a>00313 <span class="stringliteral">" CATCH: %s:%d in %s (%d)\n"</span>
<a name="l00314"></a>00314 <span class="stringliteral">" UNCATCH: %s:%d in %s (%d)\n"</span>,
<a name="l00315"></a>00315 <a class="code" href="errors_8c.html#ad63e2e9e42900784d7f912727fc90af3">exception_index</a>,
<a name="l00316"></a>00316 exception_stack[<a class="code" href="errors_8c.html#ad63e2e9e42900784d7f912727fc90af3">exception_index</a>].file,
<a name="l00317"></a>00317 exception_stack[<a class="code" href="errors_8c.html#ad63e2e9e42900784d7f912727fc90af3">exception_index</a>].line,
<a name="l00318"></a>00318 exception_stack[<a class="code" href="errors_8c.html#ad63e2e9e42900784d7f912727fc90af3">exception_index</a>].function,
<a name="l00319"></a>00319 exception_stack[<a class="code" href="errors_8c.html#ad63e2e9e42900784d7f912727fc90af3">exception_index</a>].what,
<a name="l00320"></a>00320 file, line, function, what);
<a name="l00321"></a>00321 <a class="code" href="source_2arith_2arithmetique_8h.html#a5d0d562c4394d6711b3d105487cfa229">dump_exception_stack</a>();
<a name="l00322"></a>00322 abort();
<a name="l00323"></a>00323 }
<a name="l00324"></a>00324 }
<a name="l00325"></a>00325
<a name="l00326"></a>00326 <span class="comment">/* throws an exception of a given type by searching for </span>
<a name="l00327"></a>00327 <span class="comment"> the specified 'what' in the current exception stack.</span>
<a name="l00328"></a>00328 <span class="comment">*/</span>
<a name="l00329"></a><a class="code" href="include_2polylib_2arithmetique_8h.html#a904f0eb5107e737736e3992a6c0dc90f">00329</a> <span class="keywordtype">void</span> <a class="code" href="source_2arith_2arithmetique_8h.html#a904f0eb5107e737736e3992a6c0dc90f">throw_exception</a>(
<a name="l00330"></a>00330 <span class="keywordtype">int</span> what,
<a name="l00331"></a>00331 <span class="keyword">const</span> <span class="keywordtype">char</span> * function,
<a name="l00332"></a>00332 <span class="keyword">const</span> <span class="keywordtype">char</span> * file,
<a name="l00333"></a>00333 <span class="keywordtype">int</span> line)
<a name="l00334"></a>00334 {
<a name="l00335"></a>00335 <span class="keywordtype">int</span> i;
<a name="l00336"></a>00336
<a name="l00337"></a>00337 <a class="code" href="errors_8c.html#a82fa865508693149b63d670fa7d7c438">exception_debug_trace</a>(<span class="stringliteral">"THROW"</span>);
<a name="l00338"></a>00338
<a name="l00339"></a>00339 <a class="code" href="source_2arith_2arithmetic__errors_8h.html#a9dbd1094abce0128b2995c91d701349d">the_last_just_thrown_exception</a> = what; <span class="comment">/* for rethrow */</span>
<a name="l00340"></a>00340
<a name="l00341"></a>00341 <span class="keywordflow">for</span> (i=<a class="code" href="errors_8c.html#ad63e2e9e42900784d7f912727fc90af3">exception_index</a>-1; i>=0; i--)
<a name="l00342"></a>00342 {
<a name="l00343"></a>00343 <span class="keywordflow">if</span> (<a class="code" href="errors_8c.html#a5cb3be87cd274e085213bafc6eca475f">pop_callback</a>)
<a name="l00344"></a>00344 <span class="comment">/* pop with push parameters! */</span>
<a name="l00345"></a>00345 <a class="code" href="errors_8c.html#a5cb3be87cd274e085213bafc6eca475f">pop_callback</a>(exception_stack[i].file,
<a name="l00346"></a>00346 exception_stack[i].function,
<a name="l00347"></a>00347 exception_stack[i].line);
<a name="l00348"></a>00348
<a name="l00349"></a>00349 <span class="keywordflow">if</span> (exception_stack[i].what & what)
<a name="l00350"></a>00350 {
<a name="l00351"></a>00351 <a class="code" href="errors_8c.html#ad63e2e9e42900784d7f912727fc90af3">exception_index</a> = i;
<a name="l00352"></a>00352 <a class="code" href="errors_8c.html#a3313c41a656ee03e88a9d00234cfc5ec">linear_number_of_exception_thrown</a>++;
<a name="l00353"></a>00353
<a name="l00354"></a>00354 <span class="keywordflow">if</span> (<a class="code" href="errors_8c.html#a0471cbbdd66a5ee1fa3a459878c756be">linear_exception_debug_mode</a>)
<a name="l00355"></a>00355 fprintf(stderr, <span class="stringliteral">"---->[%s:%d %s (%d)/%d]\n"</span>,
<a name="l00356"></a>00356 exception_stack[i].file,
<a name="l00357"></a>00357 exception_stack[i].line,
<a name="l00358"></a>00358 exception_stack[i].function,
<a name="l00359"></a>00359 exception_stack[i].what,
<a name="l00360"></a>00360 i);
<a name="l00361"></a>00361
<a name="l00362"></a>00362 <span class="comment">/* trace some exceptions... */</span>
<a name="l00363"></a>00363 <span class="keywordflow">if</span> (<a class="code" href="errors_8c.html#a3e54f04e8bd9d204f2ad4dcd32ac744f">linear_exception_verbose</a> & what)
<a name="l00364"></a>00364 fprintf(stderr, <span class="stringliteral">"exception %d/%d: %s(%s:%d) -> %s(%s:%d)\n"</span>,
<a name="l00365"></a>00365 what, exception_stack[i].what,
<a name="l00366"></a>00366 function, file, line,
<a name="l00367"></a>00367 exception_stack[i].function,
<a name="l00368"></a>00368 exception_stack[i].file,
<a name="l00369"></a>00369 exception_stack[i].line);
<a name="l00370"></a>00370
<a name="l00371"></a>00371 longjmp(exception_stack[i].where, 0);
<a name="l00372"></a>00372 }
<a name="l00373"></a>00373 }
<a name="l00374"></a>00374
<a name="l00375"></a>00375 <span class="comment">/* error. */</span>
<a name="l00376"></a>00376 <a class="code" href="errors_8c.html#a8d4a2127a1edadca61c0631735922769">exception_debug_message</a>(<span class="stringliteral">"throw"</span>);
<a name="l00377"></a>00377 fprintf(stderr,
<a name="l00378"></a>00378 <span class="stringliteral">"exception not found in stack:\n"</span>
<a name="l00379"></a>00379 <span class="stringliteral">"an exception was THROWN without a proper matching CATCH\n"</span>);
<a name="l00380"></a>00380 <a class="code" href="source_2arith_2arithmetique_8h.html#a5d0d562c4394d6711b3d105487cfa229">dump_exception_stack</a>();
<a name="l00381"></a>00381 abort();
<a name="l00382"></a>00382 }
<a name="l00383"></a>00383
<a name="l00384"></a><a class="code" href="errors_8c.html#a0b645a3ab909b237aebbf6b31560705c">00384</a> <span class="keywordtype">void</span> <a class="code" href="errors_8c.html#a0b645a3ab909b237aebbf6b31560705c">linear_initialize_exception_stack</a>(
<a name="l00385"></a>00385 <span class="keywordtype">unsigned</span> <span class="keywordtype">int</span> verbose_exceptions,
<a name="l00386"></a>00386 <a class="code" href="source_2arith_2arithmetic__errors_8h.html#aafc39b4cb7a07fefadbdaeb9f8753679">exception_callback_t</a> push,
<a name="l00387"></a>00387 <a class="code" href="source_2arith_2arithmetic__errors_8h.html#aafc39b4cb7a07fefadbdaeb9f8753679">exception_callback_t</a> pop)
<a name="l00388"></a>00388 {
<a name="l00389"></a>00389 <a class="code" href="errors_8c.html#a3e54f04e8bd9d204f2ad4dcd32ac744f">linear_exception_verbose</a> = verbose_exceptions;
<a name="l00390"></a>00390 <a class="code" href="errors_8c.html#a93de4c04224b53c462a8bd9242edd3ed">set_exception_callbacks</a>(push, pop);
<a name="l00391"></a>00391 }
</pre></div></div>
<hr size="1"/><address style="text-align: right;"><small>Generated on Wed Nov 25 17:45:25 2009 for polylib by
<a href="http://www.doxygen.org/index.html">
<img class="footer" src="doxygen.png" alt="doxygen"/></a> 1.6.1 </small></address>
</body>
</html>
|