fix: change the find order in PyCodec.

- now PyCodec will try to use Iconv first.
- re-claim the meaning of YYCC_FEAT_ICONV macro.
This commit is contained in:
2025-08-05 14:04:20 +08:00
parent fcac886f07
commit 17540072d3
4 changed files with 11 additions and 8 deletions

View File

@ -80,7 +80,7 @@ PRIVATE
target_compile_definitions(YYCCommonplace target_compile_definitions(YYCCommonplace
PUBLIC PUBLIC
# Iconv environment macro # Iconv environment macro
$<$<BOOL:${YYCC_ENFORCE_ICONV}>:YYCC_FEAT_ICONV> $<$<BOOL:${Iconv_FOUND}>:YYCC_FEAT_ICONV>
# OS macro # OS macro
$<$<PLATFORM_ID:Windows>:YYCC_OS_WINDOWS> $<$<PLATFORM_ID:Windows>:YYCC_OS_WINDOWS>
$<$<PLATFORM_ID:Linux>:YYCC_OS_LINUX> $<$<PLATFORM_ID:Linux>:YYCC_OS_LINUX>

View File

@ -1,6 +1,6 @@
#include "iconv.hpp" #include "iconv.hpp"
#if YYCC_FEAT_ICONV || !defined(YYCC_OS_WINDOWS) #if defined(YYCC_FEAT_ICONV)
#include "../macro/endian_detector.hpp" #include "../macro/endian_detector.hpp"
#include <cerrno> #include <cerrno>

View File

@ -48,7 +48,7 @@ namespace yycc::encoding::iconv {
template<typename T> template<typename T>
using ConvResult = std::expected<T, ConvError>; using ConvResult = std::expected<T, ConvError>;
#if YYCC_FEAT_ICONV || !defined(YYCC_OS_WINDOWS) #if defined(YYCC_FEAT_ICONV)
/// @brief Char -> UTF8 /// @brief Char -> UTF8
class CharToUtf8 { class CharToUtf8 {

View File

@ -7,15 +7,18 @@
#include <expected> #include <expected>
// Choose the backend of PyCodec module // Choose the backend of PyCodec module
#if defined(YYCC_OS_WINDOWS) && defined(YYCC_STL_MSSTL) #if defined(YYCC_FEAT_ICONV)
#include "windows.hpp" // We try Iconv first in any cases.
#define YYCC_PYCODEC_WIN32_BACKEND
#define YYCC_PYCODEC_BACKEND_NS ::yycc::encoding::windows
#elif YYCC_FEAT_ICONV || !defined(YYCC_OS_WINDOWS)
#include "iconv.hpp" #include "iconv.hpp"
#define YYCC_PYCODEC_ICONV_BACKEND #define YYCC_PYCODEC_ICONV_BACKEND
#define YYCC_PYCODEC_BACKEND_NS ::yycc::encoding::iconv #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 #else
// No viable implementation.
#error "Can not find viable encoding convertion solution in current environment for PyCodec module." #error "Can not find viable encoding convertion solution in current environment for PyCodec module."
#endif #endif