Skip to content

Commit 21420b1

Browse files
committed
examples/embedding: Place lexer constructor within NLR handler block.
The lexer constructor may now raise an exception and it needs to be caught.
1 parent 52f8f56 commit 21420b1

File tree

1 file changed

+3
-3
lines changed

1 file changed

+3
-3
lines changed

examples/embedding/hello-embed.c

+3-3
Original file line numberDiff line numberDiff line change
@@ -35,9 +35,10 @@
3535

3636
static char heap[16384];
3737

38-
mp_obj_t execute_from_lexer(mp_lexer_t *lex) {
38+
mp_obj_t execute_from_str(const char *str) {
3939
nlr_buf_t nlr;
4040
if (nlr_push(&nlr) == 0) {
41+
mp_lexer_t *lex = mp_lexer_new_from_str_len(0/*MP_QSTR_*/, str, strlen(str), false);
4142
mp_parse_tree_t pt = mp_parse(lex, MP_PARSE_FILE_INPUT);
4243
mp_obj_t module_fun = mp_compile(&pt, lex->source_name, MP_EMIT_OPT_NONE, false);
4344
mp_call_function_0(module_fun);
@@ -58,8 +59,7 @@ int main() {
5859
mp_init();
5960

6061
const char str[] = "print('Hello world of easy embedding!')";
61-
mp_lexer_t *lex = mp_lexer_new_from_str_len(0/*MP_QSTR_*/, str, strlen(str), false);
62-
if (execute_from_lexer(lex)) {
62+
if (execute_from_str(str)) {
6363
printf("Error\n");
6464
}
6565
}

0 commit comments

Comments
 (0)