From 72fd080f70a4b6ba18f30ea16af66bbd7966c08a Mon Sep 17 00:00:00 2001 From: hyung-hwan Date: Fri, 20 Sep 2013 07:18:26 +0000 Subject: [PATCH] added qse_getxlirootxtn(), QSE_XLI_ROOTXTNSIZE as well as the rootxtnsize parameter to multiple initialization functions --- qse/cmd/http/httpd.c | 2 +- qse/cmd/xli/xli.c | 2 +- qse/include/qse/xli/stdxli.h | 6 ++-- qse/include/qse/xli/xli.h | 19 ++++++++++-- qse/lib/xli/std.c | 8 ++--- qse/lib/xli/xli.c | 60 ++++++++++++++++++++++++------------ qse/lib/xli/xli.h | 3 +- 7 files changed, 69 insertions(+), 31 deletions(-) diff --git a/qse/cmd/http/httpd.c b/qse/cmd/http/httpd.c index 4a9253cf..3347617d 100644 --- a/qse/cmd/http/httpd.c +++ b/qse/cmd/http/httpd.c @@ -1470,7 +1470,7 @@ static int open_config_file (qse_httpd_t* httpd) httpd_xtn = (httpd_xtn_t*) qse_httpd_getxtnstd (httpd); QSE_ASSERT (httpd_xtn->xli == QSE_NULL); - httpd_xtn->xli = qse_xli_openstd (0); + httpd_xtn->xli = qse_xli_openstd (0, 0); if (httpd_xtn->xli == QSE_NULL) { qse_fprintf (QSE_STDERR, QSE_T("Cannot open xli\n")); diff --git a/qse/cmd/xli/xli.c b/qse/cmd/xli/xli.c index d0e56780..30d0f6e1 100644 --- a/qse/cmd/xli/xli.c +++ b/qse/cmd/xli/xli.c @@ -354,7 +354,7 @@ static int xli_main (int argc, qse_char_t* argv[]) mmgr = &xma_mmgr; } - xli = qse_xli_openstdwithmmgr (mmgr, 0); + xli = qse_xli_openstdwithmmgr (mmgr, 0, 0); if (xli == QSE_NULL) { qse_fprintf (QSE_STDERR, QSE_T("ERROR: cannot open stream editor\n")); diff --git a/qse/include/qse/xli/stdxli.h b/qse/include/qse/xli/stdxli.h index 2c00d077..ea3e6f76 100644 --- a/qse/include/qse/xli/stdxli.h +++ b/qse/include/qse/xli/stdxli.h @@ -97,7 +97,8 @@ extern "C" { * over qse_xli_open() if you don't need finer-grained customization. */ QSE_EXPORT qse_xli_t* qse_xli_openstd ( - qse_size_t xtnsize /**< extension size in bytes */ + qse_size_t xtnsize, /**< extension size in bytes */ + qse_size_t rootxtnsize /**< extension size in bytes for the root list node */ ); /** @@ -107,7 +108,8 @@ QSE_EXPORT qse_xli_t* qse_xli_openstd ( */ QSE_EXPORT qse_xli_t* qse_xli_openstdwithmmgr ( qse_mmgr_t* mmgr, /**< memory manager */ - qse_size_t xtnsize /**< extension size in bytes */ + qse_size_t xtnsize, /**< extension size in bytes */ + qse_size_t rootxtnsize /**< extension size in bytes for the root list node */ ); /** diff --git a/qse/include/qse/xli/xli.h b/qse/include/qse/xli/xli.h index 7e2842bf..2e8b9108 100644 --- a/qse/include/qse/xli/xli.h +++ b/qse/include/qse/xli/xli.h @@ -68,13 +68,21 @@ typedef enum qse_xli_errnum_t qse_xli_errnum_t; */ typedef const qse_char_t* (*qse_xli_errstr_t) ( const qse_xli_t* xli, /**< stream editor */ - qse_xli_errnum_t num /**< an error number */ + qse_xli_errnum_t num /**< error number */ ); enum qse_xli_opt_t { QSE_XLI_TRAIT, - QSE_XLI_PAIRXTNSIZE + + QSE_XLI_PAIRXTNSIZE, + + /** + * the size of extension area associated with the root list node. + * you can get the pointer to the extension with qse_getxlirootxtn(). + * the new size set takes effect after the call to qse_xli_yieldroot(). + */ + QSE_XLI_ROOTXTNSIZE }; typedef enum qse_xli_opt_t qse_xli_opt_t; @@ -325,7 +333,8 @@ extern "C" { QSE_EXPORT qse_xli_t* qse_xli_open ( qse_mmgr_t* mmgr, - qse_size_t xtnsize + qse_size_t xtnsize, + qse_size_t rootxtnsize ); QSE_EXPORT void qse_xli_close ( @@ -644,6 +653,10 @@ QSE_EXPORT void* qse_getxlipairxtn ( qse_xli_pair_t* pair ); +QSE_EXPORT void* qse_getxlirootxtn ( + qse_xli_list_t* root +); + /** * The qse_freexliroot() function frees the root list acquired with qse_xli_yeildroot(). */ diff --git a/qse/lib/xli/std.c b/qse/lib/xli/std.c index 007b05e1..8430987f 100644 --- a/qse/lib/xli/std.c +++ b/qse/lib/xli/std.c @@ -65,9 +65,9 @@ typedef struct xtn_t qse_xli_ecb_t ecb; } xtn_t; -qse_xli_t* qse_xli_openstd (qse_size_t xtnsize) +qse_xli_t* qse_xli_openstd (qse_size_t xtnsize, qse_size_t rootxtnsize) { - return qse_xli_openstdwithmmgr (QSE_MMGR_GETDFL(), xtnsize); + return qse_xli_openstdwithmmgr (QSE_MMGR_GETDFL(), xtnsize, rootxtnsize); } static void fini_xtn (qse_xli_t* xli) @@ -80,13 +80,13 @@ static void clear_xtn (qse_xli_t* xli) /* nothing to do */ } -qse_xli_t* qse_xli_openstdwithmmgr (qse_mmgr_t* mmgr, qse_size_t xtnsize) +qse_xli_t* qse_xli_openstdwithmmgr (qse_mmgr_t* mmgr, qse_size_t xtnsize, qse_size_t rootxtnsize) { qse_xli_t* xli; xtn_t* xtn; /* create an object */ - xli = qse_xli_open (mmgr, QSE_SIZEOF(xtn_t) + xtnsize); + xli = qse_xli_open (mmgr, QSE_SIZEOF(xtn_t) + xtnsize, rootxtnsize); if (xli == QSE_NULL) goto oops; /* initialize extension */ diff --git a/qse/lib/xli/xli.c b/qse/lib/xli/xli.c index ae245fde..5b2f49ac 100644 --- a/qse/lib/xli/xli.c +++ b/qse/lib/xli/xli.c @@ -21,18 +21,19 @@ #include "xli.h" #include +static qse_xli_root_list_t* make_root (qse_xli_t* xli); static void free_val (qse_xli_root_list_t* xli, qse_xli_val_t* val); static void free_list (qse_xli_root_list_t* xli, qse_xli_list_t* list); static void free_atom (qse_xli_root_list_t* xli, qse_xli_atom_t* atom); -qse_xli_t* qse_xli_open (qse_mmgr_t* mmgr, qse_size_t xtnsize) +qse_xli_t* qse_xli_open (qse_mmgr_t* mmgr, qse_size_t xtnsize, qse_size_t rootxtnsize) { qse_xli_t* xli; xli = (qse_xli_t*) QSE_MMGR_ALLOC (mmgr, QSE_SIZEOF(qse_xli_t) + xtnsize); if (xli) { - if (qse_xli_init (xli, mmgr) <= -1) + if (qse_xli_init (xli, mmgr, rootxtnsize) <= -1) { QSE_MMGR_FREE (xli->mmgr, xli); return QSE_NULL; @@ -54,11 +55,12 @@ void qse_xli_close (qse_xli_t* xli) QSE_MMGR_FREE (xli->mmgr, xli); } -int qse_xli_init (qse_xli_t* xli, qse_mmgr_t* mmgr) +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->errstr = qse_xli_dflerrstr; + xli->opt.root_xtnsize = rootxtnsize; xli->dotted_curkey = qse_str_open (mmgr, 0, 128); if (xli->dotted_curkey == QSE_NULL) goto oops; @@ -70,12 +72,8 @@ int qse_xli_init (qse_xli_t* xli, qse_mmgr_t* mmgr) if (xli->schema == QSE_NULL) goto oops; qse_rbt_setstyle (xli->schema, qse_getrbtstyle(QSE_RBT_STYLE_INLINE_COPIERS)); - xli->root = QSE_MMGR_ALLOC (mmgr, QSE_SIZEOF(*xli->root)); + xli->root = make_root (xli); if (xli->root == QSE_NULL) goto oops; - QSE_MEMSET (xli->root, 0, QSE_SIZEOF(*xli->root)); - xli->root->list.type = QSE_XLI_LIST; - xli->root->xnil.type = QSE_XLI_NIL; - xli->root->mmgr = mmgr; return 0; @@ -119,6 +117,10 @@ int qse_xli_setopt (qse_xli_t* xli, qse_xli_opt_t id, const void* value) case QSE_XLI_PAIRXTNSIZE: xli->opt.pair_xtnsize = *(const qse_size_t*)value; return 0; + + case QSE_XLI_ROOTXTNSIZE: + xli->opt.root_xtnsize = *(const qse_size_t*)value; + return 0; } qse_xli_seterrnum (xli, QSE_XLI_EINVAL, QSE_NULL); @@ -136,6 +138,10 @@ int qse_xli_getopt (qse_xli_t* xli, qse_xli_opt_t id, void* value) case QSE_XLI_PAIRXTNSIZE: *(qse_size_t*)value = xli->opt.pair_xtnsize; return 0; + + case QSE_XLI_ROOTXTNSIZE: + *(qse_size_t*)value = xli->opt.root_xtnsize; + return 0; }; qse_xli_seterrnum (xli, QSE_XLI_EINVAL, QSE_NULL); @@ -402,6 +408,25 @@ qse_xli_eof_t* qse_xli_inserteof ( /* ------------------------------------------------------ */ +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); + if (tmp == QSE_NULL) + { + qse_xli_seterrnum (xli, QSE_XLI_ENOMEM, QSE_NULL); + return QSE_NULL; + } + + QSE_MEMSET (tmp, 0, QSE_SIZEOF(*tmp) + xli->opt.root_xtnsize); + tmp->list.type = QSE_XLI_LIST; + tmp->xnil.type = QSE_XLI_NIL; + tmp->mmgr = xli->mmgr; + + return tmp; +} + static void free_val (qse_xli_root_list_t* root, qse_xli_val_t* val) { if ((qse_xli_nil_t*)val != &root->xnil) @@ -475,17 +500,8 @@ qse_xli_list_t* qse_xli_yieldroot (qse_xli_t* xli) { qse_xli_root_list_t* tmp, * tmp2; - tmp = QSE_MMGR_ALLOC (xli->mmgr, QSE_SIZEOF(*tmp)); - if (tmp == QSE_NULL) - { - qse_xli_seterrnum (xli, QSE_XLI_ENOMEM, QSE_NULL); - return QSE_NULL; - } - - QSE_MEMSET (tmp, 0, QSE_SIZEOF(*tmp)); - tmp->list.type = QSE_XLI_LIST; - tmp->xnil.type = QSE_XLI_NIL; - tmp->mmgr = xli->mmgr; + tmp = make_root (xli); + if (tmp == QSE_NULL) return QSE_NULL; tmp2 = xli->root; xli->root = tmp; @@ -979,6 +995,12 @@ void* qse_getxlipairxtn (qse_xli_pair_t* pair) return (void*)(pair + 1); } +void* qse_getxlirootxtn (qse_xli_list_t* root) +{ + qse_xli_root_list_t* real_root = (qse_xli_root_list_t*)root; + return (void*)(real_root + 1); +} + void qse_freexliroot (qse_xli_list_t* root) { qse_xli_root_list_t* real_root = (qse_xli_root_list_t*)root; diff --git a/qse/lib/xli/xli.h b/qse/lib/xli/xli.h index bbedcf9e..14f01bd6 100644 --- a/qse/lib/xli/xli.h +++ b/qse/lib/xli/xli.h @@ -65,6 +65,7 @@ struct qse_xli_t { int trait; qse_size_t pair_xtnsize; + qse_size_t root_xtnsize; } opt; qse_xli_ecb_t* ecb; @@ -100,7 +101,7 @@ struct qse_xli_t extern "C" { #endif -int qse_xli_init (qse_xli_t* xli, qse_mmgr_t* mmgr); +int qse_xli_init (qse_xli_t* xli, qse_mmgr_t* mmgr, qse_size_t rootxtnsize); void qse_xli_fini (qse_xli_t* xli);