fixed the infinite recursion issue in qse_awk_rtx_valtombsdupwithcmgr()
This commit is contained in:
parent
a6484a5605
commit
da20a99a10
@ -1759,11 +1759,7 @@ int qse_awk_initgbls (qse_awk_t* awk)
|
||||
{
|
||||
qse_size_t g;
|
||||
|
||||
g = qse_arr_insert (
|
||||
awk->parse.gbls,
|
||||
QSE_ARR_SIZE(awk->parse.gbls),
|
||||
(qse_char_t*)gtab[id].name,
|
||||
gtab[id].namelen);
|
||||
g = qse_arr_insert(awk->parse.gbls, QSE_ARR_SIZE(awk->parse.gbls), (qse_char_t*)gtab[id].name, gtab[id].namelen);
|
||||
if (g == QSE_ARR_NIL) return -1;
|
||||
|
||||
QSE_ASSERT ((int)g == id);
|
||||
@ -1772,8 +1768,7 @@ int qse_awk_initgbls (qse_awk_t* awk)
|
||||
awk->tree.ngbls++;
|
||||
}
|
||||
|
||||
QSE_ASSERT (awk->tree.ngbls_base ==
|
||||
QSE_AWK_MAX_GBL_ID-QSE_AWK_MIN_GBL_ID+1);
|
||||
QSE_ASSERT (awk->tree.ngbls_base == QSE_AWK_MAX_GBL_ID-QSE_AWK_MIN_GBL_ID+1);
|
||||
return 0;
|
||||
}
|
||||
|
||||
@ -1781,8 +1776,7 @@ static void adjust_static_globals (qse_awk_t* awk)
|
||||
{
|
||||
int id;
|
||||
|
||||
QSE_ASSERT (awk->tree.ngbls_base >=
|
||||
QSE_AWK_MAX_GBL_ID - QSE_AWK_MAX_GBL_ID + 1);
|
||||
QSE_ASSERT (awk->tree.ngbls_base >= QSE_AWK_MAX_GBL_ID - QSE_AWK_MAX_GBL_ID + 1);
|
||||
|
||||
for (id = QSE_AWK_MIN_GBL_ID; id <= QSE_AWK_MAX_GBL_ID; id++)
|
||||
{
|
||||
@ -2032,7 +2026,7 @@ int qse_awk_delgblwithmbs (qse_awk_t* awk, const qse_mchar_t* name)
|
||||
awk->parse.gbls.buf[n].name.ptr[0] = QSE_T('\0');
|
||||
awk->parse.gbls.buf[n].name.len = 0;
|
||||
*/
|
||||
n = qse_arr_uplete (awk->parse.gbls, n, 1);
|
||||
n = qse_arr_uplete(awk->parse.gbls, n, 1);
|
||||
QSE_ASSERT (n == 1);
|
||||
|
||||
return 0;
|
||||
@ -2074,7 +2068,6 @@ int qse_awk_delgblwithwcs (qse_awk_t* awk, const qse_wchar_t* name)
|
||||
}
|
||||
#endif
|
||||
|
||||
|
||||
/* invalidate the name if deletion is requested.
|
||||
* this approach does not delete the entry.
|
||||
* if qse_delgbl() is called with the same name
|
||||
@ -2084,7 +2077,7 @@ int qse_awk_delgblwithwcs (qse_awk_t* awk, const qse_wchar_t* name)
|
||||
awk->parse.gbls.buf[n].name.ptr[0] = QSE_T('\0');
|
||||
awk->parse.gbls.buf[n].name.len = 0;
|
||||
*/
|
||||
n = qse_arr_uplete (awk->parse.gbls, n, 1);
|
||||
n = qse_arr_uplete(awk->parse.gbls, n, 1);
|
||||
QSE_ASSERT (n == 1);
|
||||
|
||||
return 0;
|
||||
@ -2132,7 +2125,6 @@ int qse_awk_findgblwithwcs (qse_awk_t* awk, const qse_wchar_t* name)
|
||||
ncs.len = qse_wcslen(name);
|
||||
|
||||
#if defined(QSE_CHAR_IS_MCHAR)
|
||||
|
||||
mbs.ptr = qse_awk_wcstombsdup(awk, ncs.ptr, &mbs.len);
|
||||
if (!mbs.ptr) return -1;
|
||||
n = qse_arr_search(awk->parse.gbls, QSE_AWK_NUM_STATIC_GBLS, mbs.ptr, mbs.len);
|
||||
|
@ -1495,8 +1495,13 @@ int qse_awk_rtx_valtostr (qse_awk_rtx_t* rtx, const qse_awk_val_t* v, qse_awk_rt
|
||||
qse_mchar_t* qse_awk_rtx_valtombsdupwithcmgr (qse_awk_rtx_t* rtx, const qse_awk_val_t* v, qse_size_t* len, qse_cmgr_t* cmgr)
|
||||
{
|
||||
qse_mchar_t* mbs;
|
||||
qse_awk_val_type_t vtype;
|
||||
|
||||
if (QSE_AWK_RTX_GETVALTYPE(rtx,v) == QSE_AWK_VAL_MBS)
|
||||
vtype = QSE_AWK_RTX_GETVALTYPE(rtx,v);
|
||||
|
||||
switch (vtype)
|
||||
{
|
||||
case QSE_AWK_VAL_MBS:
|
||||
{
|
||||
mbs = qse_mbsxdup(((qse_awk_val_mbs_t*)v)->val.ptr, ((qse_awk_val_mbs_t*)v)->val.len, qse_awk_rtx_getmmgr(rtx));
|
||||
if (!mbs)
|
||||
@ -1506,28 +1511,64 @@ qse_mchar_t* qse_awk_rtx_valtombsdupwithcmgr (qse_awk_rtx_t* rtx, const qse_awk_
|
||||
}
|
||||
|
||||
if (len) *len = ((qse_awk_val_mbs_t*)v)->val.len;
|
||||
break;
|
||||
}
|
||||
else
|
||||
|
||||
case QSE_AWK_VAL_STR:
|
||||
{
|
||||
qse_char_t* str0;
|
||||
qse_size_t len0, len1;
|
||||
|
||||
str0 = qse_awk_rtx_getvalstr(rtx, v, &len0);
|
||||
if (!str0) return QSE_NULL;
|
||||
|
||||
#if defined(QSE_CHAR_IS_MCHAR)
|
||||
mbs = qse_strxdup(str0, len0, qse_awk_rtx_getmmgr(rtx));
|
||||
len1 = len0;
|
||||
#else
|
||||
mbs = qse_wcsntombsdupwithcmgr(str0, len0, &len1, qse_awk_rtx_getmmgr(rtx), cmgr);
|
||||
#endif
|
||||
qse_awk_rtx_freevalstr (rtx, v, str0);
|
||||
mbs = qse_strxdup(((qse_awk_val_str_t*)v)->val.ptr, ((qse_awk_val_str_t*)v)->val.len, qse_awk_rtx_getmmgr(rtx));
|
||||
if (!mbs)
|
||||
{
|
||||
qse_awk_rtx_seterror (rtx, QSE_AWK_ENOMEM, QSE_NULL, QSE_NULL);
|
||||
return QSE_NULL;
|
||||
}
|
||||
if (len) *len = len1;
|
||||
|
||||
if (len) *len = ((qse_awk_val_str_t*)v)->val.len;
|
||||
#else
|
||||
qse_size_t mbslen, wcslen;
|
||||
wcslen = ((qse_awk_val_str_t*)v)->val.len;
|
||||
mbs = qse_wcsntombsdupwithcmgr(((qse_awk_val_str_t*)v)->val.ptr, wcslen, &mbslen, qse_awk_rtx_getmmgr(rtx), cmgr);
|
||||
if (!mbs)
|
||||
{
|
||||
qse_awk_rtx_seterror (rtx, QSE_AWK_ENOMEM, QSE_NULL, QSE_NULL);
|
||||
return QSE_NULL;
|
||||
}
|
||||
|
||||
if (len) *len = mbslen;
|
||||
#endif
|
||||
break;
|
||||
}
|
||||
|
||||
default:
|
||||
{
|
||||
#if defined(QSE_CHAR_IS_MCHAR)
|
||||
qse_awk_rtx_valtostr_out_t out;
|
||||
|
||||
out.type = QSE_AWK_RTX_VALTOSTR_CPLDUP;
|
||||
if (qse_awk_rtx_valtostr(rtx, v, &out) <= -1) return QSE_NULL;
|
||||
|
||||
mbs = out.u.cpldup.ptr;
|
||||
if (len) *len = out.u.cpldup.len;
|
||||
#else
|
||||
qse_size_t mbslen;
|
||||
qse_awk_rtx_valtostr_out_t out;
|
||||
|
||||
out.type = QSE_AWK_RTX_VALTOSTR_CPLDUP;
|
||||
if (qse_awk_rtx_valtostr(rtx, v, &out) <= -1) return QSE_NULL;
|
||||
|
||||
mbs = qse_wcsntombsdupwithcmgr(out.u.cpldup.ptr, out.u.cpldup.len, &mbslen, qse_awk_rtx_getmmgr(rtx), cmgr);
|
||||
qse_awk_rtx_freemem (rtx, out.u.cpldup.ptr);
|
||||
if (!mbs)
|
||||
{
|
||||
qse_awk_rtx_seterror (rtx, QSE_AWK_ENOMEM, QSE_NULL, QSE_NULL);
|
||||
return QSE_NULL;
|
||||
}
|
||||
|
||||
if (len) *len = mbslen;
|
||||
#endif
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
return mbs;
|
||||
|
Loading…
Reference in New Issue
Block a user