defined QSE_APP_LOG4 through QSE_APP_LOG9

added QSE::App::setCmgr() and QSE::App::getCmgr()
fixed a wrong memory disposal call in awk/run.c
fixed some syntax issues in the QSE_CHAR_IS_MCHAR mode
initialized best.len and cur.len to 0s in qse_ip6adtombs() and qse_ip6adtowcs()
This commit is contained in:
hyung-hwan 2019-06-12 07:07:18 +00:00
parent 12eacceec0
commit 7f57afe262
9 changed files with 74 additions and 34 deletions

View File

@ -45,6 +45,12 @@ QSE_BEGIN_NAMESPACE(QSE)
#define QSE_APP_LOG1(app, mask, fmt, a1) do { if (QSE_APP_LOG_ENABLED(app, mask)) app->logfmt(mask, fmt, a1); } while(0) #define QSE_APP_LOG1(app, mask, fmt, a1) do { if (QSE_APP_LOG_ENABLED(app, mask)) app->logfmt(mask, fmt, a1); } while(0)
#define QSE_APP_LOG2(app, mask, fmt, a1, a2) do { if (QSE_APP_LOG_ENABLED(app, mask)) app->logfmt(mask, fmt, a1, a2); } while(0) #define QSE_APP_LOG2(app, mask, fmt, a1, a2) do { if (QSE_APP_LOG_ENABLED(app, mask)) app->logfmt(mask, fmt, a1, a2); } while(0)
#define QSE_APP_LOG3(app, mask, fmt, a1, a2, a3) do { if (QSE_APP_LOG_ENABLED(app, mask)) app->logfmt(mask, fmt, a1, a2, a3); } while(0) #define QSE_APP_LOG3(app, mask, fmt, a1, a2, a3) do { if (QSE_APP_LOG_ENABLED(app, mask)) app->logfmt(mask, fmt, a1, a2, a3); } while(0)
#define QSE_APP_LOG4(app, mask, fmt, a1, a2, a3, a4) do { if (QSE_APP_LOG_ENABLED(app, mask)) app->logfmt(mask, fmt, a1, a2, a3, a4); } while(0)
#define QSE_APP_LOG5(app, mask, fmt, a1, a2, a3, a4, a5) do { if (QSE_APP_LOG_ENABLED(app, mask)) app->logfmt(mask, fmt, a1, a2, a3, a4, a5); } while(0)
#define QSE_APP_LOG6(app, mask, fmt, a1, a2, a3, a4, a5, a6) do { if (QSE_APP_LOG_ENABLED(app, mask)) app->logfmt(mask, fmt, a1, a2, a3, a4, a5, a6); } while(0)
#define QSE_APP_LOG7(app, mask, fmt, a1, a2, a3, a4, a5, a6, a7) do { if (QSE_APP_LOG_ENABLED(app, mask)) app->logfmt(mask, fmt, a1, a2, a3, a4, a5, a6, a7); } while(0)
#define QSE_APP_LOG8(app, mask, fmt, a1, a2, a3, a4, a5, a6, a7, a8) do { if (QSE_APP_LOG_ENABLED(app, mask)) app->logfmt(mask, fmt, a1, a2, a3, a4, a5, a6, a7, a8); } while(0)
#define QSE_APP_LOG9(app, mask, fmt, a1, a2, a3, a4, a5, a6, a7, a8, a9) do { if (QSE_APP_LOG_ENABLED(app, mask)) app->logfmt(mask, fmt, a1, a2, a3, a4, a5, a6, a7, a8, a9); } while(0)
class App: public Uncopyable, public Types, public Mmged class App: public Uncopyable, public Types, public Mmged
{ {
@ -61,6 +67,19 @@ public:
App (Mmgr* mmgr = QSE_NULL) QSE_CPP_NOEXCEPT; App (Mmgr* mmgr = QSE_NULL) QSE_CPP_NOEXCEPT;
virtual ~App () QSE_CPP_NOEXCEPT; virtual ~App () QSE_CPP_NOEXCEPT;
void setCmgr (qse_cmgr_t* cmgr) QSE_CPP_NOEXCEPT
{
this->_cmgr = cmgr;
}
qse_cmgr_t* getCmgr () QSE_CPP_NOEXCEPT
{
return this->_cmgr;
}
const qse_cmgr_t* getCmgr () const QSE_CPP_NOEXCEPT
{
return this->_cmgr;
}
int daemonize (bool chdir_to_root = true, int fork_count = 1, bool root_only = false) QSE_CPP_NOEXCEPT; int daemonize (bool chdir_to_root = true, int fork_count = 1, bool root_only = false) QSE_CPP_NOEXCEPT;
int chroot (const qse_mchar_t* mpath) QSE_CPP_NOEXCEPT; int chroot (const qse_mchar_t* mpath) QSE_CPP_NOEXCEPT;
@ -195,6 +214,7 @@ private:
_SigLink _sig[QSE_NSIGS]; _SigLink _sig[QSE_NSIGS];
long int _guarded_child_pid; long int _guarded_child_pid;
qse_cmgr_t* _cmgr;
struct log_t struct log_t
{ {
log_t (App* app): mask(0), last_mask(0), len(0), mtx(app->getMmgr()) log_t (App* app): mask(0), last_mask(0), len(0), mtx(app->getMmgr())

View File

@ -45,7 +45,8 @@ enum qse_json_errnum_t
QSE_JSON_ENOMEM, QSE_JSON_ENOMEM,
QSE_JSON_EINVAL, QSE_JSON_EINVAL,
QSE_JSON_EFINIS QSE_JSON_EFINIS,
QSE_JSON_EECERR
}; };
typedef enum qse_json_errnum_t qse_json_errnum_t; typedef enum qse_json_errnum_t qse_json_errnum_t;

View File

@ -1019,7 +1019,7 @@ oops_3:
oops_2: oops_2:
qse_str_fini (&rtx->inrec.line); qse_str_fini (&rtx->inrec.line);
oops_1: oops_1:
qse_awk_freemem (rtx, rtx->stack); qse_awk_rtx_freemem (rtx, rtx->stack);
oops_0: oops_0:
qse_awk_seterrnum (awk, QSE_AWK_ENOMEM, QSE_NULL); qse_awk_seterrnum (awk, QSE_AWK_ENOMEM, QSE_NULL);
return -1; return -1;

View File

@ -440,7 +440,7 @@ void* qse_awk_stdmodsym (qse_awk_t* awk, void* handle, const qse_char_t* name)
qse_mchar_t* mname; qse_mchar_t* mname;
#if defined(QSE_CHAR_IS_MCHAR) #if defined(QSE_CHAR_IS_MCHAR)
mname = name; mname = (qse_mchar_t*)name;
#else #else
mname = qse_wcstombsdupwithcmgr(name, QSE_NULL, awk->mmgr, awk->cmgr); mname = qse_wcstombsdupwithcmgr(name, QSE_NULL, awk->mmgr, awk->cmgr);
if (!mname) if (!mname)

View File

@ -282,7 +282,7 @@ qse_awk_val_t* qse_awk_rtx_makestrvalwithwxstr (qse_awk_rtx_t* rtx, const qse_wc
qse_size_t wcslen; qse_size_t wcslen;
wcslen = wxstr->len; wcslen = wxstr->len;
tmp.ptr = qse_wcsntombsdupwithcmgr(wxstr->ptr, &wcslen, &tmp.len, rtx->awk->mmgr, rtx->awk->cmgr); tmp.ptr = qse_wcsntombsdupwithcmgr(wxstr->ptr, wcslen, &tmp.len, rtx->awk->mmgr, rtx->awk->cmgr);
if (tmp.ptr == QSE_NULL) if (tmp.ptr == QSE_NULL)
{ {
qse_awk_rtx_seterrnum (rtx, QSE_AWK_ENOMEM, QSE_NULL); qse_awk_rtx_seterrnum (rtx, QSE_AWK_ENOMEM, QSE_NULL);
@ -1513,7 +1513,12 @@ qse_mchar_t* qse_awk_rtx_valtombsdup (qse_awk_rtx_t* rtx, const qse_awk_val_t* v
str0 = qse_awk_rtx_getvalstr(rtx, v, &len0); str0 = qse_awk_rtx_getvalstr(rtx, v, &len0);
if (!str0) return QSE_NULL; if (!str0) return QSE_NULL;
#if defined(QSE_CHAR_IS_MCHAR)
mbs = qse_strxdup(str0, len0, rtx->awk->mmgr);
#else
mbs = qse_wcsntombsdupwithcmgr(str0, len0, &len1, rtx->awk->mmgr, rtx->awk->cmgr); mbs = qse_wcsntombsdupwithcmgr(str0, len0, &len1, rtx->awk->mmgr, rtx->awk->cmgr);
#endif
qse_awk_rtx_freevalstr (rtx, v, str0); qse_awk_rtx_freevalstr (rtx, v, str0);
if (!mbs) if (!mbs)
{ {
@ -1554,7 +1559,7 @@ qse_wchar_t* qse_awk_rtx_valtowcsdup (qse_awk_rtx_t* rtx, const qse_awk_val_t* v
{ {
#if defined(QSE_CHAR_IS_MCHAR) #if defined(QSE_CHAR_IS_MCHAR)
qse_size_t wcslen, mbslen; qse_size_t wcslen, mbslen;
mbslen = ((qse_awk_val_str_t*)v)->val.len mbslen = ((qse_awk_val_str_t*)v)->val.len;
wcs = qse_mbsntowcsalldupwithcmgr(((qse_awk_val_str_t*)v)->val.ptr, &mbslen, &wcslen, rtx->awk->mmgr, rtx->awk->cmgr); wcs = qse_mbsntowcsalldupwithcmgr(((qse_awk_val_str_t*)v)->val.ptr, &mbslen, &wcslen, rtx->awk->mmgr, rtx->awk->cmgr);
#else #else
wcs = qse_strxdup(((qse_awk_val_str_t*)v)->val.ptr, ((qse_awk_val_str_t*)v)->val.len, rtx->awk->mmgr); wcs = qse_strxdup(((qse_awk_val_str_t*)v)->val.ptr, ((qse_awk_val_str_t*)v)->val.len, rtx->awk->mmgr);
@ -1582,7 +1587,7 @@ qse_wchar_t* qse_awk_rtx_valtowcsdup (qse_awk_rtx_t* rtx, const qse_awk_val_t* v
dup = qse_awk_rtx_valtostrdup(rtx, v, &duplen); dup = qse_awk_rtx_valtostrdup(rtx, v, &duplen);
if (!dup) return QSE_NULL; if (!dup) return QSE_NULL;
wcs = qse_mbsntowcsalldupwithcmgr(dup, duplen, &wcslen, rtx->awk->mmgr, rtx->awk->cmgr); wcs = qse_mbsntowcsalldupwithcmgr(dup, &duplen, &wcslen, rtx->awk->mmgr, rtx->awk->cmgr);
qse_awk_rtx_freemem (rtx, dup); qse_awk_rtx_freemem (rtx, dup);
if (!wcs) if (!wcs)
{ {
@ -2049,6 +2054,7 @@ int qse_awk_rtx_setrefval (qse_awk_rtx_t* rtx, qse_awk_val_ref_t* ref, qse_awk_v
} }
case QSE_AWK_VAL_REF_GBL: case QSE_AWK_VAL_REF_GBL:
/* ref->adr is the index to the global variables, not a real pointer address for QSE_AWK_VAL_REF_GBL */
return qse_awk_rtx_setgbl(rtx, (int)ref->adr, val); return qse_awk_rtx_setgbl(rtx, (int)ref->adr, val);
case QSE_AWK_VAL_REF_NAMEDIDX: case QSE_AWK_VAL_REF_NAMEDIDX:

View File

@ -469,8 +469,7 @@ int qse_wcsntoip6ad (const qse_wchar_t* src, qse_size_t len, qse_ip6ad_t* ipad)
return 0; return 0;
} }
qse_size_t qse_ip6adtombs ( qse_size_t qse_ip6adtombs (const qse_ip6ad_t* ipad, qse_mchar_t* buf, qse_size_t size)
const qse_ip6ad_t* ipad, qse_mchar_t* buf, qse_size_t size)
{ {
/* /*
* Note that int32_t and int16_t need only be "at least" large enough * Note that int32_t and int16_t need only be "at least" large enough
@ -498,7 +497,9 @@ qse_size_t qse_ip6adtombs (
for (i = 0; i < QSE_SIZEOF(ipad->value); i++) for (i = 0; i < QSE_SIZEOF(ipad->value); i++)
words[i / 2] |= (ipad->value[i] << ((1 - (i % 2)) << 3)); words[i / 2] |= (ipad->value[i] << ((1 - (i % 2)) << 3));
best.base = -1; best.base = -1;
best.len = 0;
cur.base = -1; cur.base = -1;
cur.len = 0;
for (i = 0; i < IP6ADDR_NWORDS; i++) for (i = 0; i < IP6ADDR_NWORDS; i++)
{ {
@ -571,8 +572,7 @@ qse_size_t qse_ip6adtombs (
#undef IP6ADDR_NWORDS #undef IP6ADDR_NWORDS
} }
qse_size_t qse_ip6adtowcs ( qse_size_t qse_ip6adtowcs (const qse_ip6ad_t* ipad, qse_wchar_t* buf, qse_size_t size)
const qse_ip6ad_t* ipad, qse_wchar_t* buf, qse_size_t size)
{ {
/* /*
* Note that int32_t and int16_t need only be "at least" large enough * Note that int32_t and int16_t need only be "at least" large enough
@ -600,7 +600,9 @@ qse_size_t qse_ip6adtowcs (
for (i = 0; i < QSE_SIZEOF(ipad->value); i++) for (i = 0; i < QSE_SIZEOF(ipad->value); i++)
words[i / 2] |= (ipad->value[i] << ((1 - (i % 2)) << 3)); words[i / 2] |= (ipad->value[i] << ((1 - (i % 2)) << 3));
best.base = -1; best.base = -1;
best.len = 0;
cur.base = -1; cur.base = -1;
cur.len = 0;
for (i = 0; i < IP6ADDR_NWORDS; i++) for (i = 0; i < IP6ADDR_NWORDS; i++)
{ {

View File

@ -75,6 +75,8 @@ protected:
App::App (Mmgr* mmgr) QSE_CPP_NOEXCEPT: Mmged(mmgr), _prev_app(QSE_NULL), _next_app(QSE_NULL), _guarded_child_pid(-1), _log(this) App::App (Mmgr* mmgr) QSE_CPP_NOEXCEPT: Mmged(mmgr), _prev_app(QSE_NULL), _next_app(QSE_NULL), _guarded_child_pid(-1), _log(this)
{ {
this->_cmgr = qse_getdflcmgr();
SigScopedMutexLocker sml(g_app_mutex); SigScopedMutexLocker sml(g_app_mutex);
if (!g_app_top) if (!g_app_top)
{ {
@ -542,6 +544,18 @@ int App::put_char_to_log_buf (qse_char_t c, void* ctx)
return 1; return 1;
} }
static int wcs_to_mbs (const qse_wchar_t* wcs, qse_size_t* wcslen, qse_mchar_t* mbs, qse_size_t* mbslen, void* ctx)
{
App* app = (App*)ctx;
return qse_wcsntombsnwithcmgr (wcs, wcslen, mbs, mbslen, app->getCmgr());
}
static int mbs_to_wcs (const qse_mchar_t* mbs, qse_size_t* mbslen, qse_wchar_t* wcs, qse_size_t* wcslen, void* ctx)
{
App* app = (App*)ctx;
return qse_mbsntowcsnwithcmgr (mbs, mbslen, wcs, wcslen, app->getCmgr());
}
void App::logfmtv (int mask, const qse_char_t* fmt, va_list ap) void App::logfmtv (int mask, const qse_char_t* fmt, va_list ap)
{ {
/*if (this->threaded)*/ this->_log.mtx.lock (); /*if (this->threaded)*/ this->_log.mtx.lock ();
@ -563,10 +577,10 @@ void App::logfmtv (int mask, const qse_char_t* fmt, va_list ap)
fo.limit = QSE_TYPE_MAX(qse_size_t) - 1; fo.limit = QSE_TYPE_MAX(qse_size_t) - 1;
fo.ctx = this; fo.ctx = this;
fo.put = put_char_to_log_buf; fo.put = put_char_to_log_buf;
#if defined(QSE_CHAR_IS_WCHAR) #if defined(QSE_CHAR_IS_MCHAR)
fo.conv = QSE_NULL; fo.conv = wcs_to_mbs;
#else #else
fo.conv = QSE_NULL; fo.conv = mbs_to_wcs;
#endif #endif
this->_log.last_mask = mask; this->_log.last_mask = mask;

View File

@ -562,14 +562,11 @@ static int reset_to_path (qse_dir_t* dir, const qse_char_t* path)
if (dir->flags & QSE_DIR_MBSPATH) if (dir->flags & QSE_DIR_MBSPATH)
{ {
const qse_mchar_t* mpath; const qse_mchar_t* mpath = (const qse_mchar_t*)path;
dp = QSE_OPENDIR(mpath[0] == QSE_MT('\0')? QSE_MT("."): mpath);
mpath = (const qse_mchar_t*)path;
dp = QSE_OPENDIR (mpath == QSE_MT('\0')? QSE_MT("."): mpath);
} }
else else
{ {
const qse_wchar_t* wpath; const qse_wchar_t* wpath;
QSE_ASSERT (dir->flags & QSE_DIR_WCSPATH); QSE_ASSERT (dir->flags & QSE_DIR_WCSPATH);

View File

@ -208,8 +208,8 @@ int qse_fs_move (qse_fs_t* fs, const qse_char_t* oldpath, const qse_char_t* newp
QSE_MEMSET (&fop, 0, QSE_SIZEOF(fop)); QSE_MEMSET (&fop, 0, QSE_SIZEOF(fop));
#if defined(QSE_CHAR_IS_MCHAR) #if defined(QSE_CHAR_IS_MCHAR)
fop.old_path = oldpath; fop.old_path = (qse_char_t*)oldpath;
fop.new_path = newpath; fop.new_path = (qse_char_t*)newpath;
#else #else
fop.old_path = qse_wcstombsdup(oldpath, QSE_NULL, fs->mmgr); fop.old_path = qse_wcstombsdup(oldpath, QSE_NULL, fs->mmgr);
fop.new_path = qse_wcstombsdup(newpath, QSE_NULL, fs->mmgr); fop.new_path = qse_wcstombsdup(newpath, QSE_NULL, fs->mmgr);
@ -281,7 +281,7 @@ int qse_fs_move (qse_fs_t* fs, const qse_char_t* oldpath, const qse_char_t* newp
{ {
/* the destination is a directory. move the source file /* the destination is a directory. move the source file
* into the destination directory */ * into the destination directory */
const qse_wchar_t* arr[4]; const qse_char_t* arr[4];
arr[0] = newpath; arr[0] = newpath;
arr[1] = QSE_T("/"); arr[1] = QSE_T("/");