py: Change exception traceback data to use size_t instead of mp_uint_t.
The traceback array stores qstrs and line numbers. qstrs are typed as size_t, and line numbers should safely fit in size_t as well.
This commit is contained in:
parent
ae4865efa1
commit
3d2daa2d03
2
py/obj.c
2
py/obj.c
@ -86,7 +86,7 @@ void mp_obj_print(mp_obj_t o_in, mp_print_kind_t kind) {
|
||||
// helper function to print an exception with traceback
|
||||
void mp_obj_print_exception(const mp_print_t *print, mp_obj_t exc) {
|
||||
if (mp_obj_is_exception_instance(exc)) {
|
||||
mp_uint_t n, *values;
|
||||
size_t n, *values;
|
||||
mp_obj_exception_get_traceback(exc, &n, &values);
|
||||
if (n > 0) {
|
||||
assert(n % 3 == 0);
|
||||
|
4
py/obj.h
4
py/obj.h
@ -680,8 +680,8 @@ bool mp_obj_is_exception_type(mp_obj_t self_in);
|
||||
bool mp_obj_is_exception_instance(mp_obj_t self_in);
|
||||
bool mp_obj_exception_match(mp_obj_t exc, mp_const_obj_t exc_type);
|
||||
void mp_obj_exception_clear_traceback(mp_obj_t self_in);
|
||||
void mp_obj_exception_add_traceback(mp_obj_t self_in, qstr file, mp_uint_t line, qstr block);
|
||||
void mp_obj_exception_get_traceback(mp_obj_t self_in, mp_uint_t *n, mp_uint_t **values);
|
||||
void mp_obj_exception_add_traceback(mp_obj_t self_in, qstr file, size_t line, qstr block);
|
||||
void mp_obj_exception_get_traceback(mp_obj_t self_in, size_t *n, size_t **values);
|
||||
mp_obj_t mp_obj_exception_get_value(mp_obj_t self_in);
|
||||
mp_obj_t mp_obj_exception_make_new(mp_obj_t type_in, mp_uint_t n_args, mp_uint_t n_kw, const mp_obj_t *args);
|
||||
mp_obj_t mp_alloc_emergency_exception_buf(mp_obj_t size_in);
|
||||
|
@ -346,9 +346,9 @@ mp_obj_t mp_obj_new_exception_msg_varg(const mp_obj_type_t *exc_type, const char
|
||||
offset += sizeof(void *) - 1;
|
||||
offset &= ~(sizeof(void *) - 1);
|
||||
|
||||
if ((mp_emergency_exception_buf_size - offset) > (sizeof(mp_uint_t) * 3)) {
|
||||
if ((mp_emergency_exception_buf_size - offset) > (sizeof(o->traceback_data[0]) * 3)) {
|
||||
// We have room to store some traceback.
|
||||
o->traceback_data = (mp_uint_t*)((byte *)MP_STATE_VM(mp_emergency_exception_buf) + offset);
|
||||
o->traceback_data = (size_t*)((byte *)MP_STATE_VM(mp_emergency_exception_buf) + offset);
|
||||
o->traceback_alloc = (MP_STATE_VM(mp_emergency_exception_buf) + mp_emergency_exception_buf_size - (byte *)o->traceback_data) / sizeof(o->traceback_data[0]);
|
||||
o->traceback_len = 0;
|
||||
}
|
||||
@ -429,14 +429,14 @@ void mp_obj_exception_clear_traceback(mp_obj_t self_in) {
|
||||
self->traceback_data = NULL;
|
||||
}
|
||||
|
||||
void mp_obj_exception_add_traceback(mp_obj_t self_in, qstr file, mp_uint_t line, qstr block) {
|
||||
void mp_obj_exception_add_traceback(mp_obj_t self_in, qstr file, size_t line, qstr block) {
|
||||
GET_NATIVE_EXCEPTION(self, self_in);
|
||||
|
||||
// append this traceback info to traceback data
|
||||
// if memory allocation fails (eg because gc is locked), just return
|
||||
|
||||
if (self->traceback_data == NULL) {
|
||||
self->traceback_data = m_new_maybe(mp_uint_t, 3);
|
||||
self->traceback_data = m_new_maybe(size_t, 3);
|
||||
if (self->traceback_data == NULL) {
|
||||
return;
|
||||
}
|
||||
@ -444,7 +444,7 @@ void mp_obj_exception_add_traceback(mp_obj_t self_in, qstr file, mp_uint_t line,
|
||||
self->traceback_len = 0;
|
||||
} else if (self->traceback_len + 3 > self->traceback_alloc) {
|
||||
// be conservative with growing traceback data
|
||||
mp_uint_t *tb_data = m_renew_maybe(mp_uint_t, self->traceback_data, self->traceback_alloc, self->traceback_alloc + 3, true);
|
||||
size_t *tb_data = m_renew_maybe(size_t, self->traceback_data, self->traceback_alloc, self->traceback_alloc + 3, true);
|
||||
if (tb_data == NULL) {
|
||||
return;
|
||||
}
|
||||
@ -452,14 +452,14 @@ void mp_obj_exception_add_traceback(mp_obj_t self_in, qstr file, mp_uint_t line,
|
||||
self->traceback_alloc += 3;
|
||||
}
|
||||
|
||||
mp_uint_t *tb_data = &self->traceback_data[self->traceback_len];
|
||||
size_t *tb_data = &self->traceback_data[self->traceback_len];
|
||||
self->traceback_len += 3;
|
||||
tb_data[0] = (mp_uint_t)file;
|
||||
tb_data[1] = (mp_uint_t)line;
|
||||
tb_data[2] = (mp_uint_t)block;
|
||||
tb_data[0] = file;
|
||||
tb_data[1] = line;
|
||||
tb_data[2] = block;
|
||||
}
|
||||
|
||||
void mp_obj_exception_get_traceback(mp_obj_t self_in, mp_uint_t *n, mp_uint_t **values) {
|
||||
void mp_obj_exception_get_traceback(mp_obj_t self_in, size_t *n, size_t **values) {
|
||||
GET_NATIVE_EXCEPTION(self, self_in);
|
||||
|
||||
if (self->traceback_data == NULL) {
|
||||
|
@ -33,7 +33,7 @@ typedef struct _mp_obj_exception_t {
|
||||
mp_obj_base_t base;
|
||||
mp_uint_t traceback_alloc : (BITS_PER_WORD / 2);
|
||||
mp_uint_t traceback_len : (BITS_PER_WORD / 2);
|
||||
mp_uint_t *traceback_data;
|
||||
size_t *traceback_data;
|
||||
mp_obj_tuple_t *args;
|
||||
} mp_obj_exception_t;
|
||||
|
||||
|
6
py/vm.c
6
py/vm.c
@ -1311,9 +1311,9 @@ unwind_loop:
|
||||
qstr block_name = mp_decode_uint(&ip);
|
||||
qstr source_file = mp_decode_uint(&ip);
|
||||
#endif
|
||||
mp_uint_t bc = code_state->ip - code_state->code_info - code_info_size;
|
||||
mp_uint_t source_line = 1;
|
||||
mp_uint_t c;
|
||||
size_t bc = code_state->ip - code_state->code_info - code_info_size;
|
||||
size_t source_line = 1;
|
||||
size_t c;
|
||||
while ((c = *ip)) {
|
||||
mp_uint_t b, l;
|
||||
if ((c & 0x80) == 0) {
|
||||
|
Loading…
x
Reference in New Issue
Block a user