From 17540072d3069fe87be932ba282ee4841bca3250 Mon Sep 17 00:00:00 2001 From: yyc12345 Date: Tue, 5 Aug 2025 14:04:20 +0800 Subject: [PATCH] fix: change the find order in PyCodec. - now PyCodec will try to use Iconv first. - re-claim the meaning of YYCC_FEAT_ICONV macro. --- src/CMakeLists.txt | 2 +- src/yycc/encoding/iconv.cpp | 2 +- src/yycc/encoding/iconv.hpp | 2 +- src/yycc/encoding/pycodec.hpp | 13 ++++++++----- 4 files changed, 11 insertions(+), 8 deletions(-) diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 79fa1e8..5402290 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -80,7 +80,7 @@ PRIVATE target_compile_definitions(YYCCommonplace PUBLIC # Iconv environment macro - $<$:YYCC_FEAT_ICONV> + $<$:YYCC_FEAT_ICONV> # OS macro $<$:YYCC_OS_WINDOWS> $<$:YYCC_OS_LINUX> diff --git a/src/yycc/encoding/iconv.cpp b/src/yycc/encoding/iconv.cpp index 18becda..657810b 100644 --- a/src/yycc/encoding/iconv.cpp +++ b/src/yycc/encoding/iconv.cpp @@ -1,6 +1,6 @@ #include "iconv.hpp" -#if YYCC_FEAT_ICONV || !defined(YYCC_OS_WINDOWS) +#if defined(YYCC_FEAT_ICONV) #include "../macro/endian_detector.hpp" #include diff --git a/src/yycc/encoding/iconv.hpp b/src/yycc/encoding/iconv.hpp index 00bb7c2..095cd78 100644 --- a/src/yycc/encoding/iconv.hpp +++ b/src/yycc/encoding/iconv.hpp @@ -48,7 +48,7 @@ namespace yycc::encoding::iconv { template using ConvResult = std::expected; -#if YYCC_FEAT_ICONV || !defined(YYCC_OS_WINDOWS) +#if defined(YYCC_FEAT_ICONV) /// @brief Char -> UTF8 class CharToUtf8 { diff --git a/src/yycc/encoding/pycodec.hpp b/src/yycc/encoding/pycodec.hpp index 0c52e11..5251fba 100644 --- a/src/yycc/encoding/pycodec.hpp +++ b/src/yycc/encoding/pycodec.hpp @@ -7,15 +7,18 @@ #include // Choose the backend of PyCodec module -#if defined(YYCC_OS_WINDOWS) && defined(YYCC_STL_MSSTL) -#include "windows.hpp" -#define YYCC_PYCODEC_WIN32_BACKEND -#define YYCC_PYCODEC_BACKEND_NS ::yycc::encoding::windows -#elif YYCC_FEAT_ICONV || !defined(YYCC_OS_WINDOWS) +#if defined(YYCC_FEAT_ICONV) +// We try Iconv first in any cases. #include "iconv.hpp" #define YYCC_PYCODEC_ICONV_BACKEND #define YYCC_PYCODEC_BACKEND_NS ::yycc::encoding::iconv +#elif defined(YYCC_OS_WINDOWS) && defined(YYCC_STL_MSSTL) +// If we can not use Iconv, we try to fallback to Windows implementation. +#include "windows.hpp" +#define YYCC_PYCODEC_WIN32_BACKEND +#define YYCC_PYCODEC_BACKEND_NS ::yycc::encoding::windows #else +// No viable implementation. #error "Can not find viable encoding convertion solution in current environment for PyCodec module." #endif