Skip to content

Commit 7071478

Browse files
authored
Merge pull request #7566 from jepler/chain-exception-fix
Fix several places where an exception could be chained wrongly
2 parents fc919d2 + cec36b6 commit 7071478

File tree

5 files changed

+25
-12
lines changed

5 files changed

+25
-12
lines changed

py/objexcept.c

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -155,6 +155,12 @@ void mp_obj_exception_print(const mp_print_t *print, mp_obj_t o_in, mp_print_kin
155155
mp_obj_tuple_print(print, MP_OBJ_FROM_PTR(o->args), kind);
156156
}
157157

158+
void mp_obj_exception_initialize0(mp_obj_exception_t *o_exc, const mp_obj_type_t *type) {
159+
o_exc->base.type = type;
160+
o_exc->args = (mp_obj_tuple_t *)&mp_const_empty_tuple_obj;
161+
mp_obj_exception_clear_traceback(o_exc);
162+
}
163+
158164
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) {
159165
mp_arg_check_num(n_args, n_kw, 0, MP_OBJ_FUN_ARGS_MAX, false);
160166

@@ -583,6 +589,12 @@ void mp_obj_exception_clear_traceback(mp_obj_t self_in) {
583589
// just set the traceback to the empty traceback object
584590
// we don't want to call any memory management functions here
585591
self->traceback = (mp_obj_traceback_t *)&mp_const_empty_traceback_obj;
592+
#if MICROPY_CPYTHON_EXCEPTION_CHAIN
593+
self->cause = 0;
594+
self->context = 0;
595+
self->suppress_context = false;
596+
self->marked = false;
597+
#endif
586598
}
587599

588600
void mp_obj_exception_add_traceback(mp_obj_t self_in, qstr file, size_t line, qstr block) {

py/objexcept.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ typedef struct _mp_obj_exception_t {
4343

4444
void mp_obj_exception_print(const mp_print_t *print, mp_obj_t o_in, mp_print_kind_t kind);
4545
void mp_obj_exception_attr(mp_obj_t self_in, qstr attr, mp_obj_t *dest);
46+
void mp_obj_exception_initialize0(mp_obj_exception_t *o_exc, const mp_obj_type_t *type);
4647
mp_obj_exception_t *mp_obj_exception_get_native(mp_obj_t self_in);
4748

4849
#define MP_DEFINE_EXCEPTION(exc_name, base_name) \

py/objgenerator.c

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -40,10 +40,11 @@
4040
// Instance of GeneratorExit exception - needed by generator.close()
4141
#if MICROPY_CONST_GENERATOREXIT_OBJ
4242
const
43+
mp_obj_exception_t mp_static_GeneratorExit_obj = {{&mp_type_GeneratorExit}, (mp_obj_tuple_t *)&mp_const_empty_tuple_obj, (mp_obj_traceback_t *)&mp_const_empty_traceback_obj};
4344
#else
4445
static
46+
mp_obj_exception_t mp_static_GeneratorExit_obj;
4547
#endif
46-
mp_obj_exception_t mp_static_GeneratorExit_obj = {{&mp_type_GeneratorExit}, (mp_obj_tuple_t *)&mp_const_empty_tuple_obj, (mp_obj_traceback_t *)&mp_const_empty_traceback_obj};
4748

4849
/******************************************************************************/
4950
/* generator wrapper */
@@ -370,9 +371,7 @@ STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(gen_instance_throw_obj, 2, 4, gen_ins
370371
static mp_obj_t generatorexit(void) {
371372
#if MICROPY_CPYTHON_EXCEPTION_CHAIN
372373
MP_STATIC_ASSERT(!MICROPY_CONST_GENERATOREXIT_OBJ);
373-
mp_static_GeneratorExit_obj.context = NULL;
374-
mp_static_GeneratorExit_obj.cause = NULL;
375-
mp_static_GeneratorExit_obj.suppress_context = false;
374+
mp_obj_exception_initialize0(&mp_static_GeneratorExit_obj, &mp_type_GeneratorExit);
376375
#endif
377376
return MP_OBJ_FROM_PTR(&mp_static_GeneratorExit_obj);
378377
}

py/runtime.c

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -78,14 +78,10 @@ void mp_init(void) {
7878

7979
#if MICROPY_KBD_EXCEPTION
8080
// initialise the exception object for raising KeyboardInterrupt
81-
MP_STATE_VM(mp_kbd_exception).base.type = &mp_type_KeyboardInterrupt;
82-
MP_STATE_VM(mp_kbd_exception).args = (mp_obj_tuple_t *)&mp_const_empty_tuple_obj;
83-
MP_STATE_VM(mp_kbd_exception).traceback = (mp_obj_traceback_t *)&mp_const_empty_traceback_obj;
81+
mp_obj_exception_initialize0(&MP_STATE_VM(mp_kbd_exception), &mp_type_KeyboardInterrupt);
8482
#endif
8583

86-
MP_STATE_VM(mp_reload_exception).base.type = &mp_type_ReloadException;
87-
MP_STATE_VM(mp_reload_exception).args = (mp_obj_tuple_t *)&mp_const_empty_tuple_obj;
88-
MP_STATE_VM(mp_reload_exception).traceback = (mp_obj_traceback_t *)&mp_const_empty_traceback_obj;
84+
mp_obj_exception_initialize0(&MP_STATE_VM(mp_reload_exception), &mp_type_ReloadException);
8985

9086
// call port specific initialization if any
9187
#ifdef MICROPY_PORT_INIT_FUNC

tools/build_board_info.py

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
import sys
1111
import sh
1212
import base64
13+
from io import StringIO
1314
from datetime import date
1415
from sh.contrib import git
1516

@@ -58,9 +59,13 @@ def get_languages(list_all=False):
5859

5960
def get_version_info():
6061
version = None
61-
sha = git("rev-parse", "--short", "HEAD").stdout.decode("utf-8")
62+
buffer = StringIO()
63+
git("rev-parse", "--short", "HEAD", _out=buffer)
64+
sha = buffer.getvalue().strip()
6265
try:
63-
version = git("describe", "--tags", "--exact-match").stdout.decode("utf-8").strip()
66+
buffer = StringIO()
67+
git("describe", "--tags", "--exact-match", _out=buffer)
68+
version = buffer.getvalue().strip()
6469
except sh.ErrorReturnCode_128:
6570
# No exact match
6671
pass

0 commit comments

Comments
 (0)