removed unnecessary code in some initialization code.

added errnum to some open functions
This commit is contained in:
hyung-hwan 2015-06-12 13:11:50 +00:00
parent 7675a86234
commit 26440f1a96
22 changed files with 75 additions and 62 deletions

View File

@ -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"));

View File

@ -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;

View File

@ -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"));

View File

@ -1055,7 +1055,8 @@ extern "C" {
*/
QSE_EXPORT qse_httpd_t* qse_httpd_open (
qse_mmgr_t* mmgr, /**< memory manager */
qse_size_t xtnsize /**< extension size in bytes */
qse_size_t xtnsize, /**< extension size in bytes */
qse_httpd_errnum_t* errnum
);
/**

View File

@ -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_size_t xtnsize,
qse_httpd_errnum_t* errnum
);
QSE_EXPORT void* qse_httpd_getxtnstd (

View File

@ -425,7 +425,8 @@ extern "C" {
*/
QSE_EXPORT qse_sed_t* qse_sed_open (
qse_mmgr_t* mmgr, /**< memory manager */
qse_size_t xtnsize /**< extension size in bytes */
qse_size_t xtnsize, /**< extension size in bytes */
qse_sed_errnum_t* errnum
);
/**

View File

@ -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
);
/**
@ -120,7 +121,8 @@ QSE_EXPORT qse_sed_t* qse_sed_openstd (
*/
QSE_EXPORT qse_sed_t* qse_sed_openstdwithmmgr (
qse_mmgr_t* mmgr, /**< memory manager */
qse_size_t xtnsize /**< extension size in bytes */
qse_size_t xtnsize, /**< extension size in bytes */
qse_sed_errnum_t* errnum
);
/**

View File

@ -98,7 +98,9 @@ extern "C" {
*/
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 rootxtnsize, /**< extension size in bytes for the root list node */
qse_xli_errnum_t* errnum
);
/**
@ -109,7 +111,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 rootxtnsize /**< extension size in bytes for the root list node */
qse_size_t rootxtnsize, /**< extension size in bytes for the root list node */
qse_xli_errnum_t* errnum
);
/**

View File

@ -394,14 +394,14 @@ extern "C" {
QSE_EXPORT qse_xli_t* qse_xli_open (
qse_mmgr_t* mmgr,
qse_size_t xtnsize,
qse_size_t rootxtnsize
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
);

View File

@ -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;

View File

@ -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;

View File

@ -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 ||

View File

@ -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

View File

@ -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;
}

View File

@ -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;

View File

@ -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;
}

View File

@ -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)

View File

@ -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;

View File

@ -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;
}

View File

@ -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"));

View File

@ -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"));

View File

@ -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"));