[bugfix] macroexpand
macroexpand restores pic->lib in the case of an error
This commit is contained in:
parent
e7a2a8f0a4
commit
30cc6998de
17
src/macro.c
17
src/macro.c
|
@ -213,7 +213,12 @@ macroexpand(pic_state *pic, pic_value expr, struct pic_senv *senv)
|
|||
|
||||
if (tag == pic->sDEFINE_LIBRARY) {
|
||||
struct pic_lib *prev = pic->lib;
|
||||
jmp_buf jmp, *prevjmp = pic->jmp;
|
||||
bool name_restored = false;
|
||||
|
||||
/* restores pic->lib even if an error occurs */
|
||||
if (setjmp(jmp) == 0) {
|
||||
pic->jmp = &jmp;
|
||||
if (pic_length(pic, expr) < 2) {
|
||||
pic_error(pic, "syntax error");
|
||||
}
|
||||
|
@ -238,7 +243,17 @@ macroexpand(pic_state *pic, pic_value expr, struct pic_senv *senv)
|
|||
}
|
||||
}
|
||||
pic_in_library(pic, prev->name);
|
||||
|
||||
name_restored = true;
|
||||
}
|
||||
else {
|
||||
if (! name_restored) {
|
||||
pic_in_library(pic, prev->name);
|
||||
}
|
||||
}
|
||||
pic->jmp = prevjmp;
|
||||
if (pic->err) {
|
||||
longjmp(*pic->jmp, 1);
|
||||
}
|
||||
return pic_none_value();
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue