From 26440f1a96d181155d0bae1f02435b1df8bf0868 Mon Sep 17 00:00:00 2001 From: hyung-hwan Date: Fri, 12 Jun 2015 13:11:50 +0000 Subject: [PATCH] removed unnecessary code in some initialization code. added errnum to some open functions --- qse/cmd/http/httpd.c | 4 ++-- qse/cmd/sed/sed.c | 4 ++-- qse/cmd/xli/xli.c | 2 +- qse/include/qse/http/httpd.h | 5 +++-- qse/include/qse/http/stdhttpd.h | 8 +++++--- qse/include/qse/sed/sed.h | 5 +++-- qse/include/qse/sed/stdsed.h | 8 +++++--- qse/include/qse/xli/stdxli.h | 13 ++++++++----- qse/include/qse/xli/xli.h | 8 ++++---- qse/lib/awk/Awk.cpp | 2 +- qse/lib/awk/mod-sed.c | 4 ++-- qse/lib/awk/std.c | 3 ++- qse/lib/http/httpd-std.c | 11 ++++++----- qse/lib/http/httpd.c | 4 +++- qse/lib/sed/Sed.cpp | 13 +++++++++---- qse/lib/sed/sed.c | 4 +++- qse/lib/sed/std.c | 18 ++++-------------- qse/lib/xli/std.c | 11 ++++++----- qse/lib/xli/xli.c | 4 +++- qse/samples/sed/sed01.c | 2 +- qse/samples/sed/sed02.c | 2 +- qse/samples/sed/sed03.c | 2 +- 22 files changed, 75 insertions(+), 62 deletions(-) diff --git a/qse/cmd/http/httpd.c b/qse/cmd/http/httpd.c index 1a150ff7..c9ad2e3f 100644 --- a/qse/cmd/http/httpd.c +++ b/qse/cmd/http/httpd.c @@ -2282,7 +2282,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, 0); + httpd_xtn->xli = qse_xli_openstd (0, 0, QSE_NULL); if (httpd_xtn->xli == QSE_NULL) { qse_fprintf (QSE_STDERR, QSE_T("Cannot open xli\n")); @@ -2710,7 +2710,7 @@ static int httpd_main (int argc, qse_char_t* argv[]) if (ret <= -1) return -1; if (ret == 0) return 0; - httpd = qse_httpd_openstd (QSE_SIZEOF(httpd_xtn_t)); + httpd = qse_httpd_openstd (QSE_SIZEOF(httpd_xtn_t), QSE_NULL); if (httpd == QSE_NULL) { qse_fprintf (QSE_STDERR, QSE_T("ERROR: Cannot open httpd\n")); diff --git a/qse/cmd/sed/sed.c b/qse/cmd/sed/sed.c index 03d4de02..d2bd24c3 100644 --- a/qse/cmd/sed/sed.c +++ b/qse/cmd/sed/sed.c @@ -754,8 +754,8 @@ static int sed_main (int argc, qse_char_t* argv[]) } } - sed = qse_sed_openstdwithmmgr (mmgr, 0); - if (sed == QSE_NULL) + sed = qse_sed_openstdwithmmgr (mmgr, 0, QSE_NULL); + if (!sed) { qse_fprintf (QSE_STDERR, QSE_T("ERROR: cannot open stream editor\n")); goto oops; diff --git a/qse/cmd/xli/xli.c b/qse/cmd/xli/xli.c index 99b41c55..3a2e053c 100644 --- a/qse/cmd/xli/xli.c +++ b/qse/cmd/xli/xli.c @@ -395,7 +395,7 @@ static int xli_main (int argc, qse_char_t* argv[]) mmgr = &xma_mmgr; } - xli = qse_xli_openstdwithmmgr (mmgr, 0, 0); + xli = qse_xli_openstdwithmmgr (mmgr, 0, 0, QSE_NULL); if (xli == QSE_NULL) { qse_fprintf (QSE_STDERR, QSE_T("ERROR: cannot open stream editor\n")); diff --git a/qse/include/qse/http/httpd.h b/qse/include/qse/http/httpd.h index 7e1354f4..1d75f879 100644 --- a/qse/include/qse/http/httpd.h +++ b/qse/include/qse/http/httpd.h @@ -1054,8 +1054,9 @@ extern "C" { * The qse_httpd_open() function creates a httpd processor. */ QSE_EXPORT qse_httpd_t* qse_httpd_open ( - qse_mmgr_t* mmgr, /**< memory manager */ - qse_size_t xtnsize /**< extension size in bytes */ + qse_mmgr_t* mmgr, /**< memory manager */ + qse_size_t xtnsize, /**< extension size in bytes */ + qse_httpd_errnum_t* errnum ); /** diff --git a/qse/include/qse/http/stdhttpd.h b/qse/include/qse/http/stdhttpd.h index 569a7b6a..3a137a38 100644 --- a/qse/include/qse/http/stdhttpd.h +++ b/qse/include/qse/http/stdhttpd.h @@ -223,12 +223,14 @@ extern "C" { #endif QSE_EXPORT qse_httpd_t* qse_httpd_openstd ( - qse_size_t xtnsize + qse_size_t xtnsize, + qse_httpd_errnum_t* errnum ); QSE_EXPORT qse_httpd_t* qse_httpd_openstdwithmmgr ( - qse_mmgr_t* mmgr, - qse_size_t xtnsize + qse_mmgr_t* mmgr, + qse_size_t xtnsize, + qse_httpd_errnum_t* errnum ); QSE_EXPORT void* qse_httpd_getxtnstd ( diff --git a/qse/include/qse/sed/sed.h b/qse/include/qse/sed/sed.h index 5bfd746d..ac187ec1 100644 --- a/qse/include/qse/sed/sed.h +++ b/qse/include/qse/sed/sed.h @@ -424,8 +424,9 @@ extern "C" { * @return pointer to a stream editor on success, QSE_NULL on failure */ QSE_EXPORT qse_sed_t* qse_sed_open ( - qse_mmgr_t* mmgr, /**< memory manager */ - qse_size_t xtnsize /**< extension size in bytes */ + qse_mmgr_t* mmgr, /**< memory manager */ + qse_size_t xtnsize, /**< extension size in bytes */ + qse_sed_errnum_t* errnum ); /** diff --git a/qse/include/qse/sed/stdsed.h b/qse/include/qse/sed/stdsed.h index 12f98a3c..afd82ecc 100644 --- a/qse/include/qse/sed/stdsed.h +++ b/qse/include/qse/sed/stdsed.h @@ -108,7 +108,8 @@ extern "C" { * \return pointer to a stream editor on success, #QSE_NULL on failure. */ QSE_EXPORT qse_sed_t* qse_sed_openstd ( - qse_size_t xtnsize /**< extension size in bytes */ + qse_size_t xtnsize, /**< extension size in bytes */ + qse_sed_errnum_t* errnum ); /** @@ -119,8 +120,9 @@ QSE_EXPORT qse_sed_t* qse_sed_openstd ( * \return pointer to a stream editor on success, #QSE_NULL on failure. */ QSE_EXPORT qse_sed_t* qse_sed_openstdwithmmgr ( - qse_mmgr_t* mmgr, /**< memory manager */ - qse_size_t xtnsize /**< extension size in bytes */ + qse_mmgr_t* mmgr, /**< memory manager */ + qse_size_t xtnsize, /**< extension size in bytes */ + qse_sed_errnum_t* errnum ); /** diff --git a/qse/include/qse/xli/stdxli.h b/qse/include/qse/xli/stdxli.h index 88475008..b7bf8808 100644 --- a/qse/include/qse/xli/stdxli.h +++ b/qse/include/qse/xli/stdxli.h @@ -97,8 +97,10 @@ 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 rootxtnsize /**< extension size in bytes for the root list node */ + qse_size_t xtnsize, /**< extension size in bytes */ + qse_size_t rootxtnsize, /**< extension size in bytes for the root list node */ + qse_xli_errnum_t* errnum + ); /** @@ -107,9 +109,10 @@ QSE_EXPORT qse_xli_t* qse_xli_openstd ( * except that you can specify your own memory manager. */ 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 rootxtnsize /**< extension size in bytes for the root list node */ + qse_mmgr_t* mmgr, /**< memory manager */ + qse_size_t xtnsize, /**< extension size in bytes */ + qse_size_t rootxtnsize, /**< extension size in bytes for the root list node */ + qse_xli_errnum_t* errnum ); /** diff --git a/qse/include/qse/xli/xli.h b/qse/include/qse/xli/xli.h index 57fd15d0..febce0f1 100644 --- a/qse/include/qse/xli/xli.h +++ b/qse/include/qse/xli/xli.h @@ -392,16 +392,16 @@ extern "C" { #endif QSE_EXPORT qse_xli_t* qse_xli_open ( - qse_mmgr_t* mmgr, - qse_size_t xtnsize, - qse_size_t rootxtnsize + qse_mmgr_t* mmgr, + qse_size_t xtnsize, + qse_size_t rootxtnsize, + qse_xli_errnum_t* errnum ); QSE_EXPORT void qse_xli_close ( qse_xli_t* xli ); - QSE_EXPORT qse_mmgr_t* qse_xli_getmmgr ( qse_xli_t* xli ); diff --git a/qse/lib/awk/Awk.cpp b/qse/lib/awk/Awk.cpp index 0af03af6..55145275 100644 --- a/qse/lib/awk/Awk.cpp +++ b/qse/lib/awk/Awk.cpp @@ -1146,7 +1146,7 @@ int Awk::open () qse_awk_errnum_t errnum; this->awk = qse_awk_open (this->getMmgr(), QSE_SIZEOF(xtn_t), &prm, &errnum); - if (this->awk == QSE_NULL) + if (!this->awk) { this->setError (errnum); return -1; diff --git a/qse/lib/awk/mod-sed.c b/qse/lib/awk/mod-sed.c index 94da32c8..532bd128 100644 --- a/qse/lib/awk/mod-sed.c +++ b/qse/lib/awk/mod-sed.c @@ -94,7 +94,7 @@ static int fnc_file_to_file (qse_awk_rtx_t* rtx, const qse_awk_fnc_info_t* fi) /* result = sed::file_to_file ("s/ABC/123/g", input_file, output_file [, option_string]) */ - sed = qse_sed_openstdwithmmgr (qse_awk_rtx_getmmgr(rtx), 0); + sed = qse_sed_openstdwithmmgr (qse_awk_rtx_getmmgr(rtx), 0, QSE_NULL); if (sed == QSE_NULL) { ret = -2; @@ -150,7 +150,7 @@ static int fnc_str_to_str (qse_awk_rtx_t* rtx, const qse_awk_fnc_info_t* fi) qse_cstr_t outstr; int i = 0, ret = 0, n; - sed = qse_sed_openstdwithmmgr (qse_awk_rtx_getmmgr(rtx), 0); + sed = qse_sed_openstdwithmmgr (qse_awk_rtx_getmmgr(rtx), 0, QSE_NULL); if (sed == QSE_NULL) { ret = -2; diff --git a/qse/lib/awk/std.c b/qse/lib/awk/std.c index d066551b..078459d0 100644 --- a/qse/lib/awk/std.c +++ b/qse/lib/awk/std.c @@ -454,7 +454,8 @@ qse_awk_t* qse_awk_openstdwithmmgr (qse_mmgr_t* mmgr, qse_size_t xtnsize, qse_aw /* initialize extension */ xtn = (xtn_t*) QSE_XTN (awk); - QSE_MEMSET (xtn, 0, QSE_SIZEOF(*xtn)); + /* the extension area has been cleared in qse_awk_open(). + * QSE_MEMSET (xtn, 0, QSE_SIZEOF(*xtn));*/ /* add intrinsic global variables and functions */ if (add_globals(awk) <= -1 || diff --git a/qse/lib/http/httpd-std.c b/qse/lib/http/httpd-std.c index 9cfea5bd..988a0581 100644 --- a/qse/lib/http/httpd-std.c +++ b/qse/lib/http/httpd-std.c @@ -739,12 +739,12 @@ static void cleanup_standard_httpd (qse_httpd_t* httpd) #endif } -qse_httpd_t* qse_httpd_openstd (qse_size_t xtnsize) +qse_httpd_t* qse_httpd_openstd (qse_size_t xtnsize, qse_httpd_errnum_t* errnum) { - return qse_httpd_openstdwithmmgr (QSE_MMGR_GETDFL(), xtnsize); + return qse_httpd_openstdwithmmgr (QSE_MMGR_GETDFL(), xtnsize, errnum); } -qse_httpd_t* qse_httpd_openstdwithmmgr (qse_mmgr_t* mmgr, qse_size_t xtnsize) +qse_httpd_t* qse_httpd_openstdwithmmgr (qse_mmgr_t* mmgr, qse_size_t xtnsize, qse_httpd_errnum_t* errnum) { qse_httpd_t* httpd = QSE_NULL; httpd_xtn_t* xtn = QSE_NULL; @@ -752,11 +752,12 @@ qse_httpd_t* qse_httpd_openstdwithmmgr (qse_mmgr_t* mmgr, qse_size_t xtnsize) int lt_dlinited = 0; #endif - httpd = qse_httpd_open (mmgr, QSE_SIZEOF(httpd_xtn_t) + xtnsize); + httpd = qse_httpd_open (mmgr, QSE_SIZEOF(httpd_xtn_t) + xtnsize, errnum); if (httpd == QSE_NULL) goto oops; xtn = (httpd_xtn_t*)qse_httpd_getxtn (httpd); - QSE_MEMSET (xtn, 0, QSE_SIZEOF(*xtn)); + /* the extension area has been cleared in qse_httpd_open(). + * QSE_MEMSET (xtn, 0, QSE_SIZEOF(*xtn));*/ #if defined(USE_LTDL) /* lt_dlinit() can be called more than once and diff --git a/qse/lib/http/httpd.c b/qse/lib/http/httpd.c index 3e581f6e..84f06ff7 100644 --- a/qse/lib/http/httpd.c +++ b/qse/lib/http/httpd.c @@ -69,7 +69,7 @@ static void unload_all_modules (qse_httpd_t* httpd); qse_http_version_t qse_http_v11 = { 1, 1 }; -qse_httpd_t* qse_httpd_open (qse_mmgr_t* mmgr, qse_size_t xtnsize) +qse_httpd_t* qse_httpd_open (qse_mmgr_t* mmgr, qse_size_t xtnsize, qse_httpd_errnum_t* errnum) { qse_httpd_t* httpd; @@ -78,11 +78,13 @@ qse_httpd_t* qse_httpd_open (qse_mmgr_t* mmgr, qse_size_t xtnsize) { if (qse_httpd_init (httpd, mmgr) <= -1) { + if (errnum) *errnum = qse_httpd_geterrnum(httpd); QSE_MMGR_FREE (mmgr, httpd); return QSE_NULL; } else QSE_MEMSET (QSE_XTN(httpd), 0, xtnsize); } + else if (errnum) *errnum = QSE_HTTPD_ENOMEM; return httpd; } diff --git a/qse/lib/sed/Sed.cpp b/qse/lib/sed/Sed.cpp index d068debc..7114f15d 100644 --- a/qse/lib/sed/Sed.cpp +++ b/qse/lib/sed/Sed.cpp @@ -35,11 +35,16 @@ QSE_BEGIN_NAMESPACE(QSE) int Sed::open () { - sed = qse_sed_open (this->getMmgr(), QSE_SIZEOF(Sed*)); - if (!sed) return -1; - *(Sed**)QSE_XTN(sed) = this; + qse_sed_errnum_t errnum; + this->sed = qse_sed_open (this->getMmgr(), QSE_SIZEOF(Sed*), &errnum); + if (!this->sed) + { + this->setError (errnum); + return -1; + } + *(Sed**)QSE_XTN(this->sed) = this; - dflerrstr = qse_sed_geterrstr (sed); + dflerrstr = qse_sed_geterrstr (this->sed); qse_sed_seterrstr (sed, xerrstr); return 0; diff --git a/qse/lib/sed/sed.c b/qse/lib/sed/sed.c index d81fce37..44019211 100644 --- a/qse/lib/sed/sed.c +++ b/qse/lib/sed/sed.c @@ -63,7 +63,7 @@ do { \ static void free_all_cut_selector_blocks (qse_sed_t* sed, qse_sed_cmd_t* cmd); -qse_sed_t* qse_sed_open (qse_mmgr_t* mmgr, qse_size_t xtnsize) +qse_sed_t* qse_sed_open (qse_mmgr_t* mmgr, qse_size_t xtnsize, qse_sed_errnum_t* errnum) { qse_sed_t* sed; @@ -72,11 +72,13 @@ qse_sed_t* qse_sed_open (qse_mmgr_t* mmgr, qse_size_t xtnsize) { if (qse_sed_init (sed, mmgr) <= -1) { + if (errnum) *errnum = qse_sed_geterrnum(sed); QSE_MMGR_FREE (mmgr, sed); return QSE_NULL; } else QSE_MEMSET (QSE_XTN(sed), 0, xtnsize); } + else if (errnum) *errnum = QSE_SED_ENOMEM; return sed; } diff --git a/qse/lib/sed/std.c b/qse/lib/sed/std.c index e7970a89..e6b9fb62 100644 --- a/qse/lib/sed/std.c +++ b/qse/lib/sed/std.c @@ -100,24 +100,14 @@ static int int_to_str (qse_size_t val, qse_char_t* buf, qse_size_t buflen) return 0; } -qse_sed_t* qse_sed_openstd (qse_size_t xtnsize) +qse_sed_t* qse_sed_openstd (qse_size_t xtnsize, qse_sed_errnum_t* errnum) { - return qse_sed_openstdwithmmgr (QSE_MMGR_GETDFL(), xtnsize); + return qse_sed_openstdwithmmgr (QSE_MMGR_GETDFL(), xtnsize, errnum); } -qse_sed_t* qse_sed_openstdwithmmgr (qse_mmgr_t* mmgr, qse_size_t xtnsize) +qse_sed_t* qse_sed_openstdwithmmgr (qse_mmgr_t* mmgr, qse_size_t xtnsize, qse_sed_errnum_t* errnum) { - qse_sed_t* sed; - xtn_t* xtn; - - sed = qse_sed_open (mmgr, QSE_SIZEOF(xtn_t) + xtnsize); - if (!sed) return QSE_NULL; - - /* initialize the my own extension area excluding xtnsize */ - xtn = (xtn_t*) QSE_XTN(sed); - QSE_MEMSET (xtn, 0, QSE_SIZEOF(*xtn)); - - return sed; + return qse_sed_open (mmgr, QSE_SIZEOF(xtn_t) + xtnsize, errnum); } void* qse_sed_getxtnstd (qse_sed_t* sed) diff --git a/qse/lib/xli/std.c b/qse/lib/xli/std.c index 1721a021..34379f6e 100644 --- a/qse/lib/xli/std.c +++ b/qse/lib/xli/std.c @@ -71,9 +71,9 @@ typedef struct xtn_t qse_xli_ecb_t ecb; } xtn_t; -qse_xli_t* qse_xli_openstd (qse_size_t xtnsize, qse_size_t rootxtnsize) +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); + return qse_xli_openstdwithmmgr (QSE_MMGR_GETDFL(), xtnsize, rootxtnsize, errnum); } static void fini_xtn (qse_xli_t* xli) @@ -86,18 +86,19 @@ 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_size_t rootxtnsize) +qse_xli_t* qse_xli_openstdwithmmgr (qse_mmgr_t* mmgr, qse_size_t xtnsize, qse_size_t rootxtnsize, qse_xli_errnum_t* errnum) { qse_xli_t* xli; xtn_t* xtn; /* create an object */ - xli = qse_xli_open (mmgr, QSE_SIZEOF(xtn_t) + xtnsize, rootxtnsize); + xli = qse_xli_open (mmgr, QSE_SIZEOF(xtn_t) + xtnsize, rootxtnsize, errnum); if (xli == QSE_NULL) goto oops; /* initialize extension */ xtn = (xtn_t*) QSE_XTN (xli); - QSE_MEMSET (xtn, 0, QSE_SIZEOF(*xtn)); + /* the extension area has been cleared in qse_httpd_open(). + * QSE_MEMSET (xtn, 0, QSE_SIZEOF(*xtn));*/ xtn->ecb.close = fini_xtn; xtn->ecb.clear = clear_xtn; diff --git a/qse/lib/xli/xli.c b/qse/lib/xli/xli.c index dc140891..4562e756 100644 --- a/qse/lib/xli/xli.c +++ b/qse/lib/xli/xli.c @@ -32,7 +32,7 @@ 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_size_t rootxtnsize) +qse_xli_t* qse_xli_open (qse_mmgr_t* mmgr, qse_size_t xtnsize, qse_size_t rootxtnsize, qse_xli_errnum_t* errnum) { qse_xli_t* xli; @@ -41,11 +41,13 @@ qse_xli_t* qse_xli_open (qse_mmgr_t* mmgr, qse_size_t xtnsize, qse_size_t rootxt { if (qse_xli_init (xli, mmgr, rootxtnsize) <= -1) { + if (errnum) *errnum = qse_xli_geterrnum(xli); QSE_MMGR_FREE (mmgr, xli); return QSE_NULL; } else QSE_MEMSET (QSE_XTN(xli), 0, xtnsize); } + else if (errnum) *errnum = QSE_XLI_ENOMEM; return xli; } diff --git a/qse/samples/sed/sed01.c b/qse/samples/sed/sed01.c index 3c8b8d56..a3fa1c0f 100644 --- a/qse/samples/sed/sed01.c +++ b/qse/samples/sed/sed01.c @@ -17,7 +17,7 @@ static int sed_main (int argc, qse_char_t* argv[]) } /* create a sed object */ - sed = qse_sed_openstd (0); + sed = qse_sed_openstd (0, QSE_NULL); if (sed == QSE_NULL) { qse_fprintf (QSE_STDERR, QSE_T("ERROR: cannot open sed\n")); diff --git a/qse/samples/sed/sed02.c b/qse/samples/sed/sed02.c index 0da6e0f1..5e71364b 100644 --- a/qse/samples/sed/sed02.c +++ b/qse/samples/sed/sed02.c @@ -17,7 +17,7 @@ static int sed_main (int argc, qse_char_t* argv[]) } /* create the sed object */ - sed = qse_sed_openstd (0); + sed = qse_sed_openstd (0, QSE_NULL); if (sed == QSE_NULL) { qse_fprintf (QSE_STDERR, QSE_T("ERROR: cannot open sed\n")); diff --git a/qse/samples/sed/sed03.c b/qse/samples/sed/sed03.c index 62b9ccd2..e6bfe40c 100644 --- a/qse/samples/sed/sed03.c +++ b/qse/samples/sed/sed03.c @@ -23,7 +23,7 @@ static int sed_main (int argc, qse_char_t* argv[]) int ret = -1; /* create the sed object */ - sed = qse_sed_openstd (0); + sed = qse_sed_openstd (0, QSE_NULL); if (sed == QSE_NULL) { qse_fprintf (QSE_STDERR, QSE_T("ERROR: cannot open sed\n"));