Skip to content

Commit 25b6b62

Browse files
committed
qemu-arm: Move lexer constructors to within NLR handler block.
And raise an exception when mp_lexer_new_from_file is called.
1 parent bcd5adc commit 25b6b62

2 files changed

Lines changed: 6 additions & 13 deletions

File tree

qemu-arm/main.c

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -12,15 +12,12 @@
1212
#include "py/stackctrl.h"
1313
#include "py/gc.h"
1414
#include "py/repl.h"
15+
#include "py/mperrno.h"
1516

1617
void do_str(const char *src, mp_parse_input_kind_t input_kind) {
17-
mp_lexer_t *lex = mp_lexer_new_from_str_len(MP_QSTR__lt_stdin_gt_, src, strlen(src), 0);
18-
if (lex == NULL) {
19-
return;
20-
}
21-
2218
nlr_buf_t nlr;
2319
if (nlr_push(&nlr) == 0) {
20+
mp_lexer_t *lex = mp_lexer_new_from_str_len(MP_QSTR__lt_stdin_gt_, src, strlen(src), 0);
2421
qstr source_name = lex->source_name;
2522
mp_parse_tree_t parse_tree = mp_parse(lex, input_kind);
2623
mp_obj_t module_fun = mp_compile(&parse_tree, source_name, MP_EMIT_OPT_NONE, true);
@@ -47,7 +44,7 @@ void gc_collect(void) {
4744
}
4845

4946
mp_lexer_t *mp_lexer_new_from_file(const char *filename) {
50-
return NULL;
47+
mp_raise_OSError(MP_ENOENT);
5148
}
5249

5350
mp_import_stat_t mp_import_stat(const char *path) {

qemu-arm/test_main.c

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
#include "py/runtime.h"
1212
#include "py/stackctrl.h"
1313
#include "py/gc.h"
14-
#include "py/repl.h"
14+
#include "py/mperrno.h"
1515

1616
#include "tinytest.h"
1717
#include "tinytest_macros.h"
@@ -24,13 +24,9 @@ inline void do_str(const char *src) {
2424
gc_init(heap, (char*)heap + HEAP_SIZE);
2525
mp_init();
2626

27-
mp_lexer_t *lex = mp_lexer_new_from_str_len(MP_QSTR__lt_stdin_gt_, src, strlen(src), 0);
28-
if (lex == NULL) {
29-
tt_abort_msg("Lexer initialization error");
30-
}
31-
3227
nlr_buf_t nlr;
3328
if (nlr_push(&nlr) == 0) {
29+
mp_lexer_t *lex = mp_lexer_new_from_str_len(MP_QSTR__lt_stdin_gt_, src, strlen(src), 0);
3430
qstr source_name = lex->source_name;
3531
mp_parse_tree_t parse_tree = mp_parse(lex, MP_PARSE_FILE_INPUT);
3632
mp_obj_t module_fun = mp_compile(&parse_tree, source_name, MP_EMIT_OPT_NONE, false);
@@ -80,7 +76,7 @@ void gc_collect(void) {
8076
}
8177

8278
mp_lexer_t *mp_lexer_new_from_file(const char *filename) {
83-
return NULL;
79+
mp_raise_OSError(MP_ENOENT);
8480
}
8581

8682
mp_import_stat_t mp_import_stat(const char *path) {

0 commit comments

Comments
 (0)