From c8eb44b54b933d5a2bff7a3b380f327728dfba3f Mon Sep 17 00:00:00 2001 From: hyung-hwan Date: Thu, 9 Jun 2022 06:01:44 +0000 Subject: [PATCH] added hawk_killecb() and hawk_rtx_killecb() corrected a new silly flaw in the ON_STATEMENT() macro --- hawk/lib/hawk.c | 15 +++++++++++++++ hawk/lib/hawk.h | 16 +++++++++++++--- hawk/lib/run.c | 18 +++++++++++++++++- hawk/lib/sed.c | 18 +++++++++--------- 4 files changed, 54 insertions(+), 13 deletions(-) diff --git a/hawk/lib/hawk.c b/hawk/lib/hawk.c index 32ae84ef..4331b78e 100644 --- a/hawk/lib/hawk.c +++ b/hawk/lib/hawk.c @@ -578,6 +578,21 @@ void hawk_haltall (hawk_t* hawk) hawk->haltall = 1; } +void hawk_killecb (hawk_t* hawk, hawk_ecb_t* ecb) +{ + hawk_ecb_t* prev, * cur; + for (cur = hawk->ecb, prev = HAWK_NULL; cur != (hawk_ecb_t*)hawk; cur = cur->next) + { + if (cur == ecb) + { + if (prev) prev->next = cur->next; + else hawk->ecb = cur->next; + cur->next = HAWK_NULL; + break; + } + } +} + hawk_ecb_t* hawk_popecb (hawk_t* hawk) { hawk_ecb_t* top = hawk->ecb; diff --git a/hawk/lib/hawk.h b/hawk/lib/hawk.h index 1e1707fb..36e8f01f 100644 --- a/hawk/lib/hawk.h +++ b/hawk/lib/hawk.h @@ -1719,21 +1719,26 @@ HAWK_EXPORT int hawk_setopt ( const void* value ); +HAWK_EXPORT void hawk_killecb ( + hawk_t* hawk, + hawk_ecb_t* ecb +); + /** * The hawk_popecb() function pops an hawk event callback set * and returns the pointer to it. If no callback set can be popped, * it returns #HAWK_NULL. */ HAWK_EXPORT hawk_ecb_t* hawk_popecb ( - hawk_t* hawk /**< hawk */ + hawk_t* hawk ); /** * The hawk_pushecb() function register a runtime callback set. */ HAWK_EXPORT void hawk_pushecb ( - hawk_t* hawk, /**< hawk */ - hawk_ecb_t* ecb /**< callback set */ + hawk_t* hawk, + hawk_ecb_t* ecb ); /** @@ -2398,6 +2403,11 @@ HAWK_EXPORT void hawk_rtx_setrio ( const hawk_rio_cbs_t* rio ); +HAWK_EXPORT void hawk_rtx_killecb ( + hawk_rtx_t* rtx, /**< runtime context */ + hawk_rtx_ecb_t* ecb /**< callback set */ +); + /** * The hawk_rtx_popecb() function pops a runtime callback set * and returns the pointer to it. If no callback set can be popped, diff --git a/hawk/lib/run.c b/hawk/lib/run.c index 051fb60c..c53aac23 100644 --- a/hawk/lib/run.c +++ b/hawk/lib/run.c @@ -983,6 +983,21 @@ void hawk_rtx_setrio (hawk_rtx_t* rtx, const hawk_rio_cbs_t* rio) rtx->rio.handler[HAWK_RIO_CONSOLE] = rio->console; } +void hawk_rtx_killecb (hawk_rtx_t* rtx, hawk_rtx_ecb_t* ecb) +{ + hawk_rtx_ecb_t* prev, * cur; + for (cur = rtx->ecb, prev = HAWK_NULL; cur != (hawk_rtx_ecb_t*)rtx; cur = cur->next) + { + if (cur == ecb) + { + if (prev) prev->next = cur->next; + else rtx->ecb = cur->next; + cur->next = HAWK_NULL; + break; + } + } +} + hawk_rtx_ecb_t* hawk_rtx_popecb (hawk_rtx_t* rtx) { hawk_rtx_ecb_t* top = rtx->ecb; @@ -2233,9 +2248,10 @@ static int run_block (hawk_rtx_t* rtx, hawk_nde_blk_t* nde) #define ON_STATEMENT(rtx,nde) do { \ hawk_rtx_ecb_t* ecb, * ecb_next; \ if ((rtx)->hawk->haltall) (rtx)->exit_level = EXIT_ABORT; \ - for (ecb = (rtx)->ecb; ecb != (hawk_rtx_ecb_t*)(rtx); ecb = ecb_next) \ + for (ecb = (rtx)->ecb; ecb != (hawk_rtx_ecb_t*)(rtx); ecb = ecb_next) { \ ecb_next = ecb->next; \ if (ecb->stmt) ecb->stmt (rtx, nde, ecb->ctx); \ + } \ } while(0) static int run_statement (hawk_rtx_t* rtx, hawk_nde_t* nde) diff --git a/hawk/lib/sed.c b/hawk/lib/sed.c index 6e4fa69b..9074e3b7 100644 --- a/hawk/lib/sed.c +++ b/hawk/lib/sed.c @@ -3921,15 +3921,6 @@ void hawk_sed_setlinenum (hawk_sed_t* sed, hawk_oow_t num) sed->e.in.num = num; } -hawk_sed_ecb_t* hawk_sed_popecb (hawk_sed_t* sed) -{ - hawk_sed_ecb_t* top = sed->ecb; - if (top == (hawk_sed_ecb_t*)sed) return HAWK_NULL; - sed->ecb = top->next; - top->next = HAWK_NULL; - return top; -} - void hawk_sed_killecb (hawk_sed_t* sed, hawk_sed_ecb_t* ecb) { hawk_sed_ecb_t* prev, * cur; @@ -3945,6 +3936,15 @@ void hawk_sed_killecb (hawk_sed_t* sed, hawk_sed_ecb_t* ecb) } } +hawk_sed_ecb_t* hawk_sed_popecb (hawk_sed_t* sed) +{ + hawk_sed_ecb_t* top = sed->ecb; + if (top == (hawk_sed_ecb_t*)sed) return HAWK_NULL; + sed->ecb = top->next; + top->next = HAWK_NULL; + return top; +} + void hawk_sed_pushecb (hawk_sed_t* sed, hawk_sed_ecb_t* ecb) { ecb->next = sed->ecb;