From 8687315e86e739bbd8b6deb035f2fc7c4e4a6907 Mon Sep 17 00:00:00 2001 From: LoveSy Date: Sat, 15 Jun 2024 01:53:51 +0800 Subject: [PATCH] Guard more system headers by `FMT_MODULE` (#4006) * Guard more system headers by `FMT_MODULE` * Merge FMT_MODULE and FMT_IMPORT_STD --- include/fmt/args.h | 2 +- include/fmt/base.h | 8 ++--- include/fmt/chrono.h | 2 +- include/fmt/compile.h | 2 +- include/fmt/format-inl.h | 12 +++---- include/fmt/format.h | 7 ++-- include/fmt/os.h | 6 ++-- include/fmt/ostream.h | 2 +- include/fmt/printf.h | 2 +- include/fmt/ranges.h | 2 +- include/fmt/std.h | 4 +-- include/fmt/xchar.h | 4 +-- src/fmt.cc | 3 ++ src/os.cc | 78 ++++++++++++++++++++-------------------- 14 files changed, 69 insertions(+), 65 deletions(-) diff --git a/include/fmt/args.h b/include/fmt/args.h index 10c1eb8f..31a60e8f 100644 --- a/include/fmt/args.h +++ b/include/fmt/args.h @@ -8,7 +8,7 @@ #ifndef FMT_ARGS_H_ #define FMT_ARGS_H_ -#ifndef FMT_IMPORT_STD +#ifndef FMT_MODULE # include // std::reference_wrapper # include // std::unique_ptr # include diff --git a/include/fmt/base.h b/include/fmt/base.h index a1af876f..0e9758b7 100644 --- a/include/fmt/base.h +++ b/include/fmt/base.h @@ -8,19 +8,19 @@ #ifndef FMT_BASE_H_ #define FMT_BASE_H_ +#if defined(FMT_IMPORT_STD) && !defined(FMT_MODULE) +# define FMT_MODULE +#endif + // c headers are preferable for performance reasons #ifndef FMT_MODULE # include // CHAR_BIT # include // FILE # include // strlen -#endif -#ifndef FMT_IMPORT_STD // is also included transitively from . # include // std::byte # include // std::enable_if -#else -import std; #endif // The fmt library version in the form major * 10000 + minor * 100 + patch. diff --git a/include/fmt/chrono.h b/include/fmt/chrono.h index 77d04032..c93123fd 100644 --- a/include/fmt/chrono.h +++ b/include/fmt/chrono.h @@ -8,7 +8,7 @@ #ifndef FMT_CHRONO_H_ #define FMT_CHRONO_H_ -#ifndef FMT_IMPORT_STD +#ifndef FMT_MODULE # include # include # include // std::isfinite diff --git a/include/fmt/compile.h b/include/fmt/compile.h index d77de358..b2afc2c3 100644 --- a/include/fmt/compile.h +++ b/include/fmt/compile.h @@ -8,7 +8,7 @@ #ifndef FMT_COMPILE_H_ #define FMT_COMPILE_H_ -#ifndef FMT_IMPORT_STD +#ifndef FMT_MODULE # include // std::back_inserter #endif diff --git a/include/fmt/format-inl.h b/include/fmt/format-inl.h index 73f40f3d..0750e7fc 100644 --- a/include/fmt/format-inl.h +++ b/include/fmt/format-inl.h @@ -8,16 +8,16 @@ #ifndef FMT_FORMAT_INL_H_ #define FMT_FORMAT_INL_H_ -#ifndef FMT_IMPORT_STD +#ifndef FMT_MODULE # include +# include // errno +# include # include # include -#endif -#include // errno -#include -#if !defined(FMT_STATIC_THOUSANDS_SEPARATOR) && !defined(FMT_IMPORT_STD) -# include +# if !defined(FMT_STATIC_THOUSANDS_SEPARATOR) +# include +# endif #endif #if defined(_WIN32) && !defined(FMT_USE_WRITE_CONSOLE) diff --git a/include/fmt/format.h b/include/fmt/format.h index fa8debc1..38ea6219 100644 --- a/include/fmt/format.h +++ b/include/fmt/format.h @@ -38,7 +38,7 @@ # define FMT_REMOVE_TRANSITIVE_INCLUDES #endif -#ifndef FMT_IMPORT_STD +#ifndef FMT_MODULE # include // std::signbit # include // uint32_t # include // std::memcpy @@ -56,15 +56,14 @@ #include "base.h" // Checking FMT_CPLUSPLUS for warning suppression in MSVC. -#if FMT_HAS_INCLUDE() && FMT_CPLUSPLUS > 201703L && \ - !defined(FMT_IMPORT_STD) +#if FMT_HAS_INCLUDE() && FMT_CPLUSPLUS > 201703L && !defined(FMT_MODULE) # include // std::bit_cast #endif // libc++ supports string_view in pre-c++17. #if FMT_HAS_INCLUDE() && \ (FMT_CPLUSPLUS >= 201703L || defined(_LIBCPP_VERSION)) -# ifndef FMT_IMPORT_STD +# if !defined(FMT_MODULE) # include # endif # define FMT_USE_STRING_VIEW diff --git a/include/fmt/os.h b/include/fmt/os.h index fae18f16..5344e5c2 100644 --- a/include/fmt/os.h +++ b/include/fmt/os.h @@ -8,8 +8,8 @@ #ifndef FMT_OS_H_ #define FMT_OS_H_ -#include -#ifndef FMT_IMPORT_STD +#ifndef FMT_MODULE +# include # include # include # include // std::system_error @@ -18,7 +18,7 @@ #include "format.h" #if defined __APPLE__ || defined(__FreeBSD__) -# if FMT_HAS_INCLUDE() +# if FMT_HAS_INCLUDE() && !defined(FMT_MODULE) # include // for LC_NUMERIC_MASK on OS X # endif #endif diff --git a/include/fmt/ostream.h b/include/fmt/ostream.h index f05e0dcd..98faef65 100644 --- a/include/fmt/ostream.h +++ b/include/fmt/ostream.h @@ -8,7 +8,7 @@ #ifndef FMT_OSTREAM_H_ #define FMT_OSTREAM_H_ -#ifndef FMT_IMPORT_STD +#ifndef FMT_MODULE # include // std::filebuf #endif diff --git a/include/fmt/printf.h b/include/fmt/printf.h index e6cd5c3d..ee4b06fd 100644 --- a/include/fmt/printf.h +++ b/include/fmt/printf.h @@ -8,7 +8,7 @@ #ifndef FMT_PRINTF_H_ #define FMT_PRINTF_H_ -#ifndef FMT_IMPORT_STD +#ifndef FMT_MODULE # include // std::max # include // std::numeric_limits #endif diff --git a/include/fmt/ranges.h b/include/fmt/ranges.h index 2cd5d37f..66329aae 100644 --- a/include/fmt/ranges.h +++ b/include/fmt/ranges.h @@ -8,7 +8,7 @@ #ifndef FMT_RANGES_H_ #define FMT_RANGES_H_ -#ifndef FMT_IMPORT_STD +#ifndef FMT_MODULE # include # include # include diff --git a/include/fmt/std.h b/include/fmt/std.h index 99528514..01635e18 100644 --- a/include/fmt/std.h +++ b/include/fmt/std.h @@ -8,7 +8,7 @@ #ifndef FMT_STD_H_ #define FMT_STD_H_ -#ifndef FMT_IMPORT_STD +#ifndef FMT_MODULE # include # include # include @@ -29,7 +29,7 @@ # include #endif -#ifndef FMT_IMPORT_STD +#ifndef FMT_MODULE // Checking FMT_CPLUSPLUS for warning suppression in MSVC. # if FMT_CPLUSPLUS >= 201703L # if FMT_HAS_INCLUDE() diff --git a/include/fmt/xchar.h b/include/fmt/xchar.h index b8bb1359..6c19bf3e 100644 --- a/include/fmt/xchar.h +++ b/include/fmt/xchar.h @@ -8,7 +8,7 @@ #ifndef FMT_XCHAR_H_ #define FMT_XCHAR_H_ -#ifndef FMT_IMPORT_STD +#ifndef FMT_MODULE # include #endif @@ -16,7 +16,7 @@ #include "format.h" #include "ranges.h" -#if !defined(FMT_STATIC_THOUSANDS_SEPARATOR) && !defined(FMT_IMPORT_STD) +#if !defined(FMT_STATIC_THOUSANDS_SEPARATOR) && !defined(FMT_MODULE) # include #endif diff --git a/src/fmt.cc b/src/fmt.cc index 364f4fa1..28f4bb82 100644 --- a/src/fmt.cc +++ b/src/fmt.cc @@ -4,6 +4,7 @@ module; // to prevent attachment to this module. #ifndef FMT_IMPORT_STD # include +# include # include # include # include @@ -40,6 +41,8 @@ module; # include # include # include + +import std; #endif #include #include diff --git a/src/os.cc b/src/os.cc index 81177b26..7bc18e2a 100644 --- a/src/os.cc +++ b/src/os.cc @@ -12,47 +12,49 @@ #include "fmt/os.h" -#include +#ifndef FMT_MODULE +# include -#if FMT_USE_FCNTL -# include -# include +# if FMT_USE_FCNTL +# include +# include -# ifdef _WRS_KERNEL // VxWorks7 kernel -# include // getpagesize +# ifdef _WRS_KERNEL // VxWorks7 kernel +# include // getpagesize +# endif + +# ifndef _WIN32 +# include +# else +# ifndef WIN32_LEAN_AND_MEAN +# define WIN32_LEAN_AND_MEAN +# endif +# include + +# ifndef S_IRUSR +# define S_IRUSR _S_IREAD +# endif +# ifndef S_IWUSR +# define S_IWUSR _S_IWRITE +# endif +# ifndef S_IRGRP +# define S_IRGRP 0 +# endif +# ifndef S_IWGRP +# define S_IWGRP 0 +# endif +# ifndef S_IROTH +# define S_IROTH 0 +# endif +# ifndef S_IWOTH +# define S_IWOTH 0 +# endif +# endif // _WIN32 +# endif // FMT_USE_FCNTL + +# ifdef _WIN32 +# include # endif - -# ifndef _WIN32 -# include -# else -# ifndef WIN32_LEAN_AND_MEAN -# define WIN32_LEAN_AND_MEAN -# endif -# include - -# ifndef S_IRUSR -# define S_IRUSR _S_IREAD -# endif -# ifndef S_IWUSR -# define S_IWUSR _S_IWRITE -# endif -# ifndef S_IRGRP -# define S_IRGRP 0 -# endif -# ifndef S_IWGRP -# define S_IWGRP 0 -# endif -# ifndef S_IROTH -# define S_IROTH 0 -# endif -# ifndef S_IWOTH -# define S_IWOTH 0 -# endif -# endif // _WIN32 -#endif // FMT_USE_FCNTL - -#ifdef _WIN32 -# include #endif namespace {