Skip to content

Commit

Permalink
Merged revision(s) 22608 from trunk/OpenMPT:
Browse files Browse the repository at this point in the history
[Fix] mpt/base/detect_quirks.hpp: Add MPT_LIBCXX_QUIRK_NO_OPTIONAL_VALUE for older Apple Clang. See <fink/fink-distributions#1202>.
........


git-svn-id: https://source.openmpt.org/svn/openmpt/branches/OpenMPT-1.31@22613 56274372-70c3-4bfc-bfc3-4c3a0b034d27
  • Loading branch information
manxorist committed Dec 26, 2024
1 parent 5d1023c commit 28746a1
Show file tree
Hide file tree
Showing 6 changed files with 50 additions and 0 deletions.
8 changes: 8 additions & 0 deletions common/mptString.h
Original file line number Diff line number Diff line change
Expand Up @@ -429,7 +429,11 @@ inline mpt::ustring ToUnicode(uint16 codepage, Tencoding &&fallback, Tsrc &&str)
std::optional<mpt::common_encoding> charset = mpt::optional_encoding_from_codepage(codepage);
if(charset.has_value())
{
#if defined(MPT_LIBCXX_QUIRK_NO_OPTIONAL_VALUE)
result = mpt::transcode<mpt::ustring>(*charset, std::forward<Tsrc>(str));
#else
result = mpt::transcode<mpt::ustring>(charset.value(), std::forward<Tsrc>(str));
#endif
} else if(mpt::has_codepage(static_cast<UINT>(codepage)))
{
result = mpt::transcode<mpt::ustring>(static_cast<UINT>(codepage), std::forward<Tsrc>(str));
Expand All @@ -440,7 +444,11 @@ inline mpt::ustring ToUnicode(uint16 codepage, Tencoding &&fallback, Tsrc &&str)
return result;
#else // !MPT_OS_WINDOWS
std::optional<mpt::common_encoding> charset = mpt::optional_encoding_from_codepage(codepage);
#if defined(MPT_LIBCXX_QUIRK_NO_OPTIONAL_VALUE)
return charset.has_value() ? mpt::transcode<mpt::ustring>(charset.value(), std::forward<Tsrc>(str)) : mpt::transcode<mpt::ustring>(std::forward<Tencoding>(fallback), std::forward<Tsrc>(str));
#else
return charset.has_value() ? mpt::transcode<mpt::ustring>(*charset, std::forward<Tsrc>(str)) : mpt::transcode<mpt::ustring>(std::forward<Tencoding>(fallback), std::forward<Tsrc>(str));
#endif
#endif // MPT_OS_WINDOWS
}

Expand Down
6 changes: 6 additions & 0 deletions soundlib/Dlsbank.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1415,7 +1415,13 @@ bool CDLSBank::Open(FileReader file)
uint32 nInsDef;

if(file.GetOptionalFileName())
{
#if defined(MPT_LIBCXX_QUIRK_NO_OPTIONAL_VALUE)
m_szFileName = *(file.GetOptionalFileName());
#else
m_szFileName = file.GetOptionalFileName().value();
#endif
}

file.Rewind();
if(!file.CanRead(256))
Expand Down
4 changes: 4 additions & 0 deletions soundlib/Load_mod.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1286,7 +1286,11 @@ bool CSoundFile::ReadMOD(FileReader &file, ModLoadingFlags loadFlags)
FileReader amData;
if(file.GetOptionalFileName())
{
#if defined(MPT_LIBCXX_QUIRK_NO_OPTIONAL_VALUE)
mpt::PathString filename = *(file.GetOptionalFileName());
#else
mpt::PathString filename = file.GetOptionalFileName().value();
#endif
// Find instrument definition file
const mpt::PathString exts[] = {P_(".nt"), P_(".NT"), P_(".as"), P_(".AS")};
for(const auto &ext : exts)
Expand Down
16 changes: 16 additions & 0 deletions src/mpt/base/detect_quirks.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -322,4 +322,20 @@



#if MPT_OS_MACOSX_OR_IOS
#if defined(TARGET_OS_OSX)
#if TARGET_OS_OSX
#if !defined(MAC_OS_X_VERSION_10_14)
#define MPT_LIBCXX_QUIRK_NO_OPTIONAL_VALUE
#else
#if (MAC_OS_X_VERSION_MIN_REQUIRED < MAC_OS_X_VERSION_10_14)
#define MPT_LIBCXX_QUIRK_NO_OPTIONAL_VALUE
#endif
#endif
#endif
#endif
#endif



#endif // MPT_BASE_DETECT_QUIRKS_HPP
4 changes: 4 additions & 0 deletions src/mpt/io_file_adapter/fileadapter.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,11 @@ class FileAdapter {
m_Filename = tempName;
m_IsTempFile = true;
} else {
#if defined(MPT_LIBCXX_QUIRK_NO_OPTIONAL_VALUE)
m_Filename = *(file.GetOptionalFileName());
#else
m_Filename = file.GetOptionalFileName().value();
#endif
}
} catch (const std::runtime_error &) {
m_Filename = mpt::os_path{};
Expand Down
12 changes: 12 additions & 0 deletions src/mpt/library/library.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -187,7 +187,11 @@ class library {
if (!optionalfilename) {
return std::nullopt;
}
#if defined(MPT_LIBCXX_QUIRK_NO_OPTIONAL_VALUE)
mpt::native_path & filename = *optionalfilename;
#else
mpt::native_path & filename = optionalfilename.value();
#endif
if (filename.empty()) {
return std::nullopt;
}
Expand Down Expand Up @@ -351,7 +355,11 @@ class library {
if (!optionalfilename) {
return std::nullopt;
}
#if defined(MPT_LIBCXX_QUIRK_NO_OPTIONAL_VALUE)
mpt::native_path & filename = *optionalfilename;
#else
mpt::native_path & filename = optionalfilename.value();
#endif
if (filename.empty()) {
return std::nullopt;
}
Expand Down Expand Up @@ -405,7 +413,11 @@ class library {
if (!optionalfilename) {
return std::nullopt;
}
#if defined(MPT_LIBCXX_QUIRK_NO_OPTIONAL_VALUE)
mpt::native_path & filename = *optionalfilename;
#else
mpt::native_path & filename = optionalfilename.value();
#endif
if (filename.empty()) {
return std::nullopt;
}
Expand Down

0 comments on commit 28746a1

Please sign in to comment.