summaryrefslogtreecommitdiffstatshomepage
diff options
context:
space:
mode:
authorDamien George <damien.p.george@gmail.com>2017-03-14 11:33:06 +1100
committerDamien George <damien.p.george@gmail.com>2017-03-14 11:52:05 +1100
commit21420b13c011ca5a89a224ff7108b98fd3aeafd9 (patch)
treefff266273836d5ec2a2957ed343cd614e31a6dad
parent52f8f5666a496e17306c7cc6f53c0c14cf003a57 (diff)
downloadmicropython-21420b13c011ca5a89a224ff7108b98fd3aeafd9.tar.gz
micropython-21420b13c011ca5a89a224ff7108b98fd3aeafd9.zip
examples/embedding: Place lexer constructor within NLR handler block.
The lexer constructor may now raise an exception and it needs to be caught.
-rw-r--r--examples/embedding/hello-embed.c6
1 files changed, 3 insertions, 3 deletions
diff --git a/examples/embedding/hello-embed.c b/examples/embedding/hello-embed.c
index 1949305184..e3a4847835 100644
--- a/examples/embedding/hello-embed.c
+++ b/examples/embedding/hello-embed.c
@@ -35,9 +35,10 @@
static char heap[16384];
-mp_obj_t execute_from_lexer(mp_lexer_t *lex) {
+mp_obj_t execute_from_str(const char *str) {
nlr_buf_t nlr;
if (nlr_push(&nlr) == 0) {
+ mp_lexer_t *lex = mp_lexer_new_from_str_len(0/*MP_QSTR_*/, str, strlen(str), false);
mp_parse_tree_t pt = mp_parse(lex, MP_PARSE_FILE_INPUT);
mp_obj_t module_fun = mp_compile(&pt, lex->source_name, MP_EMIT_OPT_NONE, false);
mp_call_function_0(module_fun);
@@ -58,8 +59,7 @@ int main() {
mp_init();
const char str[] = "print('Hello world of easy embedding!')";
- mp_lexer_t *lex = mp_lexer_new_from_str_len(0/*MP_QSTR_*/, str, strlen(str), false);
- if (execute_from_lexer(lex)) {
+ if (execute_from_str(str)) {
printf("Error\n");
}
}