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:
parent
12eacceec0
commit
7f57afe262
@ -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_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_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
|
||||
{
|
||||
@ -61,6 +67,19 @@ public:
|
||||
App (Mmgr* mmgr = QSE_NULL) 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 chroot (const qse_mchar_t* mpath) QSE_CPP_NOEXCEPT;
|
||||
@ -195,6 +214,7 @@ private:
|
||||
_SigLink _sig[QSE_NSIGS];
|
||||
long int _guarded_child_pid;
|
||||
|
||||
qse_cmgr_t* _cmgr;
|
||||
struct log_t
|
||||
{
|
||||
log_t (App* app): mask(0), last_mask(0), len(0), mtx(app->getMmgr())
|
||||
|
@ -45,7 +45,8 @@ enum qse_json_errnum_t
|
||||
|
||||
QSE_JSON_ENOMEM,
|
||||
QSE_JSON_EINVAL,
|
||||
QSE_JSON_EFINIS
|
||||
QSE_JSON_EFINIS,
|
||||
QSE_JSON_EECERR
|
||||
};
|
||||
typedef enum qse_json_errnum_t qse_json_errnum_t;
|
||||
|
||||
|
@ -1019,7 +1019,7 @@ oops_3:
|
||||
oops_2:
|
||||
qse_str_fini (&rtx->inrec.line);
|
||||
oops_1:
|
||||
qse_awk_freemem (rtx, rtx->stack);
|
||||
qse_awk_rtx_freemem (rtx, rtx->stack);
|
||||
oops_0:
|
||||
qse_awk_seterrnum (awk, QSE_AWK_ENOMEM, QSE_NULL);
|
||||
return -1;
|
||||
|
@ -440,7 +440,7 @@ void* qse_awk_stdmodsym (qse_awk_t* awk, void* handle, const qse_char_t* name)
|
||||
qse_mchar_t* mname;
|
||||
|
||||
#if defined(QSE_CHAR_IS_MCHAR)
|
||||
mname = name;
|
||||
mname = (qse_mchar_t*)name;
|
||||
#else
|
||||
mname = qse_wcstombsdupwithcmgr(name, QSE_NULL, awk->mmgr, awk->cmgr);
|
||||
if (!mname)
|
||||
|
@ -282,7 +282,7 @@ qse_awk_val_t* qse_awk_rtx_makestrvalwithwxstr (qse_awk_rtx_t* rtx, const qse_wc
|
||||
qse_size_t wcslen;
|
||||
|
||||
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)
|
||||
{
|
||||
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);
|
||||
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);
|
||||
#endif
|
||||
|
||||
qse_awk_rtx_freevalstr (rtx, v, str0);
|
||||
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)
|
||||
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);
|
||||
#else
|
||||
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);
|
||||
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);
|
||||
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:
|
||||
/* 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);
|
||||
|
||||
case QSE_AWK_VAL_REF_NAMEDIDX:
|
||||
|
@ -469,8 +469,7 @@ int qse_wcsntoip6ad (const qse_wchar_t* src, qse_size_t len, qse_ip6ad_t* ipad)
|
||||
return 0;
|
||||
}
|
||||
|
||||
qse_size_t qse_ip6adtombs (
|
||||
const qse_ip6ad_t* ipad, qse_mchar_t* buf, qse_size_t size)
|
||||
qse_size_t qse_ip6adtombs (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
|
||||
@ -498,7 +497,9 @@ qse_size_t qse_ip6adtombs (
|
||||
for (i = 0; i < QSE_SIZEOF(ipad->value); i++)
|
||||
words[i / 2] |= (ipad->value[i] << ((1 - (i % 2)) << 3));
|
||||
best.base = -1;
|
||||
best.len = 0;
|
||||
cur.base = -1;
|
||||
cur.len = 0;
|
||||
|
||||
for (i = 0; i < IP6ADDR_NWORDS; i++)
|
||||
{
|
||||
@ -571,8 +572,7 @@ qse_size_t qse_ip6adtombs (
|
||||
#undef IP6ADDR_NWORDS
|
||||
}
|
||||
|
||||
qse_size_t qse_ip6adtowcs (
|
||||
const qse_ip6ad_t* ipad, qse_wchar_t* buf, qse_size_t size)
|
||||
qse_size_t qse_ip6adtowcs (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
|
||||
@ -600,7 +600,9 @@ qse_size_t qse_ip6adtowcs (
|
||||
for (i = 0; i < QSE_SIZEOF(ipad->value); i++)
|
||||
words[i / 2] |= (ipad->value[i] << ((1 - (i % 2)) << 3));
|
||||
best.base = -1;
|
||||
best.len = 0;
|
||||
cur.base = -1;
|
||||
cur.len = 0;
|
||||
|
||||
for (i = 0; i < IP6ADDR_NWORDS; i++)
|
||||
{
|
||||
|
@ -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)
|
||||
{
|
||||
this->_cmgr = qse_getdflcmgr();
|
||||
|
||||
SigScopedMutexLocker sml(g_app_mutex);
|
||||
if (!g_app_top)
|
||||
{
|
||||
@ -542,6 +544,18 @@ int App::put_char_to_log_buf (qse_char_t c, void* ctx)
|
||||
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)
|
||||
{
|
||||
/*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.ctx = this;
|
||||
fo.put = put_char_to_log_buf;
|
||||
#if defined(QSE_CHAR_IS_WCHAR)
|
||||
fo.conv = QSE_NULL;
|
||||
#if defined(QSE_CHAR_IS_MCHAR)
|
||||
fo.conv = wcs_to_mbs;
|
||||
#else
|
||||
fo.conv = QSE_NULL;
|
||||
fo.conv = mbs_to_wcs;
|
||||
#endif
|
||||
|
||||
this->_log.last_mask = mask;
|
||||
|
@ -532,7 +532,7 @@ static int reset_to_path (qse_dir_t* dir, const qse_char_t* path)
|
||||
|
||||
if (dir->flags & QSE_DIR_MBSPATH)
|
||||
{
|
||||
mptr = make_mbsdos_path (dir, (const qse_mchar_t*)path);
|
||||
mptr = make_mbsdos_path(dir, (const qse_mchar_t*)path);
|
||||
}
|
||||
else
|
||||
{
|
||||
@ -540,16 +540,16 @@ static int reset_to_path (qse_dir_t* dir, const qse_char_t* path)
|
||||
|
||||
QSE_ASSERT (dir->flags & QSE_DIR_WCSPATH);
|
||||
|
||||
wptr = make_wcsdos_path (dir, (const qse_wchar_t*)path);
|
||||
wptr = make_wcsdos_path(dir, (const qse_wchar_t*)path);
|
||||
if (wptr == QSE_NULL) return -1;
|
||||
mptr = wcs_to_mbuf (dir, wptr, &dir->mbuf);
|
||||
mptr = wcs_to_mbuf(dir, wptr, &dir->mbuf);
|
||||
}
|
||||
if (mptr == QSE_NULL) return -1;
|
||||
|
||||
rc = _dos_findfirst (mptr, _A_NORMAL | _A_SUBDIR, &dir->f);
|
||||
rc = _dos_findfirst(mptr, _A_NORMAL | _A_SUBDIR, &dir->f);
|
||||
if (rc != 0)
|
||||
{
|
||||
dir->errnum = syserr_to_errnum (errno);
|
||||
dir->errnum = syserr_to_errnum(errno);
|
||||
return -1;
|
||||
}
|
||||
|
||||
@ -562,36 +562,33 @@ static int reset_to_path (qse_dir_t* dir, const qse_char_t* path)
|
||||
|
||||
if (dir->flags & QSE_DIR_MBSPATH)
|
||||
{
|
||||
const qse_mchar_t* mpath;
|
||||
|
||||
mpath = (const qse_mchar_t*)path;
|
||||
dp = QSE_OPENDIR (mpath == QSE_MT('\0')? QSE_MT("."): mpath);
|
||||
const qse_mchar_t* mpath = (const qse_mchar_t*)path;
|
||||
dp = QSE_OPENDIR(mpath[0] == QSE_MT('\0')? QSE_MT("."): mpath);
|
||||
}
|
||||
else
|
||||
{
|
||||
|
||||
const qse_wchar_t* wpath;
|
||||
QSE_ASSERT (dir->flags & QSE_DIR_WCSPATH);
|
||||
|
||||
wpath = (const qse_wchar_t*)path;
|
||||
if (wpath[0] == QSE_WT('\0'))
|
||||
{
|
||||
dp = QSE_OPENDIR (QSE_MT("."));
|
||||
dp = QSE_OPENDIR(QSE_MT("."));
|
||||
}
|
||||
else
|
||||
{
|
||||
qse_mchar_t* mptr;
|
||||
|
||||
mptr = wcs_to_mbuf (dir, wpath, &dir->mbuf);
|
||||
mptr = wcs_to_mbuf(dir, wpath, &dir->mbuf);
|
||||
if (mptr == QSE_NULL) return -1;
|
||||
|
||||
dp = QSE_OPENDIR (mptr);
|
||||
dp = QSE_OPENDIR(mptr);
|
||||
}
|
||||
}
|
||||
|
||||
if (dp == QSE_NULL)
|
||||
{
|
||||
dir->errnum = syserr_to_errnum (errno);
|
||||
dir->errnum = syserr_to_errnum(errno);
|
||||
return -1;
|
||||
}
|
||||
|
||||
|
@ -208,11 +208,11 @@ 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));
|
||||
|
||||
#if defined(QSE_CHAR_IS_MCHAR)
|
||||
fop.old_path = oldpath;
|
||||
fop.new_path = newpath;
|
||||
fop.old_path = (qse_char_t*)oldpath;
|
||||
fop.new_path = (qse_char_t*)newpath;
|
||||
#else
|
||||
fop.old_path = qse_wcstombsdup (oldpath, QSE_NULL, fs->mmgr);
|
||||
fop.new_path = qse_wcstombsdup (newpath, QSE_NULL, fs->mmgr);
|
||||
fop.old_path = qse_wcstombsdup(oldpath, QSE_NULL, fs->mmgr);
|
||||
fop.new_path = qse_wcstombsdup(newpath, QSE_NULL, fs->mmgr);
|
||||
if (fop.old_path == QSE_NULL || fop.old_path == QSE_NULL)
|
||||
{
|
||||
fs->errnum = QSE_FS_ENOMEM;
|
||||
@ -281,16 +281,16 @@ 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
|
||||
* into the destination directory */
|
||||
const qse_wchar_t* arr[4];
|
||||
const qse_char_t* arr[4];
|
||||
|
||||
arr[0] = newpath;
|
||||
arr[1] = QSE_T("/");
|
||||
arr[2] = qse_basename(oldpath);
|
||||
arr[3] = QSE_NULL;
|
||||
#if defined(QSE_CHAR_IS_MCHAR)
|
||||
fop.new_path2 = qse_stradup (arr, QSE_NULL, fs->mmgr);
|
||||
fop.new_path2 = qse_stradup(arr, QSE_NULL, fs->mmgr);
|
||||
#else
|
||||
fop.new_path2 = qse_wcsatombsdup (arr, QSE_NULL, fs->mmgr);
|
||||
fop.new_path2 = qse_wcsatombsdup(arr, QSE_NULL, fs->mmgr);
|
||||
#endif
|
||||
if (fop.new_path2 == QSE_NULL)
|
||||
{
|
||||
|
Loading…
Reference in New Issue
Block a user