/usr/share/shedskin/lib/builtin/exception.hpp is in shedskin 0.9.4-1.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
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 | /* Copyright 2005-2011 Mark Dufour and contributors; License Expat (See LICENSE) */
/* exceptions */
#ifndef WIN32
// stacktrace.h (c) 2008, Timo Bingmann from http://idlebox.net/
// published under the WTFPL v2.0
/** Print a demangled stack backtrace of the caller function to FILE* out. */
static void print_traceback(FILE *out)
{
fprintf(out, "\nTraceback (most recent call last):\n");
// storage array for stack trace address data
void* addrlist[64];
// retrieve current stack addresses
int addrlen = backtrace(addrlist, sizeof(addrlist) / sizeof(void*));
if (addrlen == 0) {
fprintf(out, " <empty, possibly corrupt>\n");
return;
}
// resolve addresses into strings containing "filename(function+address)",
// this array must be free()-ed
char** symbollist = backtrace_symbols(addrlist, addrlen);
// allocate string which will be filled with the demangled function name
size_t funcnamesize = 256;
char* funcname = (char*)malloc(funcnamesize);
// iterate over the returned symbol lines. skip the first, it is the
// address of this function.
for (int i = addrlen-1; i > 0; i--)
{
char *begin_name = 0, *begin_offset = 0, *end_offset = 0;
// find parentheses and +address offset surrounding the mangled name:
// ./module(function+0x15c) [0x8048a6d]
for (char *p = symbollist[i]; *p; ++p)
{
if (*p == '(')
begin_name = p;
else if (*p == '+')
begin_offset = p;
else if (*p == ')' && begin_offset) {
end_offset = p;
break;
}
}
if (begin_name && begin_offset && end_offset
&& begin_name < begin_offset)
{
*begin_name++ = '\0';
*begin_offset++ = '\0';
*end_offset = '\0';
// mangled name is now in [begin_name, begin_offset) and caller
// offset in [begin_offset, end_offset). now apply
// __cxa_demangle():
int status;
char* ret = abi::__cxa_demangle(begin_name,
funcname, &funcnamesize, &status);
if (status == 0) {
funcname = ret; // use possibly realloc()-ed string
if(strncmp(funcname, "__shedskin__::", 14) != 0)
//fprintf(out, " %s : %s+%s\n", symbollist[i], funcname, begin_offset);
fprintf(out, " %s : %s\n", symbollist[i], funcname);
}
else {
// demangling failed. Output function name as a C function with
// no arguments.
//fprintf(out, " %s : %s()+%s\n",
// symbollist[i], begin_name, begin_offset);
}
}
else
{
// couldn't parse the line? print the whole line.
//fprintf(out, " %s\n", symbollist[i]);
}
}
free(funcname);
free(symbollist);
}
#endif
extern class_ *cl_stopiteration, *cl_assertionerror, *cl_eoferror, *cl_floatingpointerror, *cl_keyerror, *cl_indexerror, *cl_typeerror, *cl_ioerror, *cl_valueerror, *cl_zerodivisionerror, *cl_keyboardinterrupt, *cl_memoryerror, *cl_nameerror, *cl_notimplementederror, *cl_oserror, *cl_overflowerror, *cl_runtimeerror, *cl_syntaxerror, *cl_systemerror, *cl_systemexit;
class BaseException : public pyobj {
public:
str *message;
BaseException(str *message=0) {
__init__(message);
}
void __init__(str *message) {
if(message)
this->message = message;
else
this->message = new str("");
}
void __init__(void *) { /* XXX test 148 */
this->message = new str("");
}
str *__repr__() {
return __add_strs(4, this->__class__->__name__, new str("('"), message, new str("',)"));
}
str *__str__() {
return message;
}
};
class Exception: public BaseException {
public:
Exception(str *message=0) : BaseException(message) {}
#ifdef __SS_BIND
virtual PyObject *__to_py__() { return PyExc_Exception; }
#endif
};
class StopIteration : public Exception {
public:
StopIteration(str *message=0) : Exception(message) { this->__class__ = cl_stopiteration; }
};
class StandardError : public Exception {
public:
StandardError(str *message=0) : Exception(message) {}
};
class AssertionError : public StandardError {
public:
AssertionError(str *message=0) : StandardError(message) { this->__class__ = cl_assertionerror; }
#ifdef __SS_BIND
PyObject *__to_py__() { return PyExc_AssertionError; }
#endif
};
class EOFError : public StandardError {
public:
EOFError(str *message=0) : StandardError(message) { this->__class__ = cl_eoferror; }
#ifdef __SS_BIND
PyObject *__to_py__() { return PyExc_EOFError; }
#endif
};
class FloatingPointError : public StandardError {
public:
FloatingPointError(str *message=0) : StandardError(message) { this->__class__ = cl_floatingpointerror; }
#ifdef __SS_BIND
PyObject *__to_py__() { return PyExc_FloatingPointError; }
#endif
};
class KeyError : public StandardError {
public:
KeyError(str *message=0) : StandardError(message) { this->__class__ = cl_keyerror; }
#ifdef __SS_BIND
PyObject *__to_py__() { return PyExc_KeyError; }
#endif
};
class IndexError : public StandardError {
public:
IndexError(str *message=0) : StandardError(message) { this->__class__ = cl_indexerror; }
#ifdef __SS_BIND
PyObject *__to_py__() { return PyExc_IndexError; }
#endif
};
class TypeError : public StandardError {
public:
TypeError(str *message=0) : StandardError(message) { this->__class__ = cl_typeerror; }
#ifdef __SS_BIND
PyObject *__to_py__() { return PyExc_TypeError; }
#endif
};
class IOError : public StandardError {
public:
int __ss_errno;
str *filename;
str *message;
str *strerror;
IOError(str *message=0);
str *__str__();
str *__repr__();
#ifdef __SS_BIND
PyObject *__to_py__() { return PyExc_IOError; }
#endif
};
class KeyboardInterrupt : public BaseException {
public:
KeyboardInterrupt(str *message=0) : BaseException(message) { this->__class__ = cl_keyboardinterrupt; }
#ifdef __SS_BIND
PyObject *__to_py__() { return PyExc_KeyboardInterrupt; }
#endif
};
class MemoryError : public StandardError {
public:
MemoryError(str *message=0) : StandardError(message) { this->__class__ = cl_memoryerror; }
#ifdef __SS_BIND
PyObject *__to_py__() { return PyExc_MemoryError; }
#endif
};
class NameError : public StandardError {
public:
NameError(str *message=0) : StandardError(message) { this->__class__ = cl_nameerror; }
#ifdef __SS_BIND
PyObject *__to_py__() { return PyExc_NameError; }
#endif
};
class NotImplementedError : public StandardError {
public:
NotImplementedError(str *message=0) : StandardError(message) { this->__class__ = cl_notimplementederror; }
#ifdef __SS_BIND
PyObject *__to_py__() { return PyExc_NotImplementedError; }
#endif
};
class OSError : public StandardError {
public:
int __ss_errno;
str *filename;
str *message;
str *strerror;
OSError(str *message=0);
str *__str__();
str *__repr__();
#ifdef __SS_BIND
PyObject *__to_py__() { return PyExc_OSError; }
#endif
};
class OverflowError : public StandardError {
public:
OverflowError(str *message=0) : StandardError(message) { this->__class__ = cl_overflowerror; }
#ifdef __SS_BIND
PyObject *__to_py__() { return PyExc_OverflowError; }
#endif
};
class RuntimeError : public StandardError {
public:
RuntimeError(str *message=0) : StandardError(message) { this->__class__ = cl_runtimeerror; }
#ifdef __SS_BIND
PyObject *__to_py__() { return PyExc_RuntimeError; }
#endif
};
class SyntaxError : public StandardError {
public:
SyntaxError(str *message=0) : StandardError(message) { this->__class__ = cl_syntaxerror; }
#ifdef __SS_BIND
PyObject *__to_py__() { return PyExc_SyntaxError; }
#endif
};
class SystemError : public StandardError {
public:
SystemError(str *message=0) : StandardError(message) { this->__class__ = cl_systemerror; }
#ifdef __SS_BIND
PyObject *__to_py__() { return PyExc_SystemError; }
#endif
};
class SystemExit : public BaseException {
public:
int code;
int show_message;
SystemExit(__ss_int code) {
this->__class__ = cl_systemexit;
this->code = code;
this->message = __str(this->code);
this->show_message = 0;
}
SystemExit() {
this->__class__ = cl_systemexit;
this->code = 0;
this->message = __str(this->code);
this->show_message = 0;
}
SystemExit(str *message) : BaseException(message) {
this->__class__ = cl_systemexit;
this->code = 1;
this->show_message = 1;
}
#ifdef __SS_BIND
PyObject *__to_py__() { return PyExc_SystemExit; }
#endif
};
class ValueError : public StandardError {
public:
ValueError(str *message=0) : StandardError(message) { this->__class__ = cl_valueerror; }
#ifdef __SS_BIND
PyObject *__to_py__() { return PyExc_ValueError; }
#endif
};
class ZeroDivisionError : public StandardError {
public:
ZeroDivisionError(str *message=0) : StandardError(message) { this->__class__ = cl_zerodivisionerror; }
#ifdef __SS_BIND
PyObject *__to_py__() { return PyExc_ZeroDivisionError; }
#endif
};
|