_instsize into qse_xli_t and qse_json_t

This commit is contained in:
hyung-hwan 2019-06-24 14:24:14 +00:00
parent 35a24a56d1
commit 5d627bc2a7
16 changed files with 130 additions and 157 deletions

View File

@ -160,15 +160,6 @@ QSE_EXPORT qse_awk_rtx_t* qse_awk_rtx_openstd (
qse_cmgr_t* cmgr
);
/**
* The qse_awk_rtx_getxtnstd() function gets the pointer to extension area
* created with qse_awk_rtx_openstd().
*/
QSE_EXPORT void* qse_awk_rtx_getxtnstd (
qse_awk_rtx_t* rtx
);
/**
* The qse_awk_rtx_getiocmgrstd() function gets the current character
* manager associated with a particular I/O target indicated by the name

View File

@ -35,6 +35,18 @@
*/
typedef struct qse_json_t qse_json_t;
#define QSE_JSON_HDR \
qse_size_t _instsize; \
qse_mmgr_t* _mmgr; \
qse_cmgr_t* _cmgr
typedef struct qse_json_alt_t qse_json_alt_t;
struct qse_json_alt_t
{
/* ensure that qse_json_t matches the beginning part of qse_json_t */
QSE_JSON_HDR;
};
enum qse_json_errnum_t
{
QSE_JSON_ENOERR = 0,
@ -155,22 +167,17 @@ QSE_EXPORT int qse_json_getoption (
);
QSE_EXPORT void* qse_json_getxtn (
qse_json_t* json
);
QSE_EXPORT qse_mmgr_t* qse_json_getmmgr (
qse_json_t* json
);
QSE_EXPORT qse_cmgr_t* qse_json_getcmgr (
qse_json_t* json
);
QSE_EXPORT void qse_json_setcmgr (
qse_json_t* json,
qse_cmgr_t* cmgr
);
#if defined(QSE_HAVE_INLINE)
static QSE_INLINE void* qse_json_getxtn (qse_json_t* json) { return (void*)((qse_uint8_t*)json + ((qse_json_alt_t*)json)->_instsize); }
static QSE_INLINE qse_mmgr_t* qse_json_getmmgr (qse_json_t* json) { return ((qse_json_alt_t*)json)->_mmgr; }
static QSE_INLINE qse_cmgr_t* qse_json_getcmgr (qse_json_t* json) { return ((qse_json_alt_t*)json)->_cmgr; }
static QSE_INLINE void qse_json_setcmgr (qse_json_t* json, qse_cmgr_t* cmgr) { ((qse_json_alt_t*)json)->_cmgr = cmgr; }
#else
# define qse_json_getxtn(json) ((void*)((qse_uint8_t*)json + ((qse_json_alt_t*)json)->_instsize))
# define qse_json_getmmgr(json) (((qse_json_alt_t*)(json))->_mmgr)
# define qse_json_getcmgr(json) (((qse_json_alt_t*)(json))->_cmgr)
# define qse_json_setcmgr(json,_cmgr) (((qse_json_alt_t*)(json))->_cmgr = (_cmgr))
#endif /* QSE_HAVE_INLINE */
QSE_EXPORT qse_json_errnum_t qse_json_geterrnum (

View File

@ -115,15 +115,6 @@ QSE_EXPORT qse_xli_t* qse_xli_openstdwithmmgr (
qse_xli_errnum_t* errnum
);
/**
* The qse_xli_getxtnstd() gets the pointer to extension area created with
* qse_xli_openstd() or qse_xli_openstdwithmmgr(). You must not call
* qse_xli_getxtn() for sunch an object.
*/
QSE_EXPORT void* qse_xli_getxtnstd (
qse_xli_t* xli
);
QSE_EXPORT int qse_xli_readstd (
qse_xli_t* xli,
qse_xli_iostd_t* in

View File

@ -50,6 +50,17 @@
typedef struct qse_xli_t qse_xli_t;
#define QSE_XLI_HDR \
qse_size_t _instsize; \
qse_mmgr_t* _mmgr
typedef struct qse_xli_alt_t qse_xli_alt_t;
struct qse_xli_alt_t
{
/* ensure that qse_xli_t matches the beginning part of qse_xli_t */
QSE_XLI_HDR;
};
enum qse_xli_errnum_t
{
QSE_XLI_ENOERR, /**< no error */
@ -482,13 +493,13 @@ QSE_EXPORT void qse_xli_close (
qse_xli_t* xli
);
QSE_EXPORT qse_mmgr_t* qse_xli_getmmgr (
qse_xli_t* xli
);
QSE_EXPORT void* qse_xli_getxtn (
qse_xli_t* xli
);
#if defined(QSE_HAVE_INLINE)
static QSE_INLINE void* qse_xli_getxtn (qse_xli_t* xli) { return (void*)((qse_uint8_t*)xli + ((qse_xli_alt_t*)xli)->_instsize); }
static QSE_INLINE qse_mmgr_t* qse_xli_getmmgr (qse_xli_t* xli) { return ((qse_xli_alt_t*)xli)->_mmgr; }
#else
# define qse_xli_getxtn(xli) ((void*)((qse_uint8_t*)xli + ((qse_xli_alt_t*)xli)->_instsize))
# define qse_xli_getmmgr(xli) (((qse_xli_alt_t*)(xli))->_mmgr)
#endif /* QSE_HAVE_INLINE */
QSE_EXPORT void qse_xli_pushecb (
qse_xli_t* xli,

View File

@ -94,7 +94,7 @@ qse_awk_t* qse_awk_open (qse_mmgr_t* mmgr, qse_size_t xtnsize, const qse_awk_prm
QSE_MMGR_FREE (mmgr, awk);
awk = QSE_NULL;
}
else QSE_MEMSET (awk + 1, 0, xtnsize);
else QSE_MEMSET (QSE_XTN(awk), 0, xtnsize);
}
else if (errnum) *errnum = QSE_AWK_ENOMEM;

View File

@ -26,7 +26,7 @@
#include "awk-prv.h"
const qse_char_t* qse_awk_dflerrstr (const qse_awk_t* awk, qse_awk_errnum_t errnum)
const qse_char_t* qse_awk_dflerrstr (qse_awk_t* awk, qse_awk_errnum_t errnum)
{
static const qse_char_t* errstr[] =
{

View File

@ -31,7 +31,7 @@
extern "C" {
#endif
const qse_char_t* qse_awk_dflerrstr (const qse_awk_t* awk, qse_awk_errnum_t errnum);
const qse_char_t* qse_awk_dflerrstr (qse_awk_t* awk, qse_awk_errnum_t errnum);
#if defined(__cplusplus)
}

View File

@ -527,6 +527,8 @@ qse_awk_t* qse_awk_openstdwithmmgr (qse_mmgr_t* mmgr, qse_size_t xtnsize, qse_aw
awk = qse_awk_open(mmgr, QSE_SIZEOF(xtn_t) + xtnsize, &prm, errnum);
if (!awk) return QSE_NULL;
/* adjust the object size by the sizeof xtn_t so that qse_getxtn() returns the right pointer. */
awk->_instsize += QSE_SIZEOF(xtn_t);
#if defined(USE_DLFCN)
if (qse_awk_setopt(awk, QSE_AWK_MODPOSTFIX, QSE_T(".so")) <= -1)
@ -536,9 +538,6 @@ qse_awk_t* qse_awk_openstdwithmmgr (qse_mmgr_t* mmgr, qse_size_t xtnsize, qse_aw
}
#endif
/* adjust the object size by the sizeof xtn_t so that qse_getxtn() returns the right pointer. */
awk->_instsize += QSE_SIZEOF(xtn_t);
/* initialize extension */
xtn = GET_XTN(awk);
/* the extension area has been cleared in qse_awk_open().

View File

@ -75,9 +75,7 @@ struct qse_json_state_node_t
struct qse_json_t
{
qse_mmgr_t* mmgr;
qse_cmgr_t* cmgr;
qse_json_prim_t prim;
QSE_JSON_HDR;
qse_json_errnum_t errnum;
struct
@ -87,6 +85,8 @@ struct qse_json_t
/*qse_size_t len;*/
} errmsg;
qse_json_prim_t prim;
struct
{
int trait;
@ -276,7 +276,7 @@ static int handle_string_value_char (qse_json_t* json, qse_cint_t c)
qse_mchar_t bcsbuf[QSE_MBLEN_MAX];
qse_size_t n;
n = json->cmgr->wctomb(json->state_stack->u.sv.acc, bcsbuf, QSE_COUNTOF(bcsbuf));
n = json->_cmgr->wctomb(json->state_stack->u.sv.acc, bcsbuf, QSE_COUNTOF(bcsbuf));
if (n == 0 || n > QSE_COUNTOF(bcsbuf))
{
/* illegal character or buffer to small */
@ -786,7 +786,7 @@ static int feed_json_data (qse_json_t* json, const qse_mchar_t* data, qse_size_t
qse_size_t n;
bcslen = end - ptr;
n = json->cmgr->mbtowc(ptr, bcslen, &uc);
n = json->_cmgr->mbtowc(ptr, bcslen, &uc);
if (n == 0)
{
/* invalid sequence */
@ -834,8 +834,9 @@ qse_json_t* qse_json_open (qse_mmgr_t* mmgr, qse_size_t xtnsize, qse_json_prim_t
}
QSE_MEMSET (json, 0, QSE_SIZEOF(*json) + xtnsize);
json->mmgr = mmgr;
json->cmgr = qse_getdflcmgr();
json->_instsize = QSE_SIZEOF(*json);
json->_mmgr = mmgr;
json->_cmgr = qse_getdflcmgr();
json->prim = *prim;
json->state_top.state = QSE_JSON_STATE_START;
@ -849,7 +850,7 @@ void qse_json_close (qse_json_t* json)
{
pop_all_states (json);
if (json->tok.ptr) qse_json_freemem (json, json->tok.ptr);
QSE_MMGR_FREE (json->mmgr, json);
QSE_MMGR_FREE (json->_mmgr, json);
}
int qse_json_setoption (qse_json_t* json, qse_json_option_t id, const void* value)
@ -878,27 +879,6 @@ int qse_json_getoption (qse_json_t* json, qse_json_option_t id, void* value)
return -1;
}
void* qse_json_getxtn (qse_json_t* json)
{
return (void*)(json + 1);
}
qse_mmgr_t* qse_json_getmmgr (qse_json_t* json)
{
return json->mmgr;
}
qse_cmgr_t* qse_json_getcmgr (qse_json_t* json)
{
return json->cmgr;
}
void qse_json_setcmgr (qse_json_t* json, qse_cmgr_t* cmgr)
{
json->cmgr = cmgr;
}
qse_json_errnum_t qse_json_geterrnum (qse_json_t* json)
{
return json->errnum;
@ -951,7 +931,7 @@ void* qse_json_allocmem (qse_json_t* json, qse_size_t size)
{
void* ptr;
ptr = QSE_MMGR_ALLOC(json->mmgr, size);
ptr = QSE_MMGR_ALLOC(qse_json_getmmgr(json), size);
if (!ptr) qse_json_seterrnum (json, QSE_JSON_ENOMEM);
return ptr;
}
@ -960,7 +940,7 @@ void* qse_json_callocmem (qse_json_t* json, qse_size_t size)
{
void* ptr;
ptr = QSE_MMGR_ALLOC(json->mmgr, size);
ptr = QSE_MMGR_ALLOC(qse_json_getmmgr(json), size);
if (!ptr) qse_json_seterrnum (json, QSE_JSON_ENOMEM);
else QSE_MEMSET (ptr, 0, size);
return ptr;
@ -968,14 +948,14 @@ void* qse_json_callocmem (qse_json_t* json, qse_size_t size)
void* qse_json_reallocmem (qse_json_t* json, void* ptr, qse_size_t size)
{
ptr = QSE_MMGR_REALLOC(json->mmgr, ptr, size);
ptr = QSE_MMGR_REALLOC(qse_json_getmmgr(json), ptr, size);
if (!ptr) qse_json_seterrnum (json, QSE_JSON_ENOMEM);
return ptr;
}
void qse_json_freemem (qse_json_t* json, void* ptr)
{
QSE_MMGR_FREE (json->mmgr, ptr);
QSE_MMGR_FREE (qse_json_getmmgr(json), ptr);
}
/* ========================================================================= */

View File

@ -366,7 +366,7 @@ static int read_list (qse_xli_t* xli)
QSE_ASSERT (key.ptr == QSE_NULL);
key.len = QSE_STR_LEN(xli->tok.name);
key.ptr = qse_strdup (QSE_STR_PTR(xli->tok.name), xli->mmgr);
key.ptr = qse_strdup(QSE_STR_PTR(xli->tok.name), qse_xli_getmmgr(xli));
if (key.ptr == QSE_NULL)
{
qse_xli_seterrnum (xli, QSE_XLI_ENOMEM, QSE_NULL);
@ -398,7 +398,7 @@ static int read_list (qse_xli_t* xli)
pair = qse_xli_insertpairwithstr (xli, curlist, QSE_NULL, key.ptr, QSE_NULL, QSE_NULL, &empty, QSE_NULL);
QSE_MMGR_FREE (xli->mmgr, key.ptr);
qse_xli_freemem (xli, key.ptr);
key.ptr = QSE_NULL;
if (pair == QSE_NULL) goto oops;
@ -410,7 +410,7 @@ static int read_list (qse_xli_t* xli)
/* add a new pair with the initial string segment */
pair = qse_xli_insertpairwithstr (xli, curlist, QSE_NULL, key.ptr, QSE_NULL, QSE_NULL, QSE_STR_XSTR(xli->tok.name), QSE_NULL);
QSE_MMGR_FREE (xli->mmgr, key.ptr);
qse_xli_freemem (xli, key.ptr);
key.ptr = QSE_NULL;
if (pair == QSE_NULL) goto oops;
@ -432,7 +432,7 @@ static int read_list (qse_xli_t* xli)
return 0;
oops:
if (key.ptr) QSE_MMGR_FREE (xli->mmgr, key.ptr);
if (key.ptr) qse_xli_freemem (xli, key.ptr);
return -1;
}
@ -505,7 +505,7 @@ oops:
prev = xli->rio.inp->prev;
QSE_ASSERT (xli->rio.inp->name != QSE_NULL);
QSE_MMGR_FREE (xli->mmgr, xli->rio.inp);
qse_xli_freemem (xli, xli->rio.inp);
xli->rio.inp = prev;
}

View File

@ -258,7 +258,7 @@ static int end_include (qse_xli_t* xli, int noeof)
xli->rio.inp = xli->rio.inp->prev;
QSE_ASSERT (cur->name != QSE_NULL);
QSE_MMGR_FREE (xli->mmgr, cur);
qse_xli_freemem (xli, cur);
/* xli->parse.depth.incl--; */
if ((xli->opt.trait & QSE_XLI_KEEPFILE) && !noeof &&
@ -329,7 +329,7 @@ oops:
/* i don't need to free 'link' since it's linked to
* xli->rio_names that's freed at the beginning of qse_xli_read()
* or by qse_xli_fini() */
if (arg) QSE_MMGR_FREE (xli->mmgr, arg);
if (arg) qse_xli_freemem (xli, arg);
return -1;
}
@ -675,7 +675,7 @@ static int read_pair (qse_xli_t* xli, rpair_t* pair)
if (check_token_for_key_eligibility(xli, xli->parlink->list) <= -1) goto oops;
key = qse_strdup(QSE_STR_PTR(xli->tok.name), xli->mmgr);
key = qse_strdup(QSE_STR_PTR(xli->tok.name), qse_xli_getmmgr(xli));
if (key == QSE_NULL)
{
qse_xli_seterrnum (xli, QSE_XLI_ENOMEM, QSE_NULL);
@ -702,7 +702,7 @@ static int read_pair (qse_xli_t* xli, rpair_t* pair)
oops:
if (val) qse_xli_freeval (xli, val);
if (key) QSE_MMGR_FREE (xli->mmgr, key);
if (key) qse_xli_freemem (xli, key);
return -1;
}
@ -797,7 +797,7 @@ static int __read_list (qse_xli_t* xli)
p = qse_xli_insertpair(xli, xli->parlink->list, QSE_NULL, rpair.key, QSE_NULL, QSE_NULL, rpair.val);
if (!p)
{
QSE_MMGR_FREE (xli->mmgr, rpair.key);
qse_xli_freemem (xli, rpair.key);
qse_xli_freeval (xli, rpair.val);
return -1;
}
@ -805,7 +805,7 @@ static int __read_list (qse_xli_t* xli)
if (xli->opt.cbs.pair_read) xli->opt.cbs.pair_read (xli, p, &ploc);
/* clear the duplicated key. the key is also duplicated in qse_xli_insertpair(). don't need it */
QSE_MMGR_FREE (xli->mmgr, rpair.key);
qse_xli_freemem (xli, rpair.key);
if (get_token(xli) <= -1) return -1;
@ -1003,7 +1003,7 @@ oops:
prev = xli->rio.inp->prev;
QSE_ASSERT (xli->rio.inp->name != QSE_NULL);
QSE_MMGR_FREE (xli->mmgr, xli->rio.inp);
qse_xli_freemem (xli, xli->rio.inp);
xli->rio.inp = prev;
}

View File

@ -384,7 +384,7 @@ static int end_include (qse_xli_t* xli, int noeof)
xli->rio.inp = xli->rio.inp->prev;
QSE_ASSERT (cur->name != QSE_NULL);
QSE_MMGR_FREE (xli->mmgr, cur);
qse_xli_freemem (xli, cur);
/* xli->parse.depth.incl--; */
if ((xli->opt.trait & QSE_XLI_KEEPFILE) && !noeof &&
@ -407,7 +407,7 @@ static int begin_include (qse_xli_t* xli)
qse_link_t* link;
qse_xli_io_arg_t* arg = QSE_NULL;
link = (qse_link_t*) qse_xli_callocmem (xli,
link = (qse_link_t*)qse_xli_callocmem(xli,
QSE_SIZEOF(*link) + QSE_SIZEOF(qse_char_t) * (QSE_STR_LEN(xli->tok.name) + 1));
if (link == QSE_NULL) goto oops;
@ -415,7 +415,7 @@ static int begin_include (qse_xli_t* xli)
link->link = xli->rio_names;
xli->rio_names = link;
arg = (qse_xli_io_arg_t*) qse_xli_callocmem (xli, QSE_SIZEOF(*arg));
arg = (qse_xli_io_arg_t*)qse_xli_callocmem(xli, QSE_SIZEOF(*arg));
if (arg == QSE_NULL) goto oops;
arg->name = (const qse_char_t*)(link + 1);
@ -455,7 +455,7 @@ oops:
/* i don't need to free 'link' since it's linked to
* xli->rio_names that's freed at the beginning of qse_xli_read()
* or by qse_xli_fini() */
if (arg) QSE_MMGR_FREE (xli->mmgr, arg);
if (arg) qse_xli_freemem (xli, arg);
return -1;
}
@ -764,7 +764,7 @@ static int read_pair (qse_xli_t* xli, const qse_char_t* keytag, const qse_xli_sc
kloc = xli->tok.loc;
key.len = QSE_STR_LEN(xli->tok.name);
key.ptr = qse_strdup (QSE_STR_PTR(xli->tok.name), xli->mmgr);
key.ptr = qse_strdup (QSE_STR_PTR(xli->tok.name), qse_xli_getmmgr(xli));
if (key.ptr == QSE_NULL)
{
qse_xli_seterrnum (xli, QSE_XLI_ENOMEM, QSE_NULL);
@ -847,7 +847,7 @@ static int read_pair (qse_xli_t* xli, const qse_char_t* keytag, const qse_xli_sc
atom = atom->prev;
}
name = qse_strdup (QSE_STR_PTR(xli->tok.name), xli->mmgr);
name = qse_strdup (QSE_STR_PTR(xli->tok.name), qse_xli_getmmgr(xli));
if (name == QSE_NULL)
{
qse_xli_seterrnum (xli, QSE_XLI_ENOMEM, QSE_NULL);
@ -871,7 +871,7 @@ static int read_pair (qse_xli_t* xli, const qse_char_t* keytag, const qse_xli_sc
if ((xli->opt.trait & QSE_XLI_STRTAG) && MATCH(xli, QSE_XLI_TOK_TAG))
{
strtag = qse_strxdup (QSE_STR_PTR(xli->tok.name), QSE_STR_LEN(xli->tok.name), xli->mmgr);
strtag = qse_strxdup (QSE_STR_PTR(xli->tok.name), QSE_STR_LEN(xli->tok.name), qse_xli_getmmgr(xli));
if (strtag == QSE_NULL)
{
qse_xli_seterrnum (xli, QSE_XLI_ENOMEM, QSE_NULL);
@ -938,13 +938,13 @@ static int read_pair (qse_xli_t* xli, const qse_char_t* keytag, const qse_xli_sc
if (strtag)
{
QSE_MMGR_FREE (xli->mmgr, strtag);
qse_xli_freemem (xli, strtag);
strtag = QSE_NULL;
}
if ((xli->opt.trait & QSE_XLI_STRTAG) && MATCH(xli, QSE_XLI_TOK_TAG))
{
strtag = qse_strxdup (QSE_STR_PTR(xli->tok.name), QSE_STR_LEN(xli->tok.name), xli->mmgr);
strtag = qse_strxdup (QSE_STR_PTR(xli->tok.name), QSE_STR_LEN(xli->tok.name), qse_xli_getmmgr(xli));
if (strtag == QSE_NULL)
{
qse_xli_seterrnum (xli, QSE_XLI_ENOMEM, QSE_NULL);
@ -1070,17 +1070,17 @@ static int read_pair (qse_xli_t* xli, const qse_char_t* keytag, const qse_xli_sc
goto oops;
}
if (strtag) QSE_MMGR_FREE (xli->mmgr, strtag);
QSE_MMGR_FREE (xli->mmgr, name);
QSE_MMGR_FREE (xli->mmgr, key.ptr);
if (strtag) qse_xli_freemem (xli, strtag);
qse_xli_freemem (xli, name);
qse_xli_freemem (xli, key.ptr);
qse_str_setlen (xli->dotted_curkey, dotted_curkey_len);
return 0;
oops:
xli->tok_status &= ~TOK_STATUS_ENABLE_NSTR;
if (strtag) QSE_MMGR_FREE (xli->mmgr, strtag);
if (name) QSE_MMGR_FREE (xli->mmgr, name);
if (key.ptr) QSE_MMGR_FREE (xli->mmgr, key.ptr);
if (strtag) qse_xli_freemem (xli, strtag);
if (name) qse_xli_freemem (xli, name);
if (key.ptr) qse_xli_freemem (xli, key.ptr);
if (dotted_curkey_len != (qse_size_t)-1)
qse_str_setlen (xli->dotted_curkey, dotted_curkey_len);
return -1;
@ -1090,7 +1090,7 @@ qse_xli_list_link_t* qse_xli_makelistlink (qse_xli_t* xli, qse_xli_list_t* parli
{
qse_xli_list_link_t* link;
link = (qse_xli_list_link_t*) qse_xli_callocmem (xli, QSE_SIZEOF(*link));
link = (qse_xli_list_link_t*)qse_xli_callocmem(xli, QSE_SIZEOF(*link));
if (link == QSE_NULL) return QSE_NULL;
link->list = parlist;
@ -1128,7 +1128,7 @@ static int __read_list (qse_xli_t* xli, const qse_xli_scm_t* override)
qse_char_t* keytag;
int x;
keytag = qse_strxdup (QSE_STR_PTR(xli->tok.name), QSE_STR_LEN(xli->tok.name), xli->mmgr);
keytag = qse_strxdup (QSE_STR_PTR(xli->tok.name), QSE_STR_LEN(xli->tok.name), qse_xli_getmmgr(xli));
if (keytag == QSE_NULL)
{
qse_xli_seterrnum (xli, QSE_XLI_ENOMEM, QSE_NULL);
@ -1137,19 +1137,19 @@ static int __read_list (qse_xli_t* xli, const qse_xli_scm_t* override)
if (get_token(xli) <= -1)
{
QSE_MMGR_FREE (xli->mmgr, keytag);
qse_xli_freemem (xli, keytag);
return -1;
}
if (!MATCH(xli, QSE_XLI_TOK_IDENT) && !MATCH(xli, QSE_XLI_TOK_DQSTR) && !MATCH(xli, QSE_XLI_TOK_SQSTR))
{
QSE_MMGR_FREE (xli->mmgr, keytag);
qse_xli_freemem (xli, keytag);
qse_xli_seterror (xli, QSE_XLI_ENOKEY, QSE_NULL, &xli->tok.loc);
return -1;
}
x = read_pair(xli, keytag, override);
QSE_MMGR_FREE (xli->mmgr, keytag);
qse_xli_freemem (xli, keytag);
if (x <= -1) return -1;
}
else if (MATCH(xli, QSE_XLI_TOK_IDENT) || MATCH(xli, QSE_XLI_TOK_DQSTR) || MATCH(xli, QSE_XLI_TOK_SQSTR))
@ -1221,7 +1221,7 @@ void qse_xli_clearrionames (qse_xli_t* xli)
{
cur = xli->rio_names;
xli->rio_names = cur->link;
QSE_MMGR_FREE (xli->mmgr, cur);
qse_xli_freemem (xli, cur);
}
}
@ -1277,7 +1277,7 @@ oops:
prev = xli->rio.inp->prev;
QSE_ASSERT (xli->rio.inp->name != QSE_NULL);
QSE_MMGR_FREE (xli->mmgr, xli->rio.inp);
qse_xli_freemem (xli, xli->rio.inp);
xli->rio.inp = prev;
}

View File

@ -71,6 +71,12 @@ typedef struct xtn_t
qse_xli_ecb_t ecb;
} xtn_t;
#if defined(QSE_HAVE_INLINE)
static QSE_INLINE xtn_t* GET_XTN(qse_xli_t* xli) { return (xtn_t*)((qse_uint8_t*)qse_xli_getxtn(xli) - QSE_SIZEOF(xtn_t)); }
#else
#define GET_XTN(xli) ((xtn_t*)((qse_uint8_t*)qse_xli_getxtn(xli) - QSE_SIZEOF(xtn_t)))
#endif
qse_xli_t* qse_xli_openstd (qse_size_t xtnsize, qse_size_t rootxtnsize, qse_xli_errnum_t* errnum)
{
return qse_xli_openstdwithmmgr (QSE_MMGR_GETDFL(), xtnsize, rootxtnsize, errnum);
@ -92,11 +98,13 @@ qse_xli_t* qse_xli_openstdwithmmgr (qse_mmgr_t* mmgr, qse_size_t xtnsize, qse_si
xtn_t* xtn;
/* create an object */
xli = qse_xli_open (mmgr, QSE_SIZEOF(xtn_t) + xtnsize, rootxtnsize, errnum);
xli = qse_xli_open(mmgr, QSE_SIZEOF(xtn_t) + xtnsize, rootxtnsize, errnum);
if (xli == QSE_NULL) goto oops;
xli->_instsize += QSE_SIZEOF(xtn_t);
/* initialize extension */
xtn = (xtn_t*) QSE_XTN (xli);
xtn = GET_XTN(xli);
/* the extension area has been cleared in qse_httpd_open().
* QSE_MEMSET (xtn, 0, QSE_SIZEOF(*xtn));*/
@ -111,15 +119,10 @@ oops:
return QSE_NULL;
}
void* qse_xli_getxtnstd (qse_xli_t* xli)
{
return (void*)((xtn_t*)QSE_XTN(xli) + 1);
}
static qse_sio_t* open_sio (qse_xli_t* xli, const qse_char_t* file, int flags)
{
qse_sio_t* sio;
sio = qse_sio_open (xli->mmgr, 0, file, flags);
sio = qse_sio_open(qse_xli_getmmgr(xli), 0, file, flags);
if (sio == QSE_NULL)
{
qse_cstr_t errarg;
@ -140,7 +143,7 @@ static qse_cstr_t sio_std_names[] =
static qse_sio_t* open_sio_std (qse_xli_t* xli, qse_sio_std_t std, int flags)
{
qse_sio_t* sio;
sio = qse_sio_openstd (xli->mmgr, 0, std, flags);
sio = qse_sio_openstd (qse_xli_getmmgr(xli), 0, std, flags);
if (sio == QSE_NULL) qse_xli_seterrnum (xli, QSE_XLI_EIOFIL, &sio_std_names[std]);
return sio;
}
@ -234,10 +237,10 @@ static qse_ssize_t sf_in_open (qse_xli_t* xli, qse_xli_io_arg_t* arg, xtn_t* xtn
}
arg->handle = qse_sio_open (
xli->mmgr, 0, path, QSE_SIO_READ | QSE_SIO_IGNOREMBWCERR | QSE_SIO_KEEPPATH
qse_xli_getmmgr(xli), 0, path, QSE_SIO_READ | QSE_SIO_IGNOREMBWCERR | QSE_SIO_KEEPPATH
);
if (dbuf) QSE_MMGR_FREE (xli->mmgr, dbuf);
if (dbuf) qse_xli_freemem (xli, dbuf);
if (arg->handle == QSE_NULL)
{
qse_cstr_t ea;
@ -347,7 +350,7 @@ static qse_ssize_t sf_in (
qse_xli_t* xli, qse_xli_io_cmd_t cmd,
qse_xli_io_arg_t* arg, qse_char_t* data, qse_size_t size)
{
xtn_t* xtn = QSE_XTN (xli);
xtn_t* xtn = GET_XTN(xli);
QSE_ASSERT (arg != QSE_NULL);
@ -401,7 +404,7 @@ static qse_ssize_t sf_out_open (qse_xli_t* xli, qse_xli_io_arg_t* arg, xtn_t* xt
return 0;
case QSE_XLI_IOSTD_STR:
xtn->s.out.u.str.buf = qse_str_open (xli->mmgr, 0, 512);
xtn->s.out.u.str.buf = qse_str_open(qse_xli_getmmgr(xli), 0, 512);
if (xtn->s.out.u.str.buf == QSE_NULL)
{
qse_xli_seterrnum (xli, QSE_XLI_ENOMEM, QSE_NULL);
@ -461,10 +464,10 @@ static qse_ssize_t sf_out_open (qse_xli_t* xli, qse_xli_io_arg_t* arg, xtn_t* xt
}
arg->handle = qse_sio_open (
xli->mmgr, 0, path, QSE_SIO_WRITE | QSE_SIO_CREATE | QSE_SIO_TRUNCATE | QSE_SIO_IGNOREMBWCERR | QSE_SIO_KEEPPATH
qse_xli_getmmgr(xli), 0, path, QSE_SIO_WRITE | QSE_SIO_CREATE | QSE_SIO_TRUNCATE | QSE_SIO_IGNOREMBWCERR | QSE_SIO_KEEPPATH
);
if (dbuf) QSE_MMGR_FREE (xli->mmgr, dbuf);
if (dbuf) qse_xli_freemem (xli, dbuf);
if (arg->handle == QSE_NULL)
{
qse_cstr_t ea;
@ -578,7 +581,7 @@ static qse_ssize_t sf_out (
qse_xli_t* xli, qse_xli_io_cmd_t cmd,
qse_xli_io_arg_t* arg, qse_char_t* data, qse_size_t size)
{
xtn_t* xtn = QSE_XTN (xli);
xtn_t* xtn = GET_XTN(xli);
QSE_ASSERT (arg != QSE_NULL);
@ -601,7 +604,7 @@ static qse_ssize_t sf_out (
int qse_xli_readstd (qse_xli_t* xli, qse_xli_iostd_t* in)
{
xtn_t* xtn = (xtn_t*) QSE_XTN (xli);
xtn_t* xtn = GET_XTN(xli);
if (in == QSE_NULL || (in->type != QSE_XLI_IOSTD_FILE &&
in->type != QSE_XLI_IOSTD_STR))
@ -619,7 +622,7 @@ int qse_xli_readstd (qse_xli_t* xli, qse_xli_iostd_t* in)
int qse_xli_readinistd (qse_xli_t* xli, qse_xli_iostd_t* in)
{
xtn_t* xtn = (xtn_t*) QSE_XTN (xli);
xtn_t* xtn = GET_XTN(xli);
if (in == QSE_NULL || (in->type != QSE_XLI_IOSTD_FILE &&
in->type != QSE_XLI_IOSTD_STR))
@ -636,7 +639,7 @@ int qse_xli_readinistd (qse_xli_t* xli, qse_xli_iostd_t* in)
int qse_xli_readjsonstd (qse_xli_t* xli, qse_xli_iostd_t* in)
{
xtn_t* xtn = (xtn_t*) QSE_XTN (xli);
xtn_t* xtn = GET_XTN(xli);
if (in == QSE_NULL || (in->type != QSE_XLI_IOSTD_FILE &&
in->type != QSE_XLI_IOSTD_STR))
@ -654,7 +657,7 @@ int qse_xli_readjsonstd (qse_xli_t* xli, qse_xli_iostd_t* in)
int qse_xli_writestd (qse_xli_t* xli, qse_xli_list_t* root_list, qse_xli_iostd_t* out)
{
int n;
xtn_t* xtn = (xtn_t*) QSE_XTN (xli);
xtn_t* xtn = GET_XTN(xli);
if (out == QSE_NULL || (out->type != QSE_XLI_IOSTD_FILE &&
out->type != QSE_XLI_IOSTD_STR))
@ -684,7 +687,7 @@ int qse_xli_writestd (qse_xli_t* xli, qse_xli_list_t* root_list, qse_xli_iostd_t
int qse_xli_writeinistd (qse_xli_t* xli, qse_xli_list_t* root_list, qse_xli_iostd_t* out)
{
int n;
xtn_t* xtn = (xtn_t*) QSE_XTN (xli);
xtn_t* xtn = GET_XTN(xli);
if (out == QSE_NULL || (out->type != QSE_XLI_IOSTD_FILE &&
out->type != QSE_XLI_IOSTD_STR))
@ -714,7 +717,7 @@ int qse_xli_writeinistd (qse_xli_t* xli, qse_xli_list_t* root_list, qse_xli_iost
int qse_xli_writejsonstd (qse_xli_t* xli, qse_xli_list_t* root_list, qse_xli_iostd_t* out)
{
int n;
xtn_t* xtn = (xtn_t*) QSE_XTN (xli);
xtn_t* xtn = GET_XTN(xli);
if (out == QSE_NULL || (out->type != QSE_XLI_IOSTD_FILE &&
out->type != QSE_XLI_IOSTD_STR))

View File

@ -388,7 +388,7 @@ void qse_xli_clearwionames (qse_xli_t* xli)
{
cur = xli->wio_names;
xli->wio_names = cur->link;
QSE_MMGR_FREE (xli->mmgr, cur);
qse_xli_freemem (xli, cur);
}
}

View File

@ -90,7 +90,7 @@ struct qse_xli_root_list_t
struct qse_xli_t
{
qse_mmgr_t* mmgr;
QSE_XLI_HDR;
qse_xli_errstr_t errstr; /**< error string getter */
qse_xli_errnum_t errnum; /**< stores an error number */

View File

@ -60,13 +60,14 @@ void qse_xli_close (qse_xli_t* xli)
if (ecb->close) ecb->close (xli);
qse_xli_fini (xli);
QSE_MMGR_FREE (xli->mmgr, xli);
QSE_MMGR_FREE (xli->_mmgr, xli);
}
int qse_xli_init (qse_xli_t* xli, qse_mmgr_t* mmgr, qse_size_t rootxtnsize)
{
QSE_MEMSET (xli, 0, QSE_SIZEOF(*xli));
xli->mmgr = mmgr;
xli->_instsize = QSE_SIZEOF(*xli);
xli->_mmgr = mmgr;
xli->errstr = qse_xli_dflerrstr;
xli->opt.root_xtnsize = rootxtnsize;
xli->opt.key_splitter = QSE_T('.');
@ -100,23 +101,13 @@ oops:
void qse_xli_fini (qse_xli_t* xli)
{
qse_xli_clear (xli);
QSE_MMGR_FREE (xli->mmgr, xli->root);
QSE_MMGR_FREE (qse_xli_getmmgr(xli), xli->root);
qse_rbt_close (xli->schema);
qse_str_close (xli->tok.name);
qse_str_close (xli->dotted_curkey);
}
qse_mmgr_t* qse_xli_getmmgr (qse_xli_t* xli)
{
return xli->mmgr;
}
void* qse_xli_getxtn (qse_xli_t* xli)
{
return QSE_XTN (xli);
}
int qse_xli_setopt (qse_xli_t* xli, qse_xli_opt_t id, const void* value)
{
switch (id)
@ -204,7 +195,7 @@ void* qse_xli_allocmem (qse_xli_t* xli, qse_size_t size)
{
void* ptr;
ptr = QSE_MMGR_ALLOC (xli->mmgr, size);
ptr = QSE_MMGR_ALLOC (qse_xli_getmmgr(xli), size);
if (!ptr) qse_xli_seterrnum (xli, QSE_XLI_ENOMEM, QSE_NULL);
return ptr;
}
@ -213,7 +204,7 @@ void* qse_xli_callocmem (qse_xli_t* xli, qse_size_t size)
{
void* ptr;
ptr = QSE_MMGR_ALLOC (xli->mmgr, size);
ptr = QSE_MMGR_ALLOC (qse_xli_getmmgr(xli), size);
if (!ptr) qse_xli_seterrnum (xli, QSE_XLI_ENOMEM, QSE_NULL);
else QSE_MEMSET (ptr, 0, size);
return ptr;
@ -221,7 +212,7 @@ void* qse_xli_callocmem (qse_xli_t* xli, qse_size_t size)
void qse_xli_freemem (qse_xli_t* xli, void* ptr)
{
QSE_MMGR_FREE (xli->mmgr, ptr);
QSE_MMGR_FREE (qse_xli_getmmgr(xli), ptr);
}
/* ------------------------------------------------------ */
@ -355,7 +346,7 @@ void qse_xli_deletepair (qse_xli_t* xli, qse_xli_pair_t* pair)
}
free_val (xli->root, pair->val);
QSE_MMGR_FREE (xli->mmgr, pair);
QSE_MMGR_FREE (qse_xli_getmmgr(xli), pair);
}
/* ------------------------------------------------------ */
@ -603,7 +594,7 @@ static qse_xli_root_list_t* make_root (qse_xli_t* xli)
{
qse_xli_root_list_t* tmp;
tmp = QSE_MMGR_ALLOC (xli->mmgr, QSE_SIZEOF(*tmp) + xli->opt.root_xtnsize);
tmp = QSE_MMGR_ALLOC (qse_xli_getmmgr(xli), QSE_SIZEOF(*tmp) + xli->opt.root_xtnsize);
if (!tmp)
{
qse_xli_seterrnum (xli, QSE_XLI_ENOMEM, QSE_NULL);
@ -615,7 +606,7 @@ static qse_xli_root_list_t* make_root (qse_xli_t* xli)
tmp->xnil.type = QSE_XLI_NIL;
tmp->xtrue.type = QSE_XLI_TRUE;
tmp->xfalse.type = QSE_XLI_FALSE;
tmp->mmgr = xli->mmgr;
tmp->mmgr = qse_xli_getmmgr(xli);
return tmp;
}