From b9dde91123f7f999d266ba3cb1e39ab7c96f04d8 Mon Sep 17 00:00:00 2001 From: Yuichi Nishiwaki Date: Thu, 28 May 2015 00:41:55 +0900 Subject: [PATCH] allow custom setjmp/longjmp --- extlib/benz/cont.c | 6 ++++-- extlib/benz/include/picrin.h | 1 - extlib/benz/include/picrin/config.h | 20 ++++++++++++++++++++ extlib/benz/include/picrin/cont.h | 2 +- extlib/benz/include/picrin/error.h | 2 +- 5 files changed, 26 insertions(+), 5 deletions(-) diff --git a/extlib/benz/cont.c b/extlib/benz/cont.c index 391e766e..eaa09771 100644 --- a/extlib/benz/cont.c +++ b/extlib/benz/cont.c @@ -103,7 +103,9 @@ escape_call(pic_state *pic) pic_load_point(pic, e->data); - longjmp(((struct pic_escape *)e->data)->jmp, 1); + PIC_LONGJMP(pic, (void *)((struct pic_escape *)e->data)->jmp, 1); + + PIC_UNREACHABLE(); } struct pic_proc * @@ -130,7 +132,7 @@ pic_escape(pic_state *pic, struct pic_proc *proc) pic_save_point(pic, escape); - if (setjmp(escape->jmp)) { + if (PIC_SETJMP(pic, (void *)escape->jmp)) { return pic_values_by_list(pic, escape->results); } else { diff --git a/extlib/benz/include/picrin.h b/extlib/benz/include/picrin.h index 8965af8d..eaefc79b 100644 --- a/extlib/benz/include/picrin.h +++ b/extlib/benz/include/picrin.h @@ -35,7 +35,6 @@ extern "C" { #include #include -#include #include #include #include diff --git a/extlib/benz/include/picrin/config.h b/extlib/benz/include/picrin/config.h index e03c6819..2853c572 100644 --- a/extlib/benz/include/picrin/config.h +++ b/extlib/benz/include/picrin/config.h @@ -11,6 +11,11 @@ /** treat false value as none */ /* #define PIC_NONE_IS_FALSE 1 */ +/** custom setjmp/longjmp */ +/* #define PIC_JMPBUF_SIZE sizeof(jmp_buf) */ +/* #define PIC_SETJMP(pic, buf) setjmp(buf) */ +/* #define PIC_LONGJMP(pic, buf, val) longjmp((buf), (val)) */ + /** initial memory size (to be dynamically extended if necessary) */ /* #define PIC_ARENA_SIZE 1000 */ @@ -55,6 +60,21 @@ # define PIC_NONE_IS_FALSE 1 #endif +#ifndef PIC_JMPBUF_SIZE +# include +# define PIC_JMPBUF_SIZE sizeof(jmp_buf) +#endif + +#ifndef PIC_SETJMP +# include +# define PIC_SETJMP(pic, buf) setjmp(buf) +#endif + +#ifndef PIC_LONGJMP +# include +# define PIC_LONGJMP(pic, buf, val) longjmp((buf), (val)) +#endif + #ifndef PIC_ARENA_SIZE # define PIC_ARENA_SIZE (8 * 1024) #endif diff --git a/extlib/benz/include/picrin/cont.h b/extlib/benz/include/picrin/cont.h index 645e6d9c..72fda5b2 100644 --- a/extlib/benz/include/picrin/cont.h +++ b/extlib/benz/include/picrin/cont.h @@ -10,7 +10,7 @@ extern "C" { #endif struct pic_escape { - jmp_buf jmp; + char jmp[PIC_JMPBUF_SIZE]; bool valid; diff --git a/extlib/benz/include/picrin/error.h b/extlib/benz/include/picrin/error.h index 9a290bae..7f58ec35 100644 --- a/extlib/benz/include/picrin/error.h +++ b/extlib/benz/include/picrin/error.h @@ -34,7 +34,7 @@ struct pic_error *pic_make_error(pic_state *, pic_sym *, const char *, pic_list) do { \ struct pic_escape *escape = pic_alloc(pic, sizeof(struct pic_escape)); \ pic_save_point(pic, escape); \ - if (setjmp(escape->jmp) == 0) { \ + if (PIC_SETJMP(pic, (void *)escape->jmp) == 0) { \ pic_push_try(pic, escape); \ do #define pic_catch_(label) \