From f60512696dbaba7341fd3addfb55de701c4f60a5 Mon Sep 17 00:00:00 2001 From: "hyunghwan.chung" Date: Wed, 14 Nov 2018 07:59:39 +0000 Subject: [PATCH] fixed a wrong cmgr bug in moo_openstd(). --- moo/lib/main.c | 6 +++++- moo/lib/moo-msw.h | 3 +++ moo/lib/moo.h | 2 -- moo/lib/poll-msw.c | 19 +++++++++---------- moo/lib/std.c | 2 +- moo/lib/utl.c | 4 ++-- 6 files changed, 20 insertions(+), 16 deletions(-) diff --git a/moo/lib/main.c b/moo/lib/main.c index b79f81f..948a91d 100644 --- a/moo/lib/main.c +++ b/moo/lib/main.c @@ -449,6 +449,11 @@ int main (int argc, char* argv[]) memset (&cfg, 0, MOO_SIZEOF(cfg)); cfg.type = MOO_CFGSTD_OPTB; cfg.memsize = MIN_MEMSIZE; +#if defined(_WIN32) && (MOO_UCH_SIZE >= 4) + cfg.cmgr = moo_get_utf16_cmgr(); +#else + cfg.cmgr = moo_get_utf8_cmgr(); +#endif while ((c = moo_getbopt(argc, argv, &opt)) != MOO_BCI_EOF) { @@ -560,7 +565,6 @@ int main (int argc, char* argv[]) #else moo_uch_t tmp[1000]; moo_oow_t bcslen, ucslen; - ucslen = MOO_COUNTOF(tmp); moo_conv_utf8_to_ucstr(argv[i], &bcslen, tmp, &ucslen); in.type = MOO_IOSTD_FILEU; diff --git a/moo/lib/moo-msw.h b/moo/lib/moo-msw.h index 03f21eb..c17ef8a 100644 --- a/moo/lib/moo-msw.h +++ b/moo/lib/moo-msw.h @@ -42,6 +42,9 @@ _M_X64 x64 platform /*#define MOO_ENABLE_STATIC_MODULE*/ #define MOO_ENABLE_DYNAMIC_MODULE +/* use UCS4 for uch_t */ +/*#define MOO_UNICODE_SIZE 4*/ + /* windows for most of non-x86 platforms dropped. * make it selective to support old non-x86 windows platforms. */ #define MOO_ENDIAN_LITTLE diff --git a/moo/lib/moo.h b/moo/lib/moo.h index d8e2266..e36981d 100644 --- a/moo/lib/moo.h +++ b/moo/lib/moo.h @@ -119,10 +119,8 @@ typedef enum moo_option_dflval_t moo_option_dflval_t; enum moo_trait_t { -#if defined(MOO_BUILD_DEBUG) MOO_DEBUG_GC = (1u << 0), MOO_DEBUG_BIGINT = (1u << 1), -#endif /* perform no garbage collection when the heap is full. * you still can use moo_gc() explicitly. */ diff --git a/moo/lib/poll-msw.c b/moo/lib/poll-msw.c index c20f9bb..9793d5c 100644 --- a/moo/lib/poll-msw.c +++ b/moo/lib/poll-msw.c @@ -95,7 +95,7 @@ typedef struct _IO_STATUS_BLOCK typedef enum _FILE_INFORMATION_CLASS { - FilePipeLocalInformation = 24 + FilePipeLocalInformation = 24 } FILE_INFORMATION_CLASS, *PFILE_INFORMATION_CLASS; typedef DWORD (WINAPI *PNtQueryInformationFile) (HANDLE, IO_STATUS_BLOCK *, VOID *, ULONG, FILE_INFORMATION_CLASS); @@ -124,8 +124,7 @@ static int windows_compute_revents (HANDLE h, int *p_sought) if (!once_only) { NtQueryInformationFile = (PNtQueryInformationFile) - GetProcAddress (GetModuleHandle ("ntdll.dll"), - "NtQueryInformationFile"); + GetProcAddress (GetModuleHandle(TEXT("ntdll.dll")), "NtQueryInformationFile"); once_only = TRUE; } @@ -152,12 +151,12 @@ static int windows_compute_revents (HANDLE h, int *p_sought) memset (&fpli, 0, sizeof (fpli)); if (!NtQueryInformationFile - || NtQueryInformationFile (h, &iosb, &fpli, sizeof (fpli), - FilePipeLocalInformation) - || fpli.WriteQuotaAvailable >= PIPE_BUF - || (fpli.OutboundQuota < PIPE_BUF && - fpli.WriteQuotaAvailable == fpli.OutboundQuota)) + || NtQueryInformationFile (h, &iosb, &fpli, sizeof (fpli), FilePipeLocalInformation) + || fpli.WriteQuotaAvailable >= PIPE_BUF + || (fpli.OutboundQuota < PIPE_BUF && fpli.WriteQuotaAvailable == fpli.OutboundQuota)) + { happened |= *p_sought & (POLLOUT | POLLWRNORM | POLLWRBAND); + } } return happened; @@ -177,8 +176,8 @@ static int windows_compute_revents (HANDLE h, int *p_sought) if (!*p_sought) return 0; - irbuffer = (INPUT_RECORD *) alloca (nbuffer * sizeof (INPUT_RECORD)); - bRet = PeekConsoleInput (h, irbuffer, nbuffer, &avail); + irbuffer = (INPUT_RECORD *)_alloca(nbuffer * sizeof (INPUT_RECORD)); + bRet = PeekConsoleInput(h, irbuffer, nbuffer, &avail); if (!bRet || avail == 0) return POLLHUP; diff --git a/moo/lib/std.c b/moo/lib/std.c index ce9c0db..11e873f 100644 --- a/moo/lib/std.c +++ b/moo/lib/std.c @@ -3204,7 +3204,7 @@ moo_t* moo_openstd (moo_oow_t xtnsize, const moo_cfgstd_t* cfg, moo_errinf_t* er vmprim.vm_sleep = vm_sleep; moo = moo_open(&sys_mmgr, MOO_SIZEOF(xtn_t) + xtnsize, cfg->memsize, - (cfg->cmgr? cfg->cmgr: moo_get_utf8_cmgr), &vmprim, errinfo); + (cfg->cmgr? cfg->cmgr: moo_get_utf8_cmgr()), &vmprim, errinfo); if (!moo) return MOO_NULL; xtn = GET_XTN(moo); diff --git a/moo/lib/utl.c b/moo/lib/utl.c index a9e165c..568574d 100644 --- a/moo/lib/utl.c +++ b/moo/lib/utl.c @@ -632,7 +632,7 @@ MOO_INLINE int moo_conv_ucs_to_bcs_with_cmgr ( break; } - n = cmgr->uctobc (*p, bcs, rem); + n = cmgr->uctobc(*p, bcs, rem); if (n == 0) { ret = -1; @@ -670,7 +670,7 @@ MOO_INLINE int moo_conv_ucs_to_bcs_with_cmgr ( { moo_oow_t n; - n = cmgr->uctobc (*p, bcsbuf, MOO_COUNTOF(bcsbuf)); + n = cmgr->uctobc(*p, bcsbuf, MOO_COUNTOF(bcsbuf)); if (n == 0) { ret = -1;