Mercurial > hg > Members > kaito > longjump
changeset 4:d75a89b10176
write pointer_longjump.c
author | Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp> |
---|---|
date | Thu, 14 Nov 2013 13:16:46 +0900 |
parents | e6aa3b678e4a |
children | 4e7858590985 |
files | global_longjump.c pointer_longjump.c |
diffstat | 2 files changed, 25 insertions(+), 27 deletions(-) [+] |
line wrap: on
line diff
--- a/global_longjump.c Tue Nov 12 15:22:04 2013 +0900 +++ b/global_longjump.c Thu Nov 14 13:16:46 2013 +0900 @@ -3,9 +3,10 @@ #include <stdlib.h> int retval; -__code code1(int n,__code(*__return)(int,void *),void *__enviroment){ + +__code code1(int n,__code(*__return)(int,void *),void *__environment){ printf("code1 : code1 entry\n"); - goto __return(n,__enviroment); + goto __return(n,__environment); } __code return1 (int n,void* env){ @@ -16,16 +17,16 @@ int main1 (){ __code (*__return)(); - void *__enviroment; + void *__environment; printf("main1 : main1 entry\n"); - __enviroment = (void*)malloc(sizeof(jmp_buf)); - if (setjmp(__enviroment)){ - free(__enviroment); + __environment = (void*)malloc(sizeof(jmp_buf)); + if (setjmp(__environment)){ + free(__environment); printf("main1 : main1 return\n"); return retval; } __return = return1; - goto code1(30,__return,__enviroment); + goto code1(30,__return,__environment); return 0; }
--- a/pointer_longjump.c Tue Nov 12 15:22:04 2013 +0900 +++ b/pointer_longjump.c Thu Nov 14 13:16:46 2013 +0900 @@ -2,35 +2,32 @@ #include <setjmp.h> #include <stdlib.h> -__code code1(int n,void *__return,void *__enviroment,int *__ret_p){ - void(*ret)(int,void *,int *); - printf("code1\n"); - ret = (void(*)(int,void *,int *))__return; - ret(n,__enviroment,__ret_p); - //((void(*)(int,void *,int *))__return)(n,__enviroment,__ret_p); +__code code1(int n,__code(*__return)(int,void *,int *),void *__environment,int *__ret_p){ + printf("code1 : code entry1\n"); + goto __return(n,__environment,__ret_p); } -void *return1 (int n,void* env,int* __ret_p){ - printf("return1\n"); +__code return1 (int n,void* env,int* __ret_p){ + printf("return1 : __return entry\n"); *__ret_p = n; longjmp(*(jmp_buf*)env,1); } int main1 (){ - void *__return; - void *__enviroment; + __code (*__return)(); + void *__environment; + int retval; int *__ret_p; - printf("main1 entry\n"); - __enviroment = (void*)malloc(sizeof(jmp_buf)); - __ret_p = (int*)malloc(sizeof(int)); - if (setjmp(__enviroment)){ - free(__enviroment); - printf("main1 return\n"); - // We haven't freed __ret_p's memory... Where is the best position of the free()? - return *__ret_p; + __ret_p = &retval; + printf("main1 : main1 entry\n"); + __environment = (void*)malloc(sizeof(jmp_buf)); + if (setjmp(__environment)){ + free(__environment); + printf("main1 : main1 return\n"); + return retval; } - __return = (void*)return1; - goto code1(30,__return,__enviroment,__ret_p); + __return = return1; + goto code1(30,__return,__environment,__ret_p); return 0; }