diff --git a/create_signal_fun.py b/create_signal_fun.py index 2dc3aee..03512d3 100644 --- a/create_signal_fun.py +++ b/create_signal_fun.py @@ -189,7 +189,7 @@ def def_slot_fun(line:str): def gen_slot_fun_array(slot_fun_list:list) -> str: item_list=[] for item in slot_fun_list: - item_list.append(f" .func = {item.name}_caller,\n .name=\"{item.name}\"\n") + item_list.append(f" .func = {item.name}_caller,\n .name = \"{item.name}\"\n") table_str=""" // 定义一个数据结构来保存槽封装函数与槽函数的关系 typedef struct { diff --git a/soft/clexical.c b/soft/clexical.c index 169b000..b30ede8 100644 --- a/soft/clexical.c +++ b/soft/clexical.c @@ -67,7 +67,7 @@ const keywork_item_def g_keyword_table[ ] = { TOKEN_DEF(continue,TOKEN_CONTINUE), TOKEN_DEF(const,TOKEN_CONST), TOKEN_DEF(static,TOKEN_STATIC), - TOKEN_DEF(unisgned,TOKEN_UNSIGNED), + TOKEN_DEF(unsigned,TOKEN_UNSIGNED), TOKEN_DEF(typedef,TOKEN_TYPEDEF), TOKEN_DEF(struct,TOKEN_STRUCT), TOKEN_DEF(enum,TOKEN_ENUM), diff --git a/soft/exception.h b/soft/exception.h index 4e120e7..1325e4b 100644 --- a/soft/exception.h +++ b/soft/exception.h @@ -66,13 +66,16 @@ typedef struct{ }\ } - +/* + try 的时候保存当前回溯点,如果setjmp返回不为0 则已经产生异常回溯了, + 这时最后一个回溯点的使命已经完成,所以删除最后一个回溯点 +*/ #define __try(){\ exception_def *f=exception();\ jmp_fram **h=&f->jmp_head;\ int ret;\ jmp_next(h);\ - ret= setjmp(((*h)->fram));\ + ret = setjmp(((*h)->fram));\ if(ret){\ jmp_clear(h);\ }\ @@ -80,6 +83,11 @@ typedef struct{ } #define try_ __try();if(exception()->ret==0){ + +/* + 如果try一直执行到这里则不会产生回溯了,最后一个回溯点的使命也已经完成了, + 所以这里删除最后一个回溯点 +*/ #define catch_ {\ exception_def *f=exception();\ jmp_fram **h=&f->jmp_head;\ diff --git a/test/signal_test.c b/test/signal_test.c index 34d59b6..24b47f5 100644 --- a/test/signal_test.c +++ b/test/signal_test.c @@ -37,8 +37,8 @@ // // 封装函数用来调用实际的槽函数 // static void test_slot_caller(void* args) { // test_slot_args* a = args; -// printf("test_slot_caller: %d %d\n", a->a, a->b); -// printf("args_p=%p\n", a); +// DBG_LOG("test_slot_caller: %d %d\n", a->a, a->b); +// DBG_LOG("args_p=%p\n", a); // test_slot(a->self, a->a, a->b); // } @@ -104,18 +104,18 @@ static void mdelay(unsigned long mSec){ // 定义槽函数 slot test_slot(test_sig_obj2* obj, int a, int b) { - printf("test_slot var=%d\n", obj->test_var); + DBG_LOG("test_slot var=%d\n", obj->test_var); obj->test_var = a + b; - printf("test_slot var=%d\n", obj->test_var); + DBG_LOG("test_slot var=%d\n", obj->test_var); } slot test_slot3(test_sig_obj3* obj, int a, int b) { - printf("test_slot3 a=%d, b=%d\n", a, b); - printf("obj->v1=%d, obj->v2=%d\n", obj->test_var, obj->test_var2); + DBG_LOG("test_slot3 a=%d, b=%d\n", a, b); + DBG_LOG("obj->v1=%d, obj->v2=%d\n", obj->test_var, obj->test_var2); } slot test_slot3_2(test_sig_obj3* obj, int a, int b, const char* c) { - printf("test_slot3_2 a=%d, b=%d, c=%s\n", a, b, c); + DBG_LOG("test_slot3_2 a=%d, b=%d, c=%s\n", a, b, c); throw_("test_slot3_2 err"); } @@ -123,9 +123,32 @@ static test_sig_obj g_sig_obj = { .test_var = 1, }; static test_sig_obj2 g_sig_obj2 = { .test_var = 2, }; static test_sig_obj3 g_sig_obj3; + + +void try_catch_test() { + try_ { + DBG_LOG("进入第一个try"); + DBG_LOG("抛出异常"); + throw_("第一个try抛出的异常"); + }catch_ { + DBG_LOG("进入第一个catch"); + try_ { + DBG_LOG("进入第二个try"); + throw_("第二个try抛出的异常"); + }catch_ { + DBG_LOG("进入第二个catch"); + throw_("第二个catch抛出的异常"); + } + } +} + + + + + int thread_fun(void* t) { mythread_t* th = sigthread_init("signal_thread"); - printf("thread_fun start\n"); + DBG_LOG("thread_fun start\n"); connect(&g_sig_obj, test_signal, th, &g_sig_obj2, test_slot); connect(&g_sig_obj, test_signal, th, &g_sig_obj3, test_slot3); connect(&g_sig_obj, test_signal2, th, &g_sig_obj3, test_slot3_2); @@ -134,8 +157,8 @@ int thread_fun(void* t) { mdelay(1000); emit test_signal2(&g_sig_obj, 5, 6,"hello world"); mdelay(1000); - printf("test end\n"); - throw_("my err"); + DBG_LOG("test end\n"); + try_catch_test(); return 0; } diff --git a/test/test_fun2.c b/test/test_fun2.c index 47d6331..cd55ec3 100644 --- a/test/test_fun2.c +++ b/test/test_fun2.c @@ -104,15 +104,15 @@ int thread_fun(void* t) tmp[i] = bitmap[i]; } ret = gpio_find_first_int((uint8_t*)tmp, sizeof(tmp), 0); - printf("ret=%d\n", ret - 1); + DBG_LOG("ret=%d\n", ret - 1); ret = gpio_find_first_int((uint8_t*)tmp, sizeof(tmp), ret); - printf("ret=%d\n", ret - 1); + DBG_LOG("ret=%d\n", ret - 1); for (int i = 0;i < sizeof(bitmap) / sizeof(bitmap[0]);i++) { tmp[i] = bitmap[i]; } ret = iot_bitmap_ffs_from((uint8_t*)tmp, sizeof(tmp), 0); - printf("ret=%d\n", ret - 1); + DBG_LOG("ret=%d\n", ret - 1); ret = iot_bitmap_ffs_from((uint8_t*)tmp, sizeof(tmp), ret); - printf("ret=%d\n", ret - 1); + DBG_LOG("ret=%d\n", ret - 1); }