Numworks Epsilon  1.4.1
Graphing Calculator Operating System
objexcept.c
Go to the documentation of this file.
1 /*
2  * This file is part of the MicroPython project, http://micropython.org/
3  *
4  * The MIT License (MIT)
5  *
6  * Copyright (c) 2013, 2014 Damien P. George
7  *
8  * Permission is hereby granted, free of charge, to any person obtaining a copy
9  * of this software and associated documentation files (the "Software"), to deal
10  * in the Software without restriction, including without limitation the rights
11  * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
12  * copies of the Software, and to permit persons to whom the Software is
13  * furnished to do so, subject to the following conditions:
14  *
15  * The above copyright notice and this permission notice shall be included in
16  * all copies or substantial portions of the Software.
17  *
18  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
19  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
20  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
21  * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
22  * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
23  * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
24  * THE SOFTWARE.
25  */
26 
27 #include <string.h>
28 #include <stdarg.h>
29 #include <assert.h>
30 #include <stdio.h>
31 
32 #include "py/objlist.h"
33 #include "py/objstr.h"
34 #include "py/objtuple.h"
35 #include "py/objtype.h"
36 #include "py/runtime.h"
37 #include "py/gc.h"
38 #include "py/mperrno.h"
39 
40 // Number of items per traceback entry (file, line, block)
41 #define TRACEBACK_ENTRY_LEN (3)
42 
43 // Number of traceback entries to reserve in the emergency exception buffer
44 #define EMG_TRACEBACK_ALLOC (2 * TRACEBACK_ENTRY_LEN)
45 
46 // Instance of MemoryError exception - needed by mp_malloc_fail
48 
49 // Optionally allocated buffer for storing the first argument of an exception
50 // allocated when the heap is locked.
51 #if MICROPY_ENABLE_EMERGENCY_EXCEPTION_BUF
52 # if MICROPY_EMERGENCY_EXCEPTION_BUF_SIZE > 0
53 #define mp_emergency_exception_buf_size MICROPY_EMERGENCY_EXCEPTION_BUF_SIZE
54 
56  // Nothing to do since the buffer was declared statically. We put this
57  // definition here so that the calling code can call this function
58  // regardless of how its configured (makes the calling code a bit cleaner).
59 }
60 
61 #else
62 #define mp_emergency_exception_buf_size MP_STATE_VM(mp_emergency_exception_buf_size)
63 
65  mp_emergency_exception_buf_size = 0;
66  MP_STATE_VM(mp_emergency_exception_buf) = NULL;
67 }
68 
70  mp_int_t size = mp_obj_get_int(size_in);
71  void *buf = NULL;
72  if (size > 0) {
73  buf = m_new(byte, size);
74  }
75 
76  int old_size = mp_emergency_exception_buf_size;
77  void *old_buf = MP_STATE_VM(mp_emergency_exception_buf);
78 
79  // Update the 2 variables atomically so that an interrupt can't occur
80  // between the assignments.
81  mp_uint_t atomic_state = MICROPY_BEGIN_ATOMIC_SECTION();
82  mp_emergency_exception_buf_size = size;
83  MP_STATE_VM(mp_emergency_exception_buf) = buf;
84  MICROPY_END_ATOMIC_SECTION(atomic_state);
85 
86  if (old_buf != NULL) {
87  m_del(byte, old_buf, old_size);
88  }
89  return mp_const_none;
90 }
91 #endif
92 #endif // MICROPY_ENABLE_EMERGENCY_EXCEPTION_BUF
93 
94 // Instance of GeneratorExit exception - needed by generator.close()
95 // This would belong to objgenerator.c, but to keep mp_obj_exception_t
96 // definition module-private so far, have it here.
98 
102  bool is_subclass = kind & PRINT_EXC_SUBCLASS;
103  if (!is_subclass && (k == PRINT_REPR || k == PRINT_EXC)) {
104  mp_print_str(print, qstr_str(o->base.type->name));
105  }
106 
107  if (k == PRINT_EXC) {
108  mp_print_str(print, ": ");
109  }
110 
111  if (k == PRINT_STR || k == PRINT_EXC) {
112  if (o->args == NULL || o->args->len == 0) {
113  mp_print_str(print, "");
114  return;
115  } else if (o->args->len == 1) {
116  #if MICROPY_PY_UERRNO
117  // try to provide a nice OSError error message
118  if (o->base.type == &mp_type_OSError && MP_OBJ_IS_SMALL_INT(o->args->items[0])) {
119  qstr qst = mp_errno_to_str(o->args->items[0]);
120  if (qst != MP_QSTR_NULL) {
121  mp_printf(print, "[Errno %d] %q", MP_OBJ_SMALL_INT_VALUE(o->args->items[0]), qst);
122  return;
123  }
124  }
125  #endif
126  mp_obj_print_helper(print, o->args->items[0], PRINT_STR);
127  return;
128  }
129  }
130  mp_obj_tuple_print(print, MP_OBJ_FROM_PTR(o->args), kind);
131 }
132 
133 mp_obj_t mp_obj_exception_make_new(const mp_obj_type_t *type, size_t n_args, size_t n_kw, const mp_obj_t *args) {
134  mp_arg_check_num(n_args, n_kw, 0, MP_OBJ_FUN_ARGS_MAX, false);
135 
136  // Try to allocate memory for the exception, with fallback to emergency exception object
138  if (o_exc == NULL) {
139  o_exc = &MP_STATE_VM(mp_emergency_exception_obj);
140  }
141 
142  // Populate the exception object
143  o_exc->base.type = type;
144  o_exc->traceback_data = NULL;
145 
146  mp_obj_tuple_t *o_tuple;
147  if (n_args == 0) {
148  // No args, can use the empty tuple straightaway
150  } else {
151  // Try to allocate memory for the tuple containing the args
152  o_tuple = m_new_obj_var_maybe(mp_obj_tuple_t, mp_obj_t, n_args);
153 
154  #if MICROPY_ENABLE_EMERGENCY_EXCEPTION_BUF
155  // If we are called by mp_obj_new_exception_msg_varg then it will have
156  // reserved room (after the traceback data) for a tuple with 1 element.
157  // Otherwise we are free to use the whole buffer after the traceback data.
158  if (o_tuple == NULL && mp_emergency_exception_buf_size >=
159  EMG_TRACEBACK_ALLOC * sizeof(size_t) + sizeof(mp_obj_tuple_t) + n_args * sizeof(mp_obj_t)) {
160  o_tuple = (mp_obj_tuple_t*)
161  ((uint8_t*)MP_STATE_VM(mp_emergency_exception_buf) + EMG_TRACEBACK_ALLOC * sizeof(size_t));
162  }
163  #endif
164 
165  if (o_tuple == NULL) {
166  // No memory for a tuple, fallback to an empty tuple
168  } else {
169  // Have memory for a tuple so populate it
170  o_tuple->base.type = &mp_type_tuple;
171  o_tuple->len = n_args;
172  memcpy(o_tuple->items, args, n_args * sizeof(mp_obj_t));
173  }
174  }
175 
176  // Store the tuple of args in the exception object
177  o_exc->args = o_tuple;
178 
179  return MP_OBJ_FROM_PTR(o_exc);
180 }
181 
182 // Get exception "value" - that is, first argument, or None
184  mp_obj_exception_t *self = MP_OBJ_TO_PTR(self_in);
185  if (self->args->len == 0) {
186  return mp_const_none;
187  } else {
188  return self->args->items[0];
189  }
190 }
191 
193  mp_obj_exception_t *self = MP_OBJ_TO_PTR(self_in);
194  if (dest[0] != MP_OBJ_NULL) {
195  // store/delete attribute
196  if (attr == MP_QSTR___traceback__ && dest[1] == mp_const_none) {
197  // We allow 'exc.__traceback__ = None' assignment as low-level
198  // optimization of pre-allocating exception instance and raising
199  // it repeatedly - this avoids memory allocation during raise.
200  // However, uPy will keep adding traceback entries to such
201  // exception instance, so before throwing it, traceback should
202  // be cleared like above.
203  self->traceback_len = 0;
204  dest[0] = MP_OBJ_NULL; // indicate success
205  }
206  return;
207  }
208  if (attr == MP_QSTR_args) {
209  dest[0] = MP_OBJ_FROM_PTR(self->args);
210  } else if (self->base.type == &mp_type_StopIteration && attr == MP_QSTR_value) {
211  dest[0] = mp_obj_exception_get_value(self_in);
212  }
213 }
214 
215 STATIC mp_obj_t exc___init__(size_t n_args, const mp_obj_t *args) {
217  mp_obj_t argst = mp_obj_new_tuple(n_args - 1, args + 1);
218  self->args = MP_OBJ_TO_PTR(argst);
219  return mp_const_none;
220 }
222 
224  { MP_ROM_QSTR(MP_QSTR___init__), MP_ROM_PTR(&exc___init___obj) },
225 };
226 
228 
230  { &mp_type_type },
231  .name = MP_QSTR_BaseException,
232  .print = mp_obj_exception_print,
233  .make_new = mp_obj_exception_make_new,
234  .attr = exception_attr,
235  .locals_dict = (mp_obj_dict_t*)&exc_locals_dict,
236 };
237 
238 #define MP_DEFINE_EXCEPTION(exc_name, base_name) \
239 const mp_obj_type_t mp_type_ ## exc_name = { \
240  { &mp_type_type }, \
241  .name = MP_QSTR_ ## exc_name, \
242  .print = mp_obj_exception_print, \
243  .make_new = mp_obj_exception_make_new, \
244  .attr = exception_attr, \
245  .parent = &mp_type_ ## base_name, \
246 };
247 
248 // List of all exceptions, arranged as in the table at:
249 // http://docs.python.org/3/library/exceptions.html
250 MP_DEFINE_EXCEPTION(SystemExit, BaseException)
251 MP_DEFINE_EXCEPTION(KeyboardInterrupt, BaseException)
252 MP_DEFINE_EXCEPTION(GeneratorExit, BaseException)
253 MP_DEFINE_EXCEPTION(Exception, BaseException)
254  #if MICROPY_PY_ASYNC_AWAIT
255  MP_DEFINE_EXCEPTION(StopAsyncIteration, Exception)
256  #endif
257  MP_DEFINE_EXCEPTION(StopIteration, Exception)
258  MP_DEFINE_EXCEPTION(ArithmeticError, Exception)
259  //MP_DEFINE_EXCEPTION(FloatingPointError, ArithmeticError)
260  MP_DEFINE_EXCEPTION(OverflowError, ArithmeticError)
261  MP_DEFINE_EXCEPTION(ZeroDivisionError, ArithmeticError)
262  MP_DEFINE_EXCEPTION(AssertionError, Exception)
263  MP_DEFINE_EXCEPTION(AttributeError, Exception)
264  //MP_DEFINE_EXCEPTION(BufferError, Exception)
265  //MP_DEFINE_EXCEPTION(EnvironmentError, Exception) use OSError instead
266  MP_DEFINE_EXCEPTION(EOFError, Exception)
267  MP_DEFINE_EXCEPTION(ImportError, Exception)
268  //MP_DEFINE_EXCEPTION(IOError, Exception) use OSError instead
269  MP_DEFINE_EXCEPTION(LookupError, Exception)
270  MP_DEFINE_EXCEPTION(IndexError, LookupError)
271  MP_DEFINE_EXCEPTION(KeyError, LookupError)
272  MP_DEFINE_EXCEPTION(MemoryError, Exception)
273  MP_DEFINE_EXCEPTION(NameError, Exception)
274  /*
275  MP_DEFINE_EXCEPTION(UnboundLocalError, NameError)
276  */
277  MP_DEFINE_EXCEPTION(OSError, Exception)
278 #if MICROPY_PY_BUILTINS_TIMEOUTERROR
279  MP_DEFINE_EXCEPTION(TimeoutError, OSError)
280 #endif
281  /*
282  MP_DEFINE_EXCEPTION(BlockingIOError, OSError)
283  MP_DEFINE_EXCEPTION(ChildProcessError, OSError)
284  MP_DEFINE_EXCEPTION(ConnectionError, OSError)
285  MP_DEFINE_EXCEPTION(BrokenPipeError, ConnectionError)
286  MP_DEFINE_EXCEPTION(ConnectionAbortedError, ConnectionError)
287  MP_DEFINE_EXCEPTION(ConnectionRefusedError, ConnectionError)
288  MP_DEFINE_EXCEPTION(ConnectionResetError, ConnectionError)
289  MP_DEFINE_EXCEPTION(InterruptedError, OSError)
290  MP_DEFINE_EXCEPTION(IsADirectoryError, OSError)
291  MP_DEFINE_EXCEPTION(NotADirectoryError, OSError)
292  MP_DEFINE_EXCEPTION(PermissionError, OSError)
293  MP_DEFINE_EXCEPTION(ProcessLookupError, OSError)
294  MP_DEFINE_EXCEPTION(FileExistsError, OSError)
295  MP_DEFINE_EXCEPTION(FileNotFoundError, OSError)
296  MP_DEFINE_EXCEPTION(ReferenceError, Exception)
297  */
298  MP_DEFINE_EXCEPTION(RuntimeError, Exception)
299  MP_DEFINE_EXCEPTION(NotImplementedError, RuntimeError)
300  MP_DEFINE_EXCEPTION(SyntaxError, Exception)
301  MP_DEFINE_EXCEPTION(IndentationError, SyntaxError)
302  /*
303  MP_DEFINE_EXCEPTION(TabError, IndentationError)
304  */
305  //MP_DEFINE_EXCEPTION(SystemError, Exception)
306  MP_DEFINE_EXCEPTION(TypeError, Exception)
307 #if MICROPY_EMIT_NATIVE
308  MP_DEFINE_EXCEPTION(ViperTypeError, TypeError)
309 #endif
310  MP_DEFINE_EXCEPTION(ValueError, Exception)
311 #if MICROPY_PY_BUILTINS_STR_UNICODE
312  MP_DEFINE_EXCEPTION(UnicodeError, ValueError)
313  //TODO: Implement more UnicodeError subclasses which take arguments
314 #endif
315  /*
316  MP_DEFINE_EXCEPTION(Warning, Exception)
317  MP_DEFINE_EXCEPTION(DeprecationWarning, Warning)
318  MP_DEFINE_EXCEPTION(PendingDeprecationWarning, Warning)
319  MP_DEFINE_EXCEPTION(RuntimeWarning, Warning)
320  MP_DEFINE_EXCEPTION(SyntaxWarning, Warning)
321  MP_DEFINE_EXCEPTION(UserWarning, Warning)
322  MP_DEFINE_EXCEPTION(FutureWarning, Warning)
323  MP_DEFINE_EXCEPTION(ImportWarning, Warning)
324  MP_DEFINE_EXCEPTION(UnicodeWarning, Warning)
325  MP_DEFINE_EXCEPTION(BytesWarning, Warning)
326  MP_DEFINE_EXCEPTION(ResourceWarning, Warning)
327  */
328 
330  return mp_obj_new_exception_args(exc_type, 0, NULL);
331 }
332 
333 // "Optimized" version for common(?) case of having 1 exception arg
335  return mp_obj_new_exception_args(exc_type, 1, &arg);
336 }
337 
338 mp_obj_t mp_obj_new_exception_args(const mp_obj_type_t *exc_type, size_t n_args, const mp_obj_t *args) {
340  return exc_type->make_new(exc_type, n_args, 0, args);
341 }
342 
343 mp_obj_t mp_obj_new_exception_msg(const mp_obj_type_t *exc_type, const char *msg) {
344  return mp_obj_new_exception_msg_varg(exc_type, msg);
345 }
346 
347 // The following struct and function implement a simple printer that conservatively
348 // allocates memory and truncates the output data if no more memory can be obtained.
349 // It leaves room for a null byte at the end of the buffer.
350 
353  size_t alloc;
354  size_t len;
356 };
357 
358 STATIC void exc_add_strn(void *data, const char *str, size_t len) {
359  struct _exc_printer_t *pr = data;
360  if (pr->len + len >= pr->alloc) {
361  // Not enough room for data plus a null byte so try to grow the buffer
362  if (pr->allow_realloc) {
363  size_t new_alloc = pr->alloc + len + 16;
364  byte *new_buf = m_renew_maybe(byte, pr->buf, pr->alloc, new_alloc, true);
365  if (new_buf == NULL) {
366  pr->allow_realloc = false;
367  len = pr->alloc - pr->len - 1;
368  } else {
369  pr->alloc = new_alloc;
370  pr->buf = new_buf;
371  }
372  } else {
373  len = pr->alloc - pr->len - 1;
374  }
375  }
376  memcpy(pr->buf + pr->len, str, len);
377  pr->len += len;
378 }
379 
380 mp_obj_t mp_obj_new_exception_msg_varg(const mp_obj_type_t *exc_type, const char *fmt, ...) {
381  assert(fmt != NULL);
382 
383  // Check that the given type is an exception type
385 
386  // Try to allocate memory for the message
388  size_t o_str_alloc = strlen(fmt) + 1;
389  byte *o_str_buf = m_new_maybe(byte, o_str_alloc);
390 
391  bool used_emg_buf = false;
392  #if MICROPY_ENABLE_EMERGENCY_EXCEPTION_BUF
393  // If memory allocation failed and there is an emergency buffer then try to use
394  // that buffer to store the string object and its data (at least 16 bytes for
395  // the string data), reserving room at the start for the traceback and 1-tuple.
396  if ((o_str == NULL || o_str_buf == NULL)
397  && mp_emergency_exception_buf_size >= EMG_TRACEBACK_ALLOC * sizeof(size_t)
398  + sizeof(mp_obj_tuple_t) + sizeof(mp_obj_t) + sizeof(mp_obj_str_t) + 16) {
399  used_emg_buf = true;
400  o_str = (mp_obj_str_t*)((uint8_t*)MP_STATE_VM(mp_emergency_exception_buf)
401  + EMG_TRACEBACK_ALLOC * sizeof(size_t) + sizeof(mp_obj_tuple_t) + sizeof(mp_obj_t));
402  o_str_buf = (byte*)&o_str[1];
403  o_str_alloc = (uint8_t*)MP_STATE_VM(mp_emergency_exception_buf)
404  + mp_emergency_exception_buf_size - o_str_buf;
405  }
406  #endif
407 
408  if (o_str == NULL) {
409  // No memory for the string object so create the exception with no args
410  return mp_obj_exception_make_new(exc_type, 0, 0, NULL);
411  }
412 
413  if (o_str_buf == NULL) {
414  // No memory for the string buffer: assume that the fmt string is in ROM
415  // and use that data as the data of the string
416  o_str->len = o_str_alloc - 1; // will be equal to strlen(fmt)
417  o_str->data = (const byte*)fmt;
418  } else {
419  // We have some memory to format the string
420  struct _exc_printer_t exc_pr = {!used_emg_buf, o_str_alloc, 0, o_str_buf};
421  mp_print_t print = {&exc_pr, exc_add_strn};
422  va_list ap;
423  va_start(ap, fmt);
424  mp_vprintf(&print, fmt, ap);
425  va_end(ap);
426  exc_pr.buf[exc_pr.len] = '\0';
427  o_str->len = exc_pr.len;
428  o_str->data = exc_pr.buf;
429  }
430 
431  // Create the string object and call mp_obj_exception_make_new to create the exception
432  o_str->base.type = &mp_type_str;
433  o_str->hash = qstr_compute_hash(o_str->data, o_str->len);
434  mp_obj_t arg = MP_OBJ_FROM_PTR(o_str);
435  return mp_obj_exception_make_new(exc_type, 1, 0, &arg);
436 }
437 
438 // return true if the given object is an exception type
440  if (MP_OBJ_IS_TYPE(self_in, &mp_type_type)) {
441  // optimisation when self_in is a builtin exception
442  mp_obj_type_t *self = MP_OBJ_TO_PTR(self_in);
443  if (self->make_new == mp_obj_exception_make_new) {
444  return true;
445  }
446  }
448 }
449 
450 // return true if the given object is an instance of an exception type
453 }
454 
455 // Return true if exception (type or instance) is a subclass of given
456 // exception type. Assumes exc_type is a subclass of BaseException, as
457 // defined by mp_obj_is_exception_type(exc_type).
459  // if exc is an instance of an exception, then extract and use its type
460  if (mp_obj_is_exception_instance(exc)) {
461  exc = MP_OBJ_FROM_PTR(mp_obj_get_type(exc));
462  }
463  return mp_obj_is_subclass_fast(exc, exc_type);
464 }
465 
466 // traceback handling functions
467 
468 #define GET_NATIVE_EXCEPTION(self, self_in) \
469  /* make sure self_in is an exception instance */ \
470  assert(mp_obj_is_exception_instance(self_in)); \
471  mp_obj_exception_t *self; \
472  if (mp_obj_is_native_exception_instance(self_in)) { \
473  self = MP_OBJ_TO_PTR(self_in); \
474  } else { \
475  self = MP_OBJ_TO_PTR(((mp_obj_instance_t*)MP_OBJ_TO_PTR(self_in))->subobj[0]); \
476  }
477 
479  GET_NATIVE_EXCEPTION(self, self_in);
480  // just set the traceback to the null object
481  // we don't want to call any memory management functions here
482  self->traceback_data = NULL;
483 }
484 
485 void mp_obj_exception_add_traceback(mp_obj_t self_in, qstr file, size_t line, qstr block) {
486  GET_NATIVE_EXCEPTION(self, self_in);
487 
488  // append this traceback info to traceback data
489  // if memory allocation fails (eg because gc is locked), just return
490 
491  if (self->traceback_data == NULL) {
492  self->traceback_data = m_new_maybe(size_t, TRACEBACK_ENTRY_LEN);
493  if (self->traceback_data == NULL) {
494  #if MICROPY_ENABLE_EMERGENCY_EXCEPTION_BUF
495  if (mp_emergency_exception_buf_size >= EMG_TRACEBACK_ALLOC * sizeof(size_t)) {
496  // There is room in the emergency buffer for traceback data
497  size_t *tb = (size_t*)MP_STATE_VM(mp_emergency_exception_buf);
498  self->traceback_data = tb;
499  self->traceback_alloc = EMG_TRACEBACK_ALLOC;
500  } else {
501  // Can't allocate and no room in emergency buffer
502  return;
503  }
504  #else
505  // Can't allocate
506  return;
507  #endif
508  } else {
509  // Allocated the traceback data on the heap
510  self->traceback_alloc = TRACEBACK_ENTRY_LEN;
511  }
512  self->traceback_len = 0;
513  } else if (self->traceback_len + TRACEBACK_ENTRY_LEN > self->traceback_alloc) {
514  #if MICROPY_ENABLE_EMERGENCY_EXCEPTION_BUF
515  if (self->traceback_data == (size_t*)MP_STATE_VM(mp_emergency_exception_buf)) {
516  // Can't resize the emergency buffer
517  return;
518  }
519  #endif
520  // be conservative with growing traceback data
521  size_t *tb_data = m_renew_maybe(size_t, self->traceback_data, self->traceback_alloc,
522  self->traceback_alloc + TRACEBACK_ENTRY_LEN, true);
523  if (tb_data == NULL) {
524  return;
525  }
526  self->traceback_data = tb_data;
527  self->traceback_alloc += TRACEBACK_ENTRY_LEN;
528  }
529 
530  size_t *tb_data = &self->traceback_data[self->traceback_len];
531  self->traceback_len += TRACEBACK_ENTRY_LEN;
532  tb_data[0] = file;
533  tb_data[1] = line;
534  tb_data[2] = block;
535 }
536 
537 void mp_obj_exception_get_traceback(mp_obj_t self_in, size_t *n, size_t **values) {
538  GET_NATIVE_EXCEPTION(self, self_in);
539 
540  if (self->traceback_data == NULL) {
541  *n = 0;
542  *values = NULL;
543  } else {
544  *n = self->traceback_len;
545  *values = self->traceback_data;
546  }
547 }
#define m_renew_maybe(type, ptr, old_num, new_num, allow_move)
Definition: misc.h:76
size_t len
Definition: objtuple.h:33
mp_obj_t mp_obj_new_exception_msg(const mp_obj_type_t *exc_type, const char *msg)
Definition: objexcept.c:343
intptr_t mp_int_t
Definition: mpconfigport.h:73
#define va_end(ap)
Definition: stdarg.h:8
uintptr_t mp_uint_t
Definition: mpconfigport.h:74
mp_obj_base_t base
Definition: objtuple.h:32
mp_obj_t mp_obj_exception_make_new(const mp_obj_type_t *type, size_t n_args, size_t n_kw, const mp_obj_t *args)
Definition: objexcept.c:133
const char * qstr_str(qstr q)
Definition: qstr.c:278
mp_obj_t mp_obj_new_tuple(size_t n, const mp_obj_t *items)
Definition: objtuple.c:235
mp_obj_base_t base
Definition: objexcept.h:33
#define assert(e)
Definition: assert.h:9
#define mp_const_none
Definition: obj.h:614
def data
Definition: i18n.py:176
mp_make_new_fun_t make_new
Definition: obj.h:484
mp_obj_t mp_alloc_emergency_exception_buf(mp_obj_t size_in)
#define MP_OBJ_IS_TYPE(o, t)
Definition: obj.h:254
STATIC const uint8_t attr[]
Definition: unicode.c:51
void mp_obj_exception_get_traceback(mp_obj_t self_in, size_t *n, size_t **values)
Definition: objexcept.c:537
#define m_del(type, ptr, num)
Definition: misc.h:77
size_t len
Definition: objstr.h:35
#define GET_NATIVE_EXCEPTION(self, self_in)
Definition: objexcept.c:468
#define TRACEBACK_ENTRY_LEN
Definition: objexcept.c:41
mp_obj_t mp_obj_new_exception_arg1(const mp_obj_type_t *exc_type, mp_obj_t arg)
Definition: objexcept.c:334
unsigned int size_t
Definition: stddef.h:7
const mp_obj_type_t mp_type_StopIteration
mp_obj_t mp_obj_new_exception(const mp_obj_type_t *exc_type)
Definition: objexcept.c:329
mp_obj_type_t * mp_obj_get_type(mp_const_obj_t o_in)
Definition: obj.c:40
int mp_print_str(const mp_print_t *print, const char *str)
Definition: mpprint.c:53
#define MP_ROM_QSTR(q)
Definition: obj.h:241
#define MP_OBJ_FROM_PTR(p)
Definition: obj.h:233
void mp_arg_check_num(size_t n_args, size_t n_kw, size_t n_args_min, size_t n_args_max, bool takes_kw)
Definition: argcheck.c:32
#define MP_ROM_PTR(p)
Definition: obj.h:242
void mp_obj_tuple_print(const mp_print_t *print, mp_obj_t o_in, mp_print_kind_t kind)
Definition: objtuple.c:36
void mp_obj_exception_clear_traceback(mp_obj_t self_in)
Definition: objexcept.c:478
mp_obj_t mp_obj_new_exception_msg_varg(const mp_obj_type_t *exc_type, const char *fmt,...)
Definition: objexcept.c:380
#define MP_STATE_VM(x)
Definition: mpstate.h:241
unsigned char uint8_t
Definition: stdint.h:4
#define EMG_TRACEBACK_ALLOC
Definition: objexcept.c:44
mp_int_t mp_obj_get_int(mp_const_obj_t arg)
Definition: obj.c:225
#define STATIC
Definition: mpconfig.h:1178
#define MP_OBJ_SMALL_INT_VALUE(o)
Definition: obj.h:86
mp_obj_t items[]
Definition: objtuple.h:34
bool mp_obj_is_subclass_fast(mp_const_obj_t object, mp_const_obj_t classinfo)
Definition: objtype.c:1143
mp_print_kind_t
Definition: obj.h:412
#define MP_DEFINE_EXCEPTION(exc_name, base_name)
Definition: objexcept.c:238
#define MICROPY_BEGIN_ATOMIC_SECTION()
Definition: mpconfig.h:1169
size_t strlen(const char *s)
Definition: strlen.c:3
#define m_new_maybe(type, num)
Definition: misc.h:58
uint64_t mp_const_obj_t
Definition: obj.h:40
#define NULL
Definition: stddef.h:4
#define MP_OBJ_NULL
Definition: obj.h:73
mp_obj_tuple_t * args
Definition: objexcept.h:37
const mp_obj_type_t mp_type_OSError
mp_obj_base_t base
Definition: objstr.h:32
const byte * data
Definition: objstr.h:36
void mp_init_emergency_exception_buf(void)
void mp_obj_print_helper(const mp_print_t *print, mp_obj_t o_in, mp_print_kind_t kind)
Definition: obj.c:59
size_t qstr
Definition: qstr.h:48
const mp_obj_exception_t mp_const_GeneratorExit_obj
Definition: objexcept.c:97
const mp_obj_type_t mp_type_str
Definition: objstr.c:1950
const mp_obj_type_t mp_type_MemoryError
const mp_obj_type_t mp_type_GeneratorExit
args
Definition: i18n.py:175
#define m_new_obj_maybe(type)
Definition: misc.h:61
mp_uint_t hash
Definition: objstr.h:33
bool allow_realloc
Definition: objexcept.c:352
bool mp_obj_is_exception_type(mp_obj_t self_in)
Definition: objexcept.c:439
STATIC mp_obj_t exc___init__(size_t n_args, const mp_obj_t *args)
Definition: objexcept.c:215
STATIC void exc_add_strn(void *data, const char *str, size_t len)
Definition: objexcept.c:358
unsigned char byte
Definition: misc.h:37
size_t * traceback_data
Definition: objexcept.h:36
const mp_obj_type_t mp_type_type
Definition: objtype.c:969
const mp_obj_type_t mp_type_BaseException
Definition: objexcept.c:229
STATIC const mp_rom_map_elem_t exc_locals_dict_table[]
Definition: objexcept.c:223
STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(exc___init___obj, 1, MP_OBJ_FUN_ARGS_MAX, exc___init__)
mp_uint_t qstr_compute_hash(const byte *data, size_t len)
Definition: qstr.c:84
bool mp_obj_is_exception_instance(mp_obj_t self_in)
Definition: objexcept.c:451
mp_obj_t mp_obj_new_exception_args(const mp_obj_type_t *exc_type, size_t n_args, const mp_obj_t *args)
Definition: objexcept.c:338
__builtin_va_list va_list
Definition: stdarg.h:4
#define MP_OBJ_TO_PTR(o)
Definition: obj.h:228
Definition: obj.h:413
const mp_obj_type_t mp_type_tuple
Definition: objtuple.c:220
void mp_obj_exception_add_traceback(mp_obj_t self_in, qstr file, size_t line, qstr block)
Definition: objexcept.c:485
#define MP_OBJ_FUN_ARGS_MAX
Definition: obj.h:793
#define MICROPY_END_ATOMIC_SECTION(state)
Definition: mpconfig.h:1172
int mp_vprintf(const mp_print_t *print, const char *fmt, va_list args)
Definition: mpprint.c:388
qstr name
Definition: obj.h:478
uint64_t mp_obj_t
Definition: obj.h:39
bool mp_obj_exception_match(mp_obj_t exc, mp_const_obj_t exc_type)
Definition: objexcept.c:458
int mp_printf(const mp_print_t *print, const char *fmt,...)
Definition: mpprint.c:380
STATIC void mp_obj_exception_print(const mp_print_t *print, mp_obj_t o_in, mp_print_kind_t kind)
Definition: objexcept.c:99
#define va_start(ap, last)
Definition: stdarg.h:6
Definition: obj.h:415
STATIC void exception_attr(mp_obj_t self_in, qstr attr, mp_obj_t *dest)
Definition: objexcept.c:192
void * memcpy(void *dst, const void *src, size_t n)
Definition: memcpy.c:3
const struct _mp_obj_tuple_t mp_const_empty_tuple_obj
Definition: objtuple.c:233
#define m_new_obj_var_maybe(obj_type, var_type, var_num)
Definition: misc.h:63
#define m_new(type, num)
Definition: misc.h:57
const mp_obj_exception_t mp_const_MemoryError_obj
Definition: objexcept.c:47
mp_obj_t mp_obj_exception_get_value(mp_obj_t self_in)
Definition: objexcept.c:183
size_t alloc
Definition: objexcept.c:353
STATIC MP_DEFINE_CONST_DICT(exc_locals_dict, exc_locals_dict_table)