From 50e84999251793ff2abb604649f3f8e7eb965d37 Mon Sep 17 00:00:00 2001 From: hyung-hwan Date: Sat, 4 Oct 2025 10:42:52 +0900 Subject: [PATCH] improved wide character type detection a bit --- lib/Sed.cpp | 20 ++++++++++---------- lib/hawk-cmn.h | 7 +++++-- 2 files changed, 15 insertions(+), 12 deletions(-) diff --git a/lib/Sed.cpp b/lib/Sed.cpp index 0dfaeb4f..836af7d0 100644 --- a/lib/Sed.cpp +++ b/lib/Sed.cpp @@ -32,15 +32,15 @@ HAWK_BEGIN_NAMESPACE(HAWK) ///////////////////////////////// -struct xtn_t +struct sed_xtn_t { Sed* sed; }; #if defined(HAWK_HAVE_INLINE) -static HAWK_INLINE xtn_t* GET_XTN(hawk_sed_t* sed) { return (xtn_t*)((hawk_uint8_t*)hawk_sed_getxtn(sed) - HAWK_SIZEOF(xtn_t)); } +static HAWK_INLINE sed_xtn_t* GET_XTN(hawk_sed_t* sed) { return (sed_xtn_t*)((hawk_uint8_t*)hawk_sed_getxtn(sed) - HAWK_SIZEOF(sed_xtn_t)); } #else -#define GET_XTN(sed) ((xtn_t*)((hawk_uint8_t*)hawk_sed_getxtn(sed) - HAWK_SIZEOF(xtn_t))) +#define GET_XTN(sed) ((sed_xtn_t*)((hawk_uint8_t*)hawk_sed_getxtn(sed) - HAWK_SIZEOF(sed_xtn_t))) #endif Sed::Sed (Mmgr* mmgr): Mmged(mmgr), sed(HAWK_NULL), dflerrstr(HAWK_NULL) @@ -63,12 +63,12 @@ void Sed::setCmgr (hawk_cmgr_t* cmgr) int Sed::open () { - this->sed = hawk_sed_open(this->getMmgr(), HAWK_SIZEOF(xtn_t), this->getCmgr(), &this->errinf); + this->sed = hawk_sed_open(this->getMmgr(), HAWK_SIZEOF(sed_xtn_t), this->getCmgr(), &this->errinf); if (HAWK_UNLIKELY(!this->sed)) return -1; - this->sed->_instsize += HAWK_SIZEOF(xtn_t); + this->sed->_instsize += HAWK_SIZEOF(sed_xtn_t); - xtn_t* xtn = GET_XTN(this->sed); + sed_xtn_t* xtn = GET_XTN(this->sed); xtn->sed = this; this->dflerrstr = hawk_sed_geterrstr(this->sed); @@ -293,7 +293,7 @@ void Sed::setConsoleLine (hawk_oow_t num) hawk_ooi_t Sed::sin (hawk_sed_t* s, hawk_sed_io_cmd_t cmd, hawk_sed_io_arg_t* arg, hawk_ooch_t* buf, hawk_oow_t len) { - xtn_t* xtn = GET_XTN(s); + sed_xtn_t* xtn = GET_XTN(s); Stream::Data iodata (xtn->sed, Stream::READ, arg); @@ -319,7 +319,7 @@ hawk_ooi_t Sed::sin (hawk_sed_t* s, hawk_sed_io_cmd_t cmd, hawk_sed_io_arg_t* ar hawk_ooi_t Sed::xin (hawk_sed_t* s, hawk_sed_io_cmd_t cmd, hawk_sed_io_arg_t* arg, hawk_ooch_t* buf, hawk_oow_t len) { - xtn_t* xtn = GET_XTN(s); + sed_xtn_t* xtn = GET_XTN(s); Stream::Data iodata (xtn->sed, Stream::READ, arg); @@ -345,7 +345,7 @@ hawk_ooi_t Sed::xin (hawk_sed_t* s, hawk_sed_io_cmd_t cmd, hawk_sed_io_arg_t* ar hawk_ooi_t Sed::xout (hawk_sed_t* s, hawk_sed_io_cmd_t cmd, hawk_sed_io_arg_t* arg, hawk_ooch_t* dat, hawk_oow_t len) { - xtn_t* xtn = GET_XTN(s); + sed_xtn_t* xtn = GET_XTN(s); Stream::Data iodata (xtn->sed, Stream::WRITE, arg); @@ -377,7 +377,7 @@ const hawk_ooch_t* Sed::getErrorString (hawk_errnum_t num) const const hawk_ooch_t* Sed::xerrstr (hawk_sed_t* s, hawk_errnum_t num) { - xtn_t* xtn = GET_XTN(s); + sed_xtn_t* xtn = GET_XTN(s); return xtn->sed->getErrorString(num); } diff --git a/lib/hawk-cmn.h b/lib/hawk-cmn.h index c4bbead0..8c06aa16 100644 --- a/lib/hawk-cmn.h +++ b/lib/hawk-cmn.h @@ -527,13 +527,16 @@ typedef unsigned char hawk_bchu_t; /* unsigned version of hawk_bch_t f // gcc/g++/clang/clang++: -fshort-wchar makes wchar_t to 2 bytes. HAWK_STATIC_ASSERT (HAWK_WIDE_CHAR_SIZE == sizeof(hawk_uch_t)); +#elif defined(HAWK_WIDE_CHAR_SIZE) && (HAWK_WIDE_CHAR_SIZE == 4) && (HAWK_WIDE_CHAR_SIZE == HAWK_SIZEOF_WCHAR_T) && defined(__WCHAR_TYPE__) && defined(HAWK_PREFER_PREFIX_L) + typedef __WCHAR_TYPE__ hawk_uch_t; + typedef hawk_uint32_t hawk_uchu_t; +# define HAWK_SIZEOF_UCH_T 4 + #elif defined(HAWK_WIDE_CHAR_SIZE) && (HAWK_WIDE_CHAR_SIZE == 4) && defined(__CHAR32_TYPE__) && defined(HAWK_HAVE_PREFIX_BIG_U) typedef __CHAR32_TYPE__ hawk_uch_t; typedef hawk_uint32_t hawk_uchu_t; # define HAWK_SIZEOF_UCH_T 4 -# if !defined(HAWK_PREFER_PREFIX_L) # define HAWK_USE_PREFIX_BIG_U -# endif #elif defined(HAWK_WIDE_CHAR_SIZE) && (HAWK_WIDE_CHAR_SIZE == 4) typedef hawk_uint32_t hawk_uch_t;