fixed a segfault error in Awk.cpp for missed rtx->_instsize adjustment

This commit is contained in:
hyung-hwan 2019-09-03 16:46:57 +00:00
parent 8c6a7ae29c
commit f89efc150a
6 changed files with 19 additions and 26 deletions

View File

@ -1391,9 +1391,6 @@ int Awk::open ()
#endif
// push the call back after everything else is ok.
// the uponDemise() is called only if Awk::open() is fully successful.
// it won't be called when qse_awk_close() is called for functionMap
// opening failure above.
qse_awk_pushecb (this->awk, &xtn->ecb);
return 0;
}
@ -1457,14 +1454,14 @@ Awk::Run* Awk::parse (Source& in, Source& out)
sio.in = readSource;
sio.out = (source_writer == QSE_NULL)? QSE_NULL: writeSource;
int n = qse_awk_parse (awk, &sio);
int n = qse_awk_parse(awk, &sio);
if (n <= -1)
{
this->retrieveError ();
return QSE_NULL;
}
if (init_runctx() <= -1) return QSE_NULL;
if (this->init_runctx() <= -1) return QSE_NULL;
return &this->runctx;
}
@ -1602,6 +1599,7 @@ int Awk::init_runctx ()
return -1;
}
rtx->_instsize += QSE_SIZEOF(rxtn_t);
runctx.rtx = rtx;
rxtn_t* rxtn = GET_RXTN(rtx);

View File

@ -188,7 +188,7 @@ void StdAwk::uponClosing ()
StdAwk::Run* StdAwk::parse (Source& in, Source& out)
{
Run* run = Awk::parse (in, out);
Run* run = Awk::parse(in, out);
if (this->cmgrtab_inited)
{
@ -203,19 +203,16 @@ StdAwk::Run* StdAwk::parse (Source& in, Source& out)
// but if you call parse() multiple times while
// setting and unsetting QSE_AWK_RIO in-between,
// cmgrtab can still be initialized when QSE_AWK_RIO is not set.
if (qse_htb_init (
&this->cmgrtab, this->getMmgr(), 256, 70,
QSE_SIZEOF(qse_char_t), 1) <= -1)
if (qse_htb_init(&this->cmgrtab, this->getMmgr(), 256, 70, QSE_SIZEOF(qse_char_t), 1) <= -1)
{
this->setError (QSE_AWK_ENOMEM);
return QSE_NULL;
}
qse_htb_setstyle (&this->cmgrtab,
qse_gethtbstyle(QSE_HTB_STYLE_INLINE_KEY_COPIER));
qse_htb_setstyle (&this->cmgrtab, qse_gethtbstyle(QSE_HTB_STYLE_INLINE_KEY_COPIER));
this->cmgrtab_inited = true;
}
if (run && make_additional_globals (run) <= -1) return QSE_NULL;
if (run && make_additional_globals(run) <= -1) return QSE_NULL;
return run;
}

View File

@ -1218,8 +1218,7 @@ static int prepare_globals (qse_awk_rtx_t* rtx)
}
/* override NF to zero */
if (qse_awk_rtx_setgbl (
rtx, QSE_AWK_GBL_NF, QSE_AWK_VAL_ZERO) <= -1) goto oops;
if (qse_awk_rtx_setgbl(rtx, QSE_AWK_GBL_NF, QSE_AWK_VAL_ZERO) <= -1) goto oops;
/* return success */
return 0;
@ -1277,7 +1276,7 @@ static int defaultify_globals (qse_awk_rtx_t* rtx)
QSE_ASSERT (RTX_STACK_GBL(rtx,gtab[i].idx) == qse_awk_val_nil);
if (qse_awk_rtx_setgbl (rtx, gtab[i].idx, tmp) == -1)
if (qse_awk_rtx_setgbl(rtx, gtab[i].idx, tmp) == -1)
{
for (j = 0; j < i; j++)
{

View File

@ -1656,7 +1656,7 @@ static int open_rio_console (qse_awk_rtx_t* rtx, qse_awk_rio_arg_t* riod)
* 'BEGIN { ARGV[1]="file3"; }
* { print $0; }' file1 file2
*/
argv = qse_awk_rtx_getgbl (rtx, xtn->gbl_argv);
argv = qse_awk_rtx_getgbl(rtx, xtn->gbl_argv);
QSE_ASSERT (argv != QSE_NULL);
QSE_ASSERT (QSE_AWK_RTX_GETVALTYPE (rtx, argv) == QSE_AWK_VAL_MAP);
@ -1961,7 +1961,7 @@ static int build_argcv (
}
else argc = 1;
v_argc = qse_awk_rtx_makeintval (rtx, (qse_awk_int_t)argc);
v_argc = qse_awk_rtx_makeintval(rtx, (qse_awk_int_t)argc);
if (v_argc == QSE_NULL)
{
qse_awk_rtx_refdownval (rtx, v_argv);
@ -1970,14 +1970,14 @@ static int build_argcv (
qse_awk_rtx_refupval (rtx, v_argc);
if (qse_awk_rtx_setgbl (rtx, argc_id, v_argc) <= -1)
if (qse_awk_rtx_setgbl(rtx, argc_id, v_argc) <= -1)
{
qse_awk_rtx_refdownval (rtx, v_argc);
qse_awk_rtx_refdownval (rtx, v_argv);
return -1;
}
if (qse_awk_rtx_setgbl (rtx, argv_id, v_argv) <= -1)
if (qse_awk_rtx_setgbl(rtx, argv_id, v_argv) <= -1)
{
qse_awk_rtx_refdownval (rtx, v_argc);
qse_awk_rtx_refdownval (rtx, v_argv);
@ -1990,8 +1990,7 @@ static int build_argcv (
return 0;
}
static int __build_environ (
qse_awk_rtx_t* rtx, int gbl_id, qse_env_char_t* envarr[])
static int __build_environ (qse_awk_rtx_t* rtx, int gbl_id, qse_env_char_t* envarr[])
{
qse_awk_val_t* v_env;
qse_awk_val_t* v_tmp;

View File

@ -56,12 +56,12 @@ void* Mmgr::callocate (qse_size_t n, bool raise_exception) /*QSE_CPP_THREXCEPT1(
#if 0
#if defined(__GNUC__)
static StdMmgr __attribute__((init_priority(101))) std_dfl_mmgr; <- this solved the problem
static StdMmgr __attribute__((init_priority(101))) std_dfl_mmgr; //<- this solved the problem
#else
static StdMmgr std_dfl_mmgr; <-- has an issue for undefined initialization order
static StdMmgr std_dfl_mmgr; //<-- has an issue for undefined initialization order
#endif
Mmgr* Mmgr::dfl_mmgr = &std_dfl_mmgr;
//Mmgr* Mmgr::dfl_mmgr = StdMmgr::getInstance(); <--- has an issue as well
//Mmgr* Mmgr::dfl_mmgr = StdMmgr::getInstance(); //<--- has an issue as well
Mmgr* Mmgr::getDFL () QSE_CPP_NOEXCEPT
{
return Mmgr::dfl_mmgr;

View File

@ -277,7 +277,7 @@ htb_t* qse_htb_open (
htb = (htb_t*) QSE_MMGR_ALLOC (mmgr, SIZEOF(htb_t) + xtnsize);
if (htb == QSE_NULL) return QSE_NULL;
if (qse_htb_init (htb, mmgr, capa, factor, kscale, vscale) <= -1)
if (qse_htb_init(htb, mmgr, capa, factor, kscale, vscale) <= -1)
{
QSE_MMGR_FREE (mmgr, htb);
return QSE_NULL;
@ -313,7 +313,7 @@ int qse_htb_init (
QSE_MEMSET (htb, 0, SIZEOF(*htb));
htb->mmgr = mmgr;
htb->bucket = QSE_MMGR_ALLOC (mmgr, capa*SIZEOF(pair_t*));
htb->bucket = QSE_MMGR_ALLOC(mmgr, capa * SIZEOF(pair_t*));
if (htb->bucket == QSE_NULL) return -1;
/*for (i = 0; i < capa; i++) htb->bucket[i] = QSE_NULL;*/