Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Guard more system headers by FMT_MODULE #4006

Merged
merged 2 commits into from
Jun 14, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion include/fmt/args.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
#ifndef FMT_ARGS_H_
#define FMT_ARGS_H_

#ifndef FMT_IMPORT_STD
#ifndef FMT_MODULE
# include <functional> // std::reference_wrapper
# include <memory> // std::unique_ptr
# include <vector>
Expand Down
8 changes: 4 additions & 4 deletions include/fmt/base.h
Original file line number Diff line number Diff line change
Expand Up @@ -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 <limits.h> // CHAR_BIT
# include <stdio.h> // FILE
# include <string.h> // strlen
#endif

#ifndef FMT_IMPORT_STD
// <cstddef> is also included transitively from <type_traits>.
# include <cstddef> // std::byte
# include <type_traits> // std::enable_if
#else
import std;
#endif

// The fmt library version in the form major * 10000 + minor * 100 + patch.
Expand Down
2 changes: 1 addition & 1 deletion include/fmt/chrono.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
#ifndef FMT_CHRONO_H_
#define FMT_CHRONO_H_

#ifndef FMT_IMPORT_STD
#ifndef FMT_MODULE
# include <algorithm>
# include <chrono>
# include <cmath> // std::isfinite
Expand Down
2 changes: 1 addition & 1 deletion include/fmt/compile.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
#ifndef FMT_COMPILE_H_
#define FMT_COMPILE_H_

#ifndef FMT_IMPORT_STD
#ifndef FMT_MODULE
# include <iterator> // std::back_inserter
#endif

Expand Down
12 changes: 6 additions & 6 deletions include/fmt/format-inl.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,16 +8,16 @@
#ifndef FMT_FORMAT_INL_H_
#define FMT_FORMAT_INL_H_

#ifndef FMT_IMPORT_STD
#ifndef FMT_MODULE
# include <algorithm>
# include <cerrno> // errno
# include <climits>
# include <cmath>
# include <exception>
#endif
#include <cerrno> // errno
#include <climits>

#if !defined(FMT_STATIC_THOUSANDS_SEPARATOR) && !defined(FMT_IMPORT_STD)
# include <locale>
# if !defined(FMT_STATIC_THOUSANDS_SEPARATOR)
# include <locale>
# endif
#endif

#if defined(_WIN32) && !defined(FMT_USE_WRITE_CONSOLE)
Expand Down
7 changes: 3 additions & 4 deletions include/fmt/format.h
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@
# define FMT_REMOVE_TRANSITIVE_INCLUDES
#endif

#ifndef FMT_IMPORT_STD
#ifndef FMT_MODULE
# include <cmath> // std::signbit
# include <cstdint> // uint32_t
# include <cstring> // std::memcpy
Expand All @@ -56,15 +56,14 @@
#include "base.h"

// Checking FMT_CPLUSPLUS for warning suppression in MSVC.
#if FMT_HAS_INCLUDE(<bit>) && FMT_CPLUSPLUS > 201703L && \
!defined(FMT_IMPORT_STD)
#if FMT_HAS_INCLUDE(<bit>) && FMT_CPLUSPLUS > 201703L && !defined(FMT_MODULE)
# include <bit> // std::bit_cast
#endif

// libc++ supports string_view in pre-c++17.
#if FMT_HAS_INCLUDE(<string_view>) && \
(FMT_CPLUSPLUS >= 201703L || defined(_LIBCPP_VERSION))
# ifndef FMT_IMPORT_STD
# if !defined(FMT_MODULE)
# include <string_view>
# endif
# define FMT_USE_STRING_VIEW
Expand Down
6 changes: 3 additions & 3 deletions include/fmt/os.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@
#ifndef FMT_OS_H_
#define FMT_OS_H_

#include <cerrno>
#ifndef FMT_IMPORT_STD
#ifndef FMT_MODULE
# include <cerrno>
# include <cstddef>
# include <cstdio>
# include <system_error> // std::system_error
Expand All @@ -18,7 +18,7 @@
#include "format.h"

#if defined __APPLE__ || defined(__FreeBSD__)
# if FMT_HAS_INCLUDE(<xlocale.h>)
# if FMT_HAS_INCLUDE(<xlocale.h>) && !defined(FMT_MODULE)
# include <xlocale.h> // for LC_NUMERIC_MASK on OS X
# endif
#endif
Expand Down
2 changes: 1 addition & 1 deletion include/fmt/ostream.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
#ifndef FMT_OSTREAM_H_
#define FMT_OSTREAM_H_

#ifndef FMT_IMPORT_STD
#ifndef FMT_MODULE
# include <fstream> // std::filebuf
#endif

Expand Down
2 changes: 1 addition & 1 deletion include/fmt/printf.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
#ifndef FMT_PRINTF_H_
#define FMT_PRINTF_H_

#ifndef FMT_IMPORT_STD
#ifndef FMT_MODULE
# include <algorithm> // std::max
# include <limits> // std::numeric_limits
#endif
Expand Down
2 changes: 1 addition & 1 deletion include/fmt/ranges.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
#ifndef FMT_RANGES_H_
#define FMT_RANGES_H_

#ifndef FMT_IMPORT_STD
#ifndef FMT_MODULE
# include <initializer_list>
# include <iterator>
# include <string>
Expand Down
4 changes: 2 additions & 2 deletions include/fmt/std.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
#ifndef FMT_STD_H_
#define FMT_STD_H_

#ifndef FMT_IMPORT_STD
#ifndef FMT_MODULE
# include <atomic>
# include <bitset>
# include <complex>
Expand All @@ -29,7 +29,7 @@
# include <version>
#endif

#ifndef FMT_IMPORT_STD
#ifndef FMT_MODULE
// Checking FMT_CPLUSPLUS for warning suppression in MSVC.
# if FMT_CPLUSPLUS >= 201703L
# if FMT_HAS_INCLUDE(<filesystem>)
Expand Down
4 changes: 2 additions & 2 deletions include/fmt/xchar.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,15 @@
#ifndef FMT_XCHAR_H_
#define FMT_XCHAR_H_

#ifndef FMT_IMPORT_STD
#ifndef FMT_MODULE
# include <cwchar>
#endif

#include "color.h"
#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 <locale>
#endif

Expand Down
3 changes: 3 additions & 0 deletions src/fmt.cc
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ module;
// to prevent attachment to this module.
#ifndef FMT_IMPORT_STD
# include <algorithm>
# include <bitset>
# include <chrono>
# include <cmath>
# include <complex>
Expand Down Expand Up @@ -40,6 +41,8 @@ module;
# include <stdint.h>
# include <stdio.h>
# include <time.h>

import std;
#endif
#include <cerrno>
#include <climits>
Expand Down
74 changes: 38 additions & 36 deletions src/os.cc
Original file line number Diff line number Diff line change
Expand Up @@ -12,47 +12,49 @@

#include "fmt/os.h"

#include <climits>
#ifndef FMT_MODULE
# include <climits>

#if FMT_USE_FCNTL
# include <sys/stat.h>
# include <sys/types.h>

# ifdef _WRS_KERNEL // VxWorks7 kernel
# include <ioLib.h> // getpagesize
# endif
# if FMT_USE_FCNTL
# include <sys/stat.h>
# include <sys/types.h>

# ifndef _WIN32
# include <unistd.h>
# else
# ifndef WIN32_LEAN_AND_MEAN
# define WIN32_LEAN_AND_MEAN
# ifdef _WRS_KERNEL // VxWorks7 kernel
# include <ioLib.h> // getpagesize
# endif
# include <io.h>

# 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
# ifndef _WIN32
# include <unistd.h>
# else
# ifndef WIN32_LEAN_AND_MEAN
# define WIN32_LEAN_AND_MEAN
# endif
# include <io.h>

#ifdef _WIN32
# include <windows.h>
# 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 <windows.h>
# endif
#endif

namespace {
Expand Down
Loading