Skip to content

Commit bcd5adc

Browse files
committed
minimal/main: Move lexer constructor to within NLR handler block.
And raise an exception when mp_lexer_new_from_file is called.
1 parent c72a5f8 commit bcd5adc

1 file changed

Lines changed: 3 additions & 7 deletions

File tree

minimal/main.c

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -7,18 +7,14 @@
77
#include "py/runtime.h"
88
#include "py/repl.h"
99
#include "py/gc.h"
10+
#include "py/mperrno.h"
1011
#include "lib/utils/pyexec.h"
1112

1213
#if MICROPY_ENABLE_COMPILER
1314
void do_str(const char *src, mp_parse_input_kind_t input_kind) {
14-
mp_lexer_t *lex = mp_lexer_new_from_str_len(MP_QSTR__lt_stdin_gt_, src, strlen(src), 0);
15-
if (lex == NULL) {
16-
printf("MemoryError: lexer could not allocate memory\n");
17-
return;
18-
}
19-
2015
nlr_buf_t nlr;
2116
if (nlr_push(&nlr) == 0) {
17+
mp_lexer_t *lex = mp_lexer_new_from_str_len(MP_QSTR__lt_stdin_gt_, src, strlen(src), 0);
2218
qstr source_name = lex->source_name;
2319
mp_parse_tree_t parse_tree = mp_parse(lex, input_kind);
2420
mp_obj_t module_fun = mp_compile(&parse_tree, source_name, MP_EMIT_OPT_NONE, true);
@@ -74,7 +70,7 @@ void gc_collect(void) {
7470
}
7571

7672
mp_lexer_t *mp_lexer_new_from_file(const char *filename) {
77-
return NULL;
73+
mp_raise_OSError(MP_ENOENT);
7874
}
7975

8076
mp_import_stat_t mp_import_stat(const char *path) {

0 commit comments

Comments
 (0)