From b625c597e7b48a98547153c645bdd4d29dccfdbb Mon Sep 17 00:00:00 2001 From: "J.W. Jagersma" Date: Fri, 18 Mar 2022 15:47:41 +0100 Subject: [PATCH 1/3] Implement getpagesize() for djgpp This is the "correct" way to find the page size on DPMI. In practice though, this could be hardcoded to return 4096 and no one would ever notice the difference. --- src/os.cc | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/src/os.cc b/src/os.cc index faa84c494850..75656ded4b19 100644 --- a/src/os.cc +++ b/src/os.cc @@ -51,6 +51,10 @@ # include #endif +#ifdef DJGPP +# include +#endif + #ifdef fileno # undef fileno #endif @@ -354,6 +358,11 @@ long getpagesize() { SYSTEM_INFO si; GetSystemInfo(&si); return si.dwPageSize; +# elif defined(DJGPP) + unsigned long size; + if (__dpmi_get_page_size(&size) != 0) + FMT_THROW(system_error(ENOSYS, "cannot get memory page size")); + return size; # else long size = FMT_POSIX_CALL(sysconf(_SC_PAGESIZE)); if (size < 0) FMT_THROW(system_error(errno, "cannot get memory page size")); From 2d86bc4a79a31b7a259128d5d4d53c5f45577d44 Mon Sep 17 00:00:00 2001 From: "J.W. Jagersma" Date: Sun, 20 Mar 2022 19:01:31 +0100 Subject: [PATCH 2/3] Don't use visibility attribute for djgpp. COFF objects don't support visibility, so using this attribute needlessly generates a long list of warnings. --- include/fmt/core.h | 2 +- include/fmt/format.h | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/include/fmt/core.h b/include/fmt/core.h index 106fd6fe8760..ee72cc014dfd 100644 --- a/include/fmt/core.h +++ b/include/fmt/core.h @@ -244,7 +244,7 @@ #else # define FMT_CLASS_API # if defined(FMT_EXPORT) || defined(FMT_SHARED) -# if defined(__GNUC__) || defined(__clang__) +# if (defined(__GNUC__) || defined(__clang__)) && !defined(DJGPP) # define FMT_API __attribute__((visibility("default"))) # endif # endif diff --git a/include/fmt/format.h b/include/fmt/format.h index 2d18621a1d1a..45af8c850a51 100644 --- a/include/fmt/format.h +++ b/include/fmt/format.h @@ -48,7 +48,7 @@ #include "core.h" -#if FMT_GCC_VERSION +#if FMT_GCC_VERSION && !defined(DJGPP) # define FMT_GCC_VISIBILITY_HIDDEN __attribute__((visibility("hidden"))) #else # define FMT_GCC_VISIBILITY_HIDDEN From 52c62ca386db7d90512aeccbbef79b4d263c2ab1 Mon Sep 17 00:00:00 2001 From: "J.W. Jagersma" Date: Sun, 20 Mar 2022 19:19:33 +0100 Subject: [PATCH 3/3] Provide typedefs for std::wstring and std::wostream This is for systems with no libc support for wide character strings (specifically djgpp). libstdc++ then doesn't define these aliases, but the primary templates are still available. --- include/fmt/core.h | 3 +++ include/fmt/format.h | 2 +- include/fmt/ostream.h | 6 +++++- include/fmt/xchar.h | 2 +- 4 files changed, 10 insertions(+), 3 deletions(-) diff --git a/include/fmt/core.h b/include/fmt/core.h index ee72cc014dfd..679c95b7633b 100644 --- a/include/fmt/core.h +++ b/include/fmt/core.h @@ -300,6 +300,9 @@ FMT_GCC_PRAGMA("GCC optimize(\"Og\")") FMT_BEGIN_NAMESPACE FMT_MODULE_EXPORT_BEGIN +// Alias for older systems where std::wstring isn't defined. +using wstring = std::basic_string; + // Implementations of enable_if_t and other metafunctions for older systems. template using enable_if_t = typename std::enable_if::type; diff --git a/include/fmt/format.h b/include/fmt/format.h index 45af8c850a51..3efdfa4be983 100644 --- a/include/fmt/format.h +++ b/include/fmt/format.h @@ -1232,7 +1232,7 @@ class utf8_to_utf16 { operator basic_string_view() const { return {&buffer_[0], size()}; } auto size() const -> size_t { return buffer_.size() - 1; } auto c_str() const -> const wchar_t* { return &buffer_[0]; } - auto str() const -> std::wstring { return {&buffer_[0], size()}; } + auto str() const -> wstring { return {&buffer_[0], size()}; } }; namespace dragonbox { diff --git a/include/fmt/ostream.h b/include/fmt/ostream.h index 30c04a2d6a83..1c549bfd4311 100644 --- a/include/fmt/ostream.h +++ b/include/fmt/ostream.h @@ -138,9 +138,13 @@ void print(std::ostream& os, format_string fmt, Args&&... args) { vprint(os, fmt, fmt::make_format_args(args...)); } +// Alias for older systems where std::wostream isn't defined. +FMT_MODULE_EXPORT +using wostream = std::basic_ostream; + FMT_MODULE_EXPORT template -void print(std::wostream& os, +void print(wostream& os, basic_format_string...> fmt, Args&&... args) { vprint(os, fmt, fmt::make_format_args>(args...)); diff --git a/include/fmt/xchar.h b/include/fmt/xchar.h index 9b57815d08bc..aa61b181c2cb 100644 --- a/include/fmt/xchar.h +++ b/include/fmt/xchar.h @@ -227,7 +227,7 @@ template void print(wformat_string fmt, T&&... args) { /** Converts *value* to ``std::wstring`` using the default format for type *T*. */ -template inline auto to_wstring(const T& value) -> std::wstring { +template inline auto to_wstring(const T& value) -> wstring { return format(FMT_STRING(L"{}"), value); } FMT_MODULE_EXPORT_END