added _instsize into qse_sed_t and removed qse_sed_getxtnstd()

This commit is contained in:
hyung-hwan 2019-06-25 01:21:00 +00:00
parent 5d627bc2a7
commit 74b48b87ec
7 changed files with 132 additions and 125 deletions

View File

@ -173,7 +173,7 @@ const qse_char_t* qse_awk_dflerrstr (qse_awk_t* awk, qse_awk_errnum_t errnum)
errstr[errnum]: QSE_T("unknown error");
}
qse_awk_errstr_t qse_awk_geterrstr (const qse_awk_t* awk)
qse_awk_errstr_t qse_awk_geterrstr (qse_awk_t* awk)
{
return awk->errstr;
}
@ -183,23 +183,23 @@ void qse_awk_seterrstr (qse_awk_t* awk, qse_awk_errstr_t errstr)
awk->errstr = errstr;
}
qse_awk_errnum_t qse_awk_geterrnum (const qse_awk_t* awk)
qse_awk_errnum_t qse_awk_geterrnum (qse_awk_t* awk)
{
return awk->errinf.num;
}
const qse_awk_loc_t* qse_awk_geterrloc (const qse_awk_t* awk)
const qse_awk_loc_t* qse_awk_geterrloc (qse_awk_t* awk)
{
return &awk->errinf.loc;
}
const qse_char_t* qse_awk_geterrmsg (const qse_awk_t* awk)
const qse_char_t* qse_awk_geterrmsg (qse_awk_t* awk)
{
return (awk->errinf.msg[0] == QSE_T('\0'))?
qse_awk_geterrstr(awk)(awk,awk->errinf.num): awk->errinf.msg;
}
void qse_awk_geterrinf (const qse_awk_t* awk, qse_awk_errinf_t* errinf)
void qse_awk_geterrinf (qse_awk_t* awk, qse_awk_errinf_t* errinf)
{
QSE_MEMCPY (errinf, &awk->errinf, QSE_SIZEOF(*errinf));
if (errinf->msg[0] == QSE_T('\0'))
@ -209,7 +209,7 @@ void qse_awk_geterrinf (const qse_awk_t* awk, qse_awk_errinf_t* errinf)
}
}
void qse_awk_geterror (const qse_awk_t* awk, qse_awk_errnum_t* errnum, const qse_char_t** errmsg, qse_awk_loc_t* errloc)
void qse_awk_geterror (qse_awk_t* awk, qse_awk_errnum_t* errnum, const qse_char_t** errmsg, qse_awk_loc_t* errloc)
{
if (errnum) *errnum = awk->errinf.num;
if (errmsg)
@ -266,23 +266,23 @@ void qse_awk_seterror (qse_awk_t* awk, qse_awk_errnum_t errnum, const qse_cstr_t
}
qse_awk_errnum_t qse_awk_rtx_geterrnum (const qse_awk_rtx_t* rtx)
qse_awk_errnum_t qse_awk_rtx_geterrnum (qse_awk_rtx_t* rtx)
{
return rtx->errinf.num;
}
const qse_awk_loc_t* qse_awk_rtx_geterrloc (const qse_awk_rtx_t* rtx)
const qse_awk_loc_t* qse_awk_rtx_geterrloc (qse_awk_rtx_t* rtx)
{
return &rtx->errinf.loc;
}
const qse_char_t* qse_awk_rtx_geterrmsg (const qse_awk_rtx_t* rtx)
const qse_char_t* qse_awk_rtx_geterrmsg (qse_awk_rtx_t* rtx)
{
return (rtx->errinf.msg[0] == QSE_T('\0')) ?
qse_awk_geterrstr(rtx->awk)(rtx->awk,rtx->errinf.num): rtx->errinf.msg;
}
void qse_awk_rtx_geterrinf (const qse_awk_rtx_t* rtx, qse_awk_errinf_t* errinf)
void qse_awk_rtx_geterrinf (qse_awk_rtx_t* rtx, qse_awk_errinf_t* errinf)
{
QSE_MEMCPY (errinf, &rtx->errinf, QSE_SIZEOF(*errinf));
if (errinf->msg[0] == QSE_T('\0'))
@ -293,7 +293,7 @@ void qse_awk_rtx_geterrinf (const qse_awk_rtx_t* rtx, qse_awk_errinf_t* errinf)
}
void qse_awk_rtx_geterror (
const qse_awk_rtx_t* rtx, qse_awk_errnum_t* errnum,
qse_awk_rtx_t* rtx, qse_awk_errnum_t* errnum,
const qse_char_t** errmsg, qse_awk_loc_t* errloc)
{
if (errnum != QSE_NULL) *errnum = rtx->errinf.num;

View File

@ -33,16 +33,31 @@
QSE_BEGIN_NAMESPACE(QSE)
/////////////////////////////////
struct xtn_t
{
Sed* sed;
};
#if defined(QSE_HAVE_INLINE)
static QSE_INLINE xtn_t* GET_XTN(qse_sed_t* sed) { return (xtn_t*)((qse_uint8_t*)qse_sed_getxtn(sed) - QSE_SIZEOF(xtn_t)); }
#else
#define GET_XTN(sed) ((xtn_t*)((qse_uint8_t*)qse_sed_getxtn(sed) - QSE_SIZEOF(xtn_t)))
#endif
int Sed::open ()
{
qse_sed_errnum_t errnum;
this->sed = qse_sed_open (this->getMmgr(), QSE_SIZEOF(Sed*), &errnum);
this->sed = qse_sed_open(this->getMmgr(), QSE_SIZEOF(xtn_t), &errnum);
if (!this->sed)
{
this->setError (errnum);
return -1;
}
*(Sed**)QSE_XTN(this->sed) = this;
this->sed->_instsize += QSE_SIZEOF(xtn_t);
xtn_t* xtn = GET_XTN(this->sed);
xtn->sed = this;
dflerrstr = qse_sed_geterrstr(this->sed);
qse_sed_seterrstr (sed, xerrstr);
@ -151,23 +166,22 @@ void Sed::setConsoleLine (size_t num)
qse_sed_setlinenum (this->sed, num);
}
Sed::ssize_t Sed::sin (
sed_t* s, io_cmd_t cmd, io_arg_t* arg, char_t* buf, size_t len)
Sed::ssize_t Sed::sin (sed_t* s, io_cmd_t cmd, io_arg_t* arg, char_t* buf, size_t len)
{
Sed* sed = *(Sed**)QSE_XTN(s);
xtn_t* xtn = GET_XTN(s);
Stream::Data iodata (sed, Stream::READ, arg);
Stream::Data iodata (xtn->sed, Stream::READ, arg);
try
{
switch (cmd)
{
case QSE_SED_IO_OPEN:
return sed->sstream->open (iodata);
return xtn->sed->sstream->open (iodata);
case QSE_SED_IO_CLOSE:
return sed->sstream->close (iodata);
return xtn->sed->sstream->close (iodata);
case QSE_SED_IO_READ:
return sed->sstream->read (iodata, buf, len);
return xtn->sed->sstream->read (iodata, buf, len);
default:
return -1;
}
@ -178,23 +192,22 @@ Sed::ssize_t Sed::sin (
}
}
Sed::ssize_t Sed::xin (
sed_t* s, io_cmd_t cmd, io_arg_t* arg, char_t* buf, size_t len)
Sed::ssize_t Sed::xin (sed_t* s, io_cmd_t cmd, io_arg_t* arg, char_t* buf, size_t len)
{
Sed* sed = *(Sed**)QSE_XTN(s);
xtn_t* xtn = GET_XTN(s);
Stream::Data iodata (sed, Stream::READ, arg);
Stream::Data iodata (xtn->sed, Stream::READ, arg);
try
{
switch (cmd)
{
case QSE_SED_IO_OPEN:
return sed->iostream->open (iodata);
return xtn->sed->iostream->open (iodata);
case QSE_SED_IO_CLOSE:
return sed->iostream->close (iodata);
return xtn->sed->iostream->close (iodata);
case QSE_SED_IO_READ:
return sed->iostream->read (iodata, buf, len);
return xtn->sed->iostream->read (iodata, buf, len);
default:
return -1;
}
@ -205,23 +218,22 @@ Sed::ssize_t Sed::xin (
}
}
Sed::ssize_t Sed::xout (
sed_t* s, io_cmd_t cmd, io_arg_t* arg, char_t* dat, size_t len)
Sed::ssize_t Sed::xout (sed_t* s, io_cmd_t cmd, io_arg_t* arg, char_t* dat, size_t len)
{
Sed* sed = *(Sed**)QSE_XTN(s);
xtn_t* xtn = GET_XTN(s);
Stream::Data iodata (sed, Stream::WRITE, arg);
Stream::Data iodata (xtn->sed, Stream::WRITE, arg);
try
{
switch (cmd)
{
case QSE_SED_IO_OPEN:
return sed->iostream->open (iodata);
return xtn->sed->iostream->open (iodata);
case QSE_SED_IO_CLOSE:
return sed->iostream->close (iodata);
return xtn->sed->iostream->close (iodata);
case QSE_SED_IO_WRITE:
return sed->iostream->write (iodata, dat, len);
return xtn->sed->iostream->write (iodata, dat, len);
default:
return -1;
}
@ -234,20 +246,20 @@ Sed::ssize_t Sed::xout (
const Sed::char_t* Sed::getErrorString (errnum_t num) const
{
QSE_ASSERT (dflerrstr != QSE_NULL);
return dflerrstr (sed, num);
QSE_ASSERT (this->dflerrstr != QSE_NULL);
return this->dflerrstr (sed, num);
}
const Sed::char_t* Sed::xerrstr (const sed_t* s, errnum_t num)
const Sed::char_t* Sed::xerrstr (sed_t* s, errnum_t num)
{
Sed* sed = *(Sed**)QSE_XTN(s);
xtn_t* xtn = GET_XTN(s);
try
{
return sed->getErrorString (num);
return xtn->sed->getErrorString (num);
}
catch (...)
{
return sed->dflerrstr (s, num);
return xtn->sed->dflerrstr (s, num);
}
}

View File

@ -38,7 +38,7 @@ static qse_sio_t* open_sio (StdSed::Stream::Data& io, const qse_char_t* file, in
{
qse_sio_t* sio;
sio = qse_sio_open (((StdSed::sed_t*)io)->mmgr, 0, file, flags);
sio = qse_sio_open(qse_sed_getmmgr((StdSed::sed_t*)io), 0, file, flags);
if (sio == QSE_NULL)
{
qse_cstr_t ea;
@ -59,7 +59,7 @@ static qse_sio_t* open_sio_std (StdSed::Stream::Data& io, qse_sio_std_t std, int
QSE_T("stderr"),
};
sio = qse_sio_openstd (((StdSed::sed_t*)io)->mmgr, 0, std, flags);
sio = qse_sio_openstd(qse_sed_getmmgr((StdSed::sed_t*)io), 0, std, flags);
if (sio == QSE_NULL)
{
qse_cstr_t ea;

View File

@ -27,8 +27,7 @@
#include "sed-prv.h"
#include "../cmn/mem-prv.h"
const qse_char_t* qse_sed_dflerrstr (
const qse_sed_t* sed, qse_sed_errnum_t errnum)
const qse_char_t* qse_sed_dflerrstr (qse_sed_t* sed, qse_sed_errnum_t errnum)
{
static const qse_char_t* errstr[] =
{
@ -76,7 +75,7 @@ const qse_char_t* qse_sed_dflerrstr (
errstr[errnum]: QSE_T("unknown error");
}
qse_sed_errstr_t qse_sed_geterrstr (const qse_sed_t* sed)
qse_sed_errstr_t qse_sed_geterrstr (qse_sed_t* sed)
{
return sed->errstr;
}
@ -86,24 +85,24 @@ void qse_sed_seterrstr (qse_sed_t* sed, qse_sed_errstr_t errstr)
sed->errstr = errstr;
}
qse_sed_errnum_t qse_sed_geterrnum (const qse_sed_t* sed)
qse_sed_errnum_t qse_sed_geterrnum (qse_sed_t* sed)
{
return sed->errnum;
}
const qse_sed_loc_t* qse_sed_geterrloc (const qse_sed_t* sed)
const qse_sed_loc_t* qse_sed_geterrloc (qse_sed_t* sed)
{
return &sed->errloc;
}
const qse_char_t* qse_sed_geterrmsg (const qse_sed_t* sed)
const qse_char_t* qse_sed_geterrmsg (qse_sed_t* sed)
{
return (sed->errmsg[0] == QSE_T('\0'))?
qse_sed_geterrstr(sed)(sed,sed->errnum): sed->errmsg;
}
void qse_sed_geterror (
const qse_sed_t* sed, qse_sed_errnum_t* errnum,
qse_sed_t* sed, qse_sed_errnum_t* errnum,
const qse_char_t** errmsg, qse_sed_loc_t* errloc)
{
if (errnum != QSE_NULL) *errnum = sed->errnum;

View File

@ -72,12 +72,12 @@ struct qse_sed_unknown_cid_t
*/
struct qse_sed_t
{
qse_mmgr_t* mmgr;
QSE_SED_HDR;
qse_sed_errstr_t errstr; /**< error string getter */
qse_sed_errnum_t errnum; /**< stores an error number */
qse_char_t errmsg[128]; /**< error message holder */
qse_sed_loc_t errloc; /**< location of the last error */
qse_sed_errstr_t errstr; /**< error string getter */
struct
{
@ -236,7 +236,7 @@ void qse_sed_fini (
);
const qse_char_t* qse_sed_dflerrstr (
const qse_sed_t* sed,
qse_sed_t* sed,
qse_sed_errnum_t errnum
);

View File

@ -91,13 +91,14 @@ void qse_sed_close (qse_sed_t* sed)
if (ecb->close) ecb->close (sed);
qse_sed_fini (sed);
QSE_MMGR_FREE (sed->mmgr, sed);
QSE_MMGR_FREE (sed->_mmgr, sed);
}
int qse_sed_init (qse_sed_t* sed, qse_mmgr_t* mmgr)
{
QSE_MEMSET (sed, 0, QSE_SIZEOF(*sed));
sed->mmgr = mmgr;
sed->_instsize = QSE_SIZEOF(*sed);
sed->_mmgr = mmgr;
sed->errstr = qse_sed_dflerrstr;
if (qse_str_init (&sed->tmp.rex, mmgr, 0) <= -1) goto oops_1;
@ -144,7 +145,7 @@ void qse_sed_fini (qse_sed_t* sed)
free_all_cids (sed);
if (sed->e.cutf.flds != sed->e.cutf.sflds)
QSE_MMGR_FREE (sed->mmgr, sed->e.cutf.flds);
qse_sed_freemem (sed, sed->e.cutf.flds);
qse_str_fini (&sed->e.txt.scratch);
qse_str_fini (&sed->e.txt.hold);
@ -155,16 +156,6 @@ void qse_sed_fini (qse_sed_t* sed)
qse_str_fini (&sed->tmp.rex);
}
qse_mmgr_t* qse_sed_getmmgr (qse_sed_t* sed)
{
return sed->mmgr;
}
void* qse_sed_getxtn (qse_sed_t* sed)
{
return QSE_XTN (sed);
}
int qse_sed_setopt (qse_sed_t* sed, qse_sed_opt_t id, const void* value)
{
switch (id)
@ -234,7 +225,7 @@ static void* build_rex (
if ((sed->opt.trait & QSE_SED_EXTENDEDREX) == 0) opt |= QSE_REX_NOBOUND;
rex = qse_buildrex (
sed->mmgr, sed->opt.depth.rex.build,
qse_sed_getmmgr(sed), sed->opt.depth.rex.build,
opt, str->ptr, str->len, QSE_NULL
);
if (rex == QSE_NULL)
@ -253,27 +244,27 @@ static void* build_rex (
if (ignorecase) xopt |= REG_ICASE;
if (sed->opt.trait & QSE_SED_EXTENDEDREX) xopt |= REG_EXTENDED;
rex = QSE_MMGR_ALLOC (sed->mmgr, QSE_SIZEOF(*rex));
rex = qse_sed_allocmem(sed, QSE_SIZEOF(*rex));
if (rex == QSE_NULL)
{
SETERR0 (sed, QSE_SED_ENOMEM, loc);
return QSE_NULL;
}
strz = qse_strxdup (str->ptr, str->len, sed->mmgr);
strz = qse_strxdup (str->ptr, str->len, qse_sed_getmmgr(sed));
if (strz == QSE_NULL)
{
QSE_MMGR_FREE (sed->mmgr, rex);
qse_sed_freemem (sed, rex);
SETERR0 (sed, QSE_SED_ENOMEM, loc);
return QSE_NULL;
}
xopt = regcomp (rex, strz, xopt);
QSE_MMGR_FREE (sed->mmgr, strz);
qse_sed_freemem (sed, strz);
if (xopt != 0)
{
QSE_MMGR_FREE (sed->mmgr, rex);
qse_sed_freemem (sed, rex);
SETERR1 (sed, QSE_SED_EREXBL, str->ptr, str->len, loc);
return QSE_NULL;
}
@ -284,7 +275,7 @@ static void* build_rex (
qse_tre_t* tre;
int opt = 0;
tre = qse_tre_open (sed->mmgr, 0);
tre = qse_tre_open(qse_sed_getmmgr(sed), 0);
if (tre == QSE_NULL)
{
SETERR0 (sed, QSE_SED_ENOMEM, loc);
@ -313,10 +304,10 @@ static void* build_rex (
static QSE_INLINE void free_rex (qse_sed_t* sed, void* rex)
{
#if defined(USE_REX)
qse_freerex (sed->mmgr, rex);
qse_freerex (qse_sed_getmmgr(sed), rex);
#elif defined(QSE_CHAR_IS_MCHAR) && defined(USE_REGEX)
regfree (rex);
QSE_MMGR_FREE (sed->mmgr, rex);
qse_sed_freemem (sed, rex);
#else
qse_tre_close (rex);
#endif
@ -335,14 +326,14 @@ static int matchtre (
if (opt & QSE_TRE_NOTBOL) xopt |= REG_NOTBOL;
strz = qse_strxdup (str->ptr, str->len, sed->mmgr);
strz = qse_strxdup(str->ptr, str->len, qse_sed_getmmgr(sed));
if (strz == QSE_NULL)
{
SETERR0 (sed, QSE_SED_ENOMEM, loc);
return -1;
}
xopt = regexec ((regex_t*)tre, strz, QSE_COUNTOF(match), match, xopt);
QSE_MMGR_FREE (sed->mmgr, strz);
qse_sed_freemem (sed, strz);
if (xopt == REG_NOMATCH) return 0;
#else
@ -573,7 +564,7 @@ static void free_all_command_blocks (qse_sed_t* sed)
qse_sed_cmd_blk_t* nxt = b->next;
while (b->len > 0) free_command (sed, &b->buf[--b->len]);
if (b != &sed->cmd.fb) QSE_MMGR_FREE (sed->mmgr, b);
if (b != &sed->cmd.fb) qse_sed_freemem (sed, b);
b = nxt;
}
@ -594,7 +585,7 @@ static void free_command (qse_sed_t* sed, qse_sed_cmd_t* cmd)
case QSE_SED_CMD_INSERT:
case QSE_SED_CMD_CHANGE:
if (cmd->u.text.ptr)
QSE_MMGR_FREE (sed->mmgr, cmd->u.text.ptr);
qse_sed_freemem (sed, cmd->u.text.ptr);
break;
case QSE_SED_CMD_READ_FILE:
@ -602,27 +593,27 @@ static void free_command (qse_sed_t* sed, qse_sed_cmd_t* cmd)
case QSE_SED_CMD_WRITE_FILE:
case QSE_SED_CMD_WRITE_FILELN:
if (cmd->u.file.ptr)
QSE_MMGR_FREE (sed->mmgr, cmd->u.file.ptr);
qse_sed_freemem (sed, cmd->u.file.ptr);
break;
case QSE_SED_CMD_BRANCH:
case QSE_SED_CMD_BRANCH_COND:
if (cmd->u.branch.label.ptr)
QSE_MMGR_FREE (sed->mmgr, cmd->u.branch.label.ptr);
qse_sed_freemem (sed, cmd->u.branch.label.ptr);
break;
case QSE_SED_CMD_SUBSTITUTE:
if (cmd->u.subst.file.ptr)
QSE_MMGR_FREE (sed->mmgr, cmd->u.subst.file.ptr);
qse_sed_freemem (sed, cmd->u.subst.file.ptr);
if (cmd->u.subst.rpl.ptr)
QSE_MMGR_FREE (sed->mmgr, cmd->u.subst.rpl.ptr);
qse_sed_freemem (sed, cmd->u.subst.rpl.ptr);
if (cmd->u.subst.rex && cmd->u.subst.rex != EMPTY_REX)
free_rex (sed, cmd->u.subst.rex);
break;
case QSE_SED_CMD_TRANSLATE:
if (cmd->u.transet.ptr)
QSE_MMGR_FREE (sed->mmgr, cmd->u.transet.ptr);
qse_sed_freemem (sed, cmd->u.transet.ptr);
break;
case QSE_SED_CMD_CUT:
@ -642,7 +633,7 @@ static void free_all_cids (qse_sed_t* sed)
while (sed->src.cid)
{
qse_sed_cid_t* next = sed->src.cid->next;
QSE_MMGR_FREE (sed->mmgr, sed->src.cid);
qse_sed_freemem (sed, sed->src.cid);
sed->src.cid = next;
}
}
@ -1023,7 +1014,7 @@ do { \
qse_cint_t c;
qse_str_t* t = QSE_NULL;
t = qse_str_open (sed->mmgr, 0, 128);
t = qse_str_open(qse_sed_getmmgr(sed), 0, 128);
if (t == QSE_NULL) goto oops;
c = CURSC (sed);
@ -1208,7 +1199,7 @@ static int get_branch_target (qse_sed_t* sed, qse_sed_cmd_t* cmd)
return terminate_command (sed);
}
t = qse_str_open (sed->mmgr, 0, 32);
t = qse_str_open(qse_sed_getmmgr(sed), 0, 32);
if (t == QSE_NULL)
{
SETERR0 (sed, QSE_SED_ENOMEM, QSE_NULL);
@ -1266,7 +1257,7 @@ static int get_file (qse_sed_t* sed, qse_cstr_t* xstr)
goto oops;
}
t = qse_str_open (sed->mmgr, 0, 32);
t = qse_str_open(qse_sed_getmmgr(sed), 0, 32);
if (t == QSE_NULL)
{
SETERR0 (sed, QSE_SED_ENOMEM, QSE_NULL);
@ -1366,7 +1357,7 @@ static int get_subst (qse_sed_t* sed, qse_sed_cmd_t* cmd)
t[0] = &sed->tmp.rex;
qse_str_clear (t[0]);
t[1] = qse_str_open (sed->mmgr, 0, 32);
t[1] = qse_str_open(qse_sed_getmmgr(sed), 0, 32);
if (t[1] == QSE_NULL)
{
SETERR0 (sed, QSE_SED_ENOMEM, QSE_NULL);
@ -1488,7 +1479,7 @@ static int get_transet (qse_sed_t* sed, qse_sed_cmd_t* cmd)
goto oops;
}
t = qse_str_open (sed->mmgr, 0, 32);
t = qse_str_open(qse_sed_getmmgr(sed), 0, 32);
if (t == QSE_NULL)
{
SETERR0 (sed, QSE_SED_ENOMEM, QSE_NULL);
@ -1592,7 +1583,7 @@ static void free_all_cut_selector_blocks (qse_sed_t* sed, qse_sed_cmd_t* cmd)
for (b = cmd->u.cut.fb; b; b = next)
{
next = b->next;
QSE_MMGR_FREE (sed->mmgr, b);
qse_sed_freemem (sed, b);
}
cmd->u.cut.lb = QSE_NULL;
@ -2662,7 +2653,7 @@ static int link_append (qse_sed_t* sed, qse_sed_cmd_t* cmd)
qse_sed_app_t* app;
/* otherwise, link it using a linked list */
app = QSE_MMGR_ALLOC (sed->mmgr, QSE_SIZEOF(*app));
app = qse_sed_allocmem(sed, QSE_SIZEOF(*app));
if (app == QSE_NULL)
{
SETERR0 (sed, QSE_SED_ENOMEM, &cmd->loc);
@ -2690,7 +2681,7 @@ static void free_appends (qse_sed_t* sed)
while (app)
{
next = app->next;
QSE_MMGR_FREE (sed->mmgr, app);
qse_sed_freemem (sed, app);
app = next;
}
@ -2829,7 +2820,7 @@ static int do_subst (qse_sed_t* sed, qse_sed_cmd_t* cmd)
#if defined(USE_REX)
n = qse_matchrex (
sed->mmgr,
qse_sed_getmmgr(sed),
sed->opt.depth.rex.match,
rex, opt,
&str, &cur, &mat, &errnum
@ -3292,7 +3283,7 @@ static int match_a (qse_sed_t* sed, qse_sed_cmd_t* cmd, qse_sed_adr_t* a)
}
#if defined(USE_REX)
n = qse_matchrex (
sed->mmgr,
qse_sed_getmmgr(sed),
sed->opt.depth.rex.match,
rex, 0,
&line, &line,
@ -3868,7 +3859,7 @@ static int init_command_block_for_exec (qse_sed_t* sed, qse_sed_cmd_blk_t* b)
c->u.branch.target = QSE_MAP_VPTR(pair);
/* free resolved label name */
QSE_MMGR_FREE (sed->mmgr, lab->ptr);
qse_sed_freemem (sed, lab->ptr);
lab->ptr = QSE_NULL;
lab->len = 0;
}
@ -3980,7 +3971,7 @@ int qse_sed_exec (qse_sed_t* sed, qse_sed_io_impl_t inf, qse_sed_io_impl_t outf)
sed->e.out.eof = 0;
sed->e.out.len = 0;
if (qse_map_init (
&sed->e.out.files, sed->mmgr,
&sed->e.out.files, qse_sed_getmmgr(sed),
128, 70, QSE_SIZEOF(qse_char_t), 1) <= -1)
{
SETERR0 (sed, QSE_SED_ENOMEM, QSE_NULL);
@ -3994,7 +3985,7 @@ int qse_sed_exec (qse_sed_t* sed, qse_sed_io_impl_t inf, qse_sed_io_impl_t outf)
sed->e.in.len = 0;
sed->e.in.pos = 0;
sed->e.in.num = 0;
if (qse_str_init (&sed->e.in.line, sed->mmgr, 256) <= -1)
if (qse_str_init (&sed->e.in.line, qse_sed_getmmgr(sed), 256) <= -1)
{
qse_map_fini (&sed->e.out.files);
SETERR0 (sed, QSE_SED_ENOMEM, QSE_NULL);
@ -4132,8 +4123,7 @@ const qse_char_t* qse_sed_setcompid (qse_sed_t* sed, const qse_char_t* id)
if (id == QSE_NULL) id = QSE_T("");
len = qse_strlen (id);
cid = QSE_MMGR_ALLOC (sed->mmgr,
QSE_SIZEOF(*cid) + ((len + 1) * QSE_SIZEOF(*id)));
cid = qse_sed_allocmem(sed, QSE_SIZEOF(*cid) + ((len + 1) * QSE_SIZEOF(*id)));
if (cid == QSE_NULL)
{
/* mark that an error has occurred */
@ -4175,15 +4165,14 @@ void qse_sed_pushecb (qse_sed_t* sed, qse_sed_ecb_t* ecb)
void* qse_sed_allocmem (qse_sed_t* sed, qse_size_t size)
{
void* ptr = QSE_MMGR_ALLOC (sed->mmgr, size);
if (ptr == QSE_NULL)
qse_sed_seterrnum (sed, QSE_SED_ENOMEM, QSE_NULL);
void* ptr = QSE_MMGR_ALLOC(qse_sed_getmmgr(sed), size);
if (ptr == QSE_NULL) qse_sed_seterrnum (sed, QSE_SED_ENOMEM, QSE_NULL);
return ptr;
}
void* qse_sed_callocmem (qse_sed_t* sed, qse_size_t size)
{
void* ptr = QSE_MMGR_ALLOC (sed->mmgr, size);
void* ptr = QSE_MMGR_ALLOC(qse_sed_getmmgr(sed), size);
if (ptr) QSE_MEMSET (ptr, 0, size);
else qse_sed_seterrnum (sed, QSE_SED_ENOMEM, QSE_NULL);
return ptr;
@ -4191,14 +4180,14 @@ void* qse_sed_callocmem (qse_sed_t* sed, qse_size_t size)
void* qse_sed_reallocmem (qse_sed_t* sed, void* ptr, qse_size_t size)
{
void* nptr = QSE_MMGR_REALLOC (sed->mmgr, ptr, size);
void* nptr = QSE_MMGR_REALLOC(qse_sed_getmmgr(sed), ptr, size);
if (nptr == QSE_NULL) qse_sed_seterrnum (sed, QSE_SED_ENOMEM, QSE_NULL);
return nptr;
}
void qse_sed_freemem (qse_sed_t* sed, void* ptr)
{
QSE_MMGR_FREE (sed->mmgr, ptr);
QSE_MMGR_FREE (qse_sed_getmmgr(sed), ptr);
}

View File

@ -61,6 +61,11 @@ struct xtn_t
} e;
};
#if defined(QSE_HAVE_INLINE)
static QSE_INLINE xtn_t* GET_XTN(qse_sed_t* sed) { return (xtn_t*)((qse_uint8_t*)qse_sed_getxtn(sed) - QSE_SIZEOF(xtn_t)); }
#else
#define GET_XTN(sed) ((xtn_t*)((qse_uint8_t*)qse_sed_getxtn(sed) - QSE_SIZEOF(xtn_t)))
#endif
static int int_to_str (qse_size_t val, qse_char_t* buf, qse_size_t buflen)
{
@ -107,12 +112,14 @@ qse_sed_t* qse_sed_openstd (qse_size_t xtnsize, qse_sed_errnum_t* errnum)
qse_sed_t* qse_sed_openstdwithmmgr (qse_mmgr_t* mmgr, qse_size_t xtnsize, qse_sed_errnum_t* errnum)
{
return qse_sed_open (mmgr, QSE_SIZEOF(xtn_t) + xtnsize, errnum);
}
qse_sed_t* sed;
void* qse_sed_getxtnstd (qse_sed_t* sed)
{
return (void*)((xtn_t*)QSE_XTN(sed) + 1);
sed = qse_sed_open (mmgr, QSE_SIZEOF(xtn_t) + xtnsize, errnum);
if (!sed) return QSE_NULL;
sed->_instsize += QSE_SIZEOF(xtn_t);
return sed;
}
static int verify_iostd_in (qse_sed_t* sed, qse_sed_iostd_t in[])
@ -145,7 +152,7 @@ static qse_sio_t* open_sio_file (qse_sed_t* sed, const qse_char_t* file, int fla
{
qse_sio_t* sio;
sio = qse_sio_open (sed->mmgr, 0, file, flags);
sio = qse_sio_open(qse_sed_getmmgr(sed), 0, file, flags);
if (sio == QSE_NULL)
{
qse_cstr_t ea;
@ -173,7 +180,7 @@ static qse_sio_t* open_sio_std (qse_sed_t* sed, qse_sio_std_t std, int flags)
{
qse_sio_t* sio;
sio = qse_sio_openstd (sed->mmgr, 0, std, flags);
sio = qse_sio_openstd(qse_sed_getmmgr(sed), 0, std, flags);
if (sio == QSE_NULL)
{
qse_cstr_t ea;
@ -214,7 +221,7 @@ static void close_main_stream (
static int open_input_stream (
qse_sed_t* sed, qse_sed_io_arg_t* arg, qse_sed_iostd_t* io, xtn_in_t* base)
{
xtn_t* xtn = (xtn_t*) QSE_XTN (sed);
xtn_t* xtn = GET_XTN(sed);
QSE_ASSERT (io != QSE_NULL);
switch (io->type)
@ -295,7 +302,7 @@ static int open_input_stream (
static int open_output_stream (qse_sed_t* sed, qse_sed_io_arg_t* arg, qse_sed_iostd_t* io)
{
xtn_t* xtn = (xtn_t*) QSE_XTN (sed);
xtn_t* xtn = GET_XTN(sed);
QSE_ASSERT (io != QSE_NULL);
switch (io->type)
@ -334,7 +341,7 @@ static int open_output_stream (qse_sed_t* sed, qse_sed_io_arg_t* arg, qse_sed_io
case QSE_SED_IOSTD_STR:
/* don't store anything to arg->handle */
xtn->e.out.memstr = qse_str_open (sed->mmgr, 0, 512);
xtn->e.out.memstr = qse_str_open(qse_sed_getmmgr(sed), 0, 512);
if (xtn->e.out.memstr == QSE_NULL)
{
qse_sed_seterrnum (sed, QSE_SED_ENOMEM, QSE_NULL);
@ -362,7 +369,7 @@ static qse_ssize_t read_input_stream (
qse_sed_t* sed, qse_sed_io_arg_t* arg,
qse_char_t* buf, qse_size_t len, xtn_in_t* base)
{
xtn_t* xtn = (xtn_t*) QSE_XTN (sed);
xtn_t* xtn = GET_XTN(sed);
qse_sed_iostd_t* io, * next;
void* old, * new;
qse_ssize_t n = 0;
@ -485,7 +492,7 @@ static qse_ssize_t s_in (
qse_sed_t* sed, qse_sed_io_cmd_t cmd, qse_sed_io_arg_t* arg,
qse_char_t* buf, qse_size_t len)
{
xtn_t* xtn = (xtn_t*) QSE_XTN (sed);
xtn_t* xtn = GET_XTN(sed);
switch (cmd)
{
@ -523,7 +530,7 @@ static qse_ssize_t x_in (
qse_char_t* buf, qse_size_t len)
{
qse_sio_t* sio;
xtn_t* xtn = (xtn_t*) QSE_XTN (sed);
xtn_t* xtn = GET_XTN(sed);
switch (cmd)
{
@ -623,7 +630,7 @@ static qse_ssize_t x_out (
qse_sed_t* sed, qse_sed_io_cmd_t cmd, qse_sed_io_arg_t* arg,
qse_char_t* dat, qse_size_t len)
{
xtn_t* xtn = (xtn_t*) QSE_XTN (sed);
xtn_t* xtn = GET_XTN(sed);
qse_sio_t* sio;
switch (cmd)
@ -769,7 +776,7 @@ static qse_ssize_t x_out (
int qse_sed_compstd (qse_sed_t* sed, qse_sed_iostd_t in[], qse_size_t* count)
{
xtn_t* xtn = (xtn_t*) QSE_XTN (sed);
xtn_t* xtn = GET_XTN(sed);
int ret;
if (in == QSE_NULL)
@ -795,7 +802,7 @@ int qse_sed_execstd (
qse_sed_t* sed, qse_sed_iostd_t in[], qse_sed_iostd_t* out)
{
int n;
xtn_t* xtn = (xtn_t*) QSE_XTN (sed);
xtn_t* xtn = GET_XTN(sed);
if (in && verify_iostd_in (sed, in) <= -1) return -1;