From 97bd469ce899e701641f3137f1bc4f25624c4936 Mon Sep 17 00:00:00 2001 From: hyung-hwan Date: Mon, 7 Dec 2020 16:48:29 +0000 Subject: [PATCH] touched up hawk_rtx_truncrec(). fixed a bug in hawk_xma_init() --- hawk/bin/main.c | 2 +- hawk/lib/mod-str.c | 2 +- hawk/lib/rec.c | 77 ++++++++++++++++++++++------------------------ hawk/lib/std.c | 2 +- hawk/lib/val.c | 3 +- hawk/lib/xma.c | 2 +- 6 files changed, 42 insertions(+), 46 deletions(-) diff --git a/hawk/bin/main.c b/hawk/bin/main.c index d492b583..bb05c81a 100644 --- a/hawk/bin/main.c +++ b/hawk/bin/main.c @@ -1050,7 +1050,7 @@ static hawk_mmgr_t xma_mmgr = HAWK_NULL }; -static int xma_dumper_without_hawk (void* ctx, const hawk_bch_t* fmt, ...) +static void xma_dumper_without_hawk (void* ctx, const hawk_bch_t* fmt, ...) { va_list ap; va_start (ap, fmt); diff --git a/hawk/lib/mod-str.c b/hawk/lib/mod-str.c index 03b27832..39115c7f 100644 --- a/hawk/lib/mod-str.c +++ b/hawk/lib/mod-str.c @@ -468,7 +468,7 @@ static int fnc_tonum (hawk_rtx_t* rtx, const hawk_fnc_info_t* fi) /* str::tonum(value) */ /* str::tonum(string, base) */ - hawk_t* hawk = hawk_rtx_gethawk(rtx); + /*hawk_t* hawk = hawk_rtx_gethawk(rtx);*/ hawk_val_t* retv; hawk_val_t* a0; hawk_int_t lv; diff --git a/hawk/lib/rec.c b/hawk/lib/rec.c index 4cd496d2..d31b87e5 100644 --- a/hawk/lib/rec.c +++ b/hawk/lib/rec.c @@ -492,68 +492,62 @@ int hawk_rtx_truncrec (hawk_rtx_t* rtx, hawk_oow_t nflds) hawk_val_t* v = HAWK_NULL, * w; hawk_ooch_t* ofs_free = HAWK_NULL, * ofs_ptr; hawk_oow_t ofs_len, i; - hawk_ooecs_t tmp; hawk_val_type_t vtype; + hawk_ooecs_t tmp; + int fini_tmp = 0; HAWK_ASSERT (nflds <= rtx->inrec.nflds); - if (nflds > 1) - { - v = HAWK_RTX_STACK_GBL(rtx, HAWK_GBL_OFS); - hawk_rtx_refupval (rtx, v); - vtype = HAWK_RTX_GETVALTYPE(rtx, v); - - if (vtype == HAWK_VAL_NIL) - { - /* OFS not set */ - ofs_ptr = HAWK_T(" "); - ofs_len = 1; - } - else - { - ofs_ptr = hawk_rtx_getvaloocstr(rtx, v, &ofs_len); - if (HAWK_UNLIKELY(!ofs_ptr)) goto oops; - ofs_free = ofs_ptr; - } - } - if (hawk_ooecs_init(&tmp, hawk_rtx_getgem(rtx), HAWK_OOECS_LEN(&rtx->inrec.line)) <= -1) goto oops; + fini_tmp = 1; - for (i = 0; i < nflds; i++) + if (nflds > 0) { - if (i > 0 && hawk_ooecs_ncat(&tmp,ofs_ptr,ofs_len) == (hawk_oow_t)-1) + if (nflds > 1) { - hawk_ooecs_fini (&tmp); - goto oops; + v = HAWK_RTX_STACK_GBL(rtx, HAWK_GBL_OFS); + hawk_rtx_refupval (rtx, v); + vtype = HAWK_RTX_GETVALTYPE(rtx, v); + + if (vtype == HAWK_VAL_NIL) + { + /* OFS not set */ + ofs_ptr = HAWK_T(" "); + ofs_len = 1; + } + else + { + ofs_ptr = hawk_rtx_getvaloocstr(rtx, v, &ofs_len); + if (HAWK_UNLIKELY(!ofs_ptr)) goto oops; + ofs_free = ofs_ptr; + } + } + + if (hawk_ooecs_ncat(&tmp, rtx->inrec.flds[0].ptr, rtx->inrec.flds[0].len) == (hawk_oow_t)-1) goto oops; + for (i = 1; i < nflds; i++) + { + if (i > 0 && hawk_ooecs_ncat(&tmp,ofs_ptr,ofs_len) == (hawk_oow_t)-1) goto oops; + if (hawk_ooecs_ncat(&tmp, rtx->inrec.flds[i].ptr, rtx->inrec.flds[i].len) == (hawk_oow_t)-1) goto oops; } - if (hawk_ooecs_ncat(&tmp, rtx->inrec.flds[i].ptr, rtx->inrec.flds[i].len) == (hawk_oow_t)-1) + if (v) { - hawk_ooecs_fini (&tmp); - goto oops; + if (ofs_free) hawk_rtx_freevaloocstr (rtx, v, ofs_free); + hawk_rtx_refdownval(rtx, v); + v = HAWK_NULL; } } - if (v) - { - if (ofs_free) hawk_rtx_freevaloocstr (rtx, v, ofs_free); - hawk_rtx_refdownval(rtx, v); - v = HAWK_NULL; - } - w = (hawk_val_t*)hawk_rtx_makestrvalwithoocs(rtx, HAWK_OOECS_OOCS(&tmp)); - if (!w) - { - hawk_ooecs_fini (&tmp); - return -1; - } + if (HAWK_UNLIKELY(!w)) goto oops; - if (HAWK_RTX_GETVALTYPE(rtx, rtx->inrec.d0) != HAWK_VAL_NIL) hawk_rtx_refdownval (rtx, rtx->inrec.d0); + hawk_rtx_refdownval (rtx, rtx->inrec.d0); rtx->inrec.d0 = w; hawk_rtx_refupval (rtx, rtx->inrec.d0); hawk_ooecs_swap (&tmp, &rtx->inrec.line); hawk_ooecs_fini (&tmp); + fini_tmp = 0; for (i = nflds; i < rtx->inrec.nflds; i++) { @@ -564,6 +558,7 @@ int hawk_rtx_truncrec (hawk_rtx_t* rtx, hawk_oow_t nflds) return 0; oops: + if (fini_tmp) hawk_ooecs_fini (&tmp); if (v) { if (ofs_free) hawk_rtx_freevaloocstr (rtx, v, ofs_free); diff --git a/hawk/lib/std.c b/hawk/lib/std.c index f864d81b..c76920fa 100644 --- a/hawk/lib/std.c +++ b/hawk/lib/std.c @@ -3051,7 +3051,7 @@ static ioattr_t* find_or_make_ioattr (hawk_rtx_t* rtx, hawk_htb_t* tab, const ha static int fnc_setioattr (hawk_rtx_t* rtx, const hawk_fnc_info_t* fi) { - hawk_t* hawk = hawk_rtx_gethawk(rtx); + /*hawk_t* hawk = hawk_rtx_gethawk(rtx);*/ rxtn_t* rxtn; hawk_val_t* v[3]; hawk_ooch_t* ptr[3]; diff --git a/hawk/lib/val.c b/hawk/lib/val.c index 45b64ddd..23bdb121 100644 --- a/hawk/lib/val.c +++ b/hawk/lib/val.c @@ -2293,7 +2293,8 @@ hawk_ooch_t* hawk_rtx_getvaloocstrwithcmgr (hawk_rtx_t* rtx, hawk_val_t* v, hawk rtx->ctos.b[fi].c[0] = c; rtx->ctos.b[fi].c[1] = '\0'; if (len) *len = l; - return &rtx->ctos.b[fi]; + HAWK_ASSERT ((void*)&rtx->ctos.b[fi] == (void*)rtx->ctos.b[fi].c); + return rtx->ctos.b[fi].c; } goto duplicate; diff --git a/hawk/lib/xma.c b/hawk/lib/xma.c index 307a3d8d..9a177745 100644 --- a/hawk/lib/xma.c +++ b/hawk/lib/xma.c @@ -261,7 +261,7 @@ int hawk_xma_init (hawk_xma_t* xma, hawk_mmgr_t* mmgr, void* zoneptr, hawk_oow_t /* let it be the head, which is natural with only a block */ xma->start = (hawk_uint8_t*)first; xma->end = xma->start + zonesize; - xma->internal = 1; + xma->internal = internal; /* initialize some statistical variables */ #if defined(HAWK_XMA_ENABLE_STAT)