Repository navigation
fix(windows): isolate Moonlight errno macros #5805
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
Open
ArgaAAL
wants to merge
4
commits into
LizardByte:master
Choose a base branch
from
ArgaAAL:fix/windows-moonlight-errno-isolation
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
b5adb57
fix(windows): isolate Moonlight errno macros
ArgaAAL 8b9a6e3
refactor: group dependency compatibility headers
ArgaAAL a1284f8
Merge latest master for review validation
ArgaAAL cea8193
test: use shared fixture for Moonlight errno tests
ArgaAAL File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,36 @@ | ||
| /** | ||
| * @file src/compat/moonlight.h | ||
| * @brief Import Moonlight's C declarations without changing C++ errno definitions. | ||
| */ | ||
| #pragma once | ||
|
|
||
| // standard includes | ||
| // Load the CRT definitions before saving them, even when this is the first include. | ||
| #include <cerrno> | ||
|
|
||
| // PlatformSockets.h maps these names to Winsock values for Moonlight's C code. | ||
| // Let that code see its mappings, but do not leak them into Boost or the C++ library. | ||
| #ifdef _WIN32 | ||
| #pragma push_macro("EAGAIN") | ||
| #pragma push_macro("EINTR") | ||
| #pragma push_macro("EWOULDBLOCK") | ||
| #pragma push_macro("EINPROGRESS") | ||
| #pragma push_macro("ETIMEDOUT") | ||
| #pragma push_macro("ECONNREFUSED") | ||
| #pragma push_macro("EMSGSIZE") | ||
| #endif | ||
|
|
||
| // lib includes | ||
| extern "C" { | ||
| #include <moonlight-common-c/src/Limelight-internal.h> | ||
| } | ||
|
|
||
| #ifdef _WIN32 | ||
| #pragma pop_macro("EMSGSIZE") | ||
| #pragma pop_macro("ECONNREFUSED") | ||
| #pragma pop_macro("ETIMEDOUT") | ||
| #pragma pop_macro("EINPROGRESS") | ||
| #pragma pop_macro("EWOULDBLOCK") | ||
| #pragma pop_macro("EINTR") | ||
| #pragma pop_macro("EAGAIN") | ||
| #endif |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,69 @@ | ||
| /** | ||
| * @file tests/unit/moonlight_common_first_include.cpp | ||
| * @brief Capture errno when the Moonlight wrapper is the first include in its translation unit. | ||
| */ | ||
|
|
||
| // local includes | ||
| #include <src/compat/moonlight.h> | ||
|
|
||
| namespace { | ||
| // Capture before any other include. Missing macros use zero only to keep a | ||
| // broken wrapper testable at runtime; the separate completeness flag must pass. | ||
| constexpr int errno_after_first_include[7] /* NOSONAR(cpp:S5945): No extra headers before the errno snapshot. */ { | ||
| #ifdef EAGAIN | ||
| EAGAIN, | ||
| #else | ||
| 0, | ||
| #endif | ||
| #ifdef EINTR | ||
| EINTR, | ||
| #else | ||
| 0, | ||
| #endif | ||
| #ifdef EWOULDBLOCK | ||
| EWOULDBLOCK, | ||
| #else | ||
| 0, | ||
| #endif | ||
| #ifdef EINPROGRESS | ||
| EINPROGRESS, | ||
| #else | ||
| 0, | ||
| #endif | ||
| #ifdef ETIMEDOUT | ||
| ETIMEDOUT, | ||
| #else | ||
| 0, | ||
| #endif | ||
| #ifdef ECONNREFUSED | ||
| ECONNREFUSED, | ||
| #else | ||
| 0, | ||
| #endif | ||
| #ifdef EMSGSIZE | ||
| EMSGSIZE | ||
| #else | ||
| 0 | ||
| #endif | ||
| }; ///< Errno values captured immediately after the first include. | ||
|
|
||
| #if defined(EAGAIN) && defined(EINTR) && defined(EWOULDBLOCK) && defined(EINPROGRESS) && defined(ETIMEDOUT) && defined(ECONNREFUSED) && defined(EMSGSIZE) | ||
| constexpr bool errno_complete = true; ///< Every required errno name was defined. | ||
| #else | ||
| constexpr bool errno_complete = false; ///< At least one required errno name was absent. | ||
| #endif | ||
| } // namespace | ||
|
|
||
| namespace moonlight_common_tests { | ||
| /** | ||
| * @brief Copy the first-include errno snapshot without sharing library types across translation units. | ||
| * @param values Destination for seven errno values. | ||
| * @return Whether all seven errno names were defined. | ||
| */ | ||
| bool first_include_errno(int *values) { | ||
| for (int index = 0; index < 7; ++index) { | ||
| values[index] = errno_after_first_include[index]; | ||
| } | ||
| return errno_complete; | ||
| } | ||
| } // namespace moonlight_common_tests |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,111 @@ | ||
| /** | ||
| * @file tests/unit/test_moonlight_common.cpp | ||
| * @brief Verify that importing Moonlight does not change C++ errno constants. | ||
| */ | ||
|
|
||
| // The shared test header includes Boost. Keep it after the errno snapshots and | ||
| // the explicit Boost include so it cannot mask this regression. | ||
|
|
||
| // standard includes | ||
| #include <array> | ||
| #include <cerrno> | ||
|
ReenigneArcher marked this conversation as resolved.
|
||
|
|
||
| namespace { | ||
| constexpr std::array<int, 7> errno_before_moonlight { | ||
| EAGAIN, | ||
| EINTR, | ||
| EWOULDBLOCK, | ||
| EINPROGRESS, | ||
| ETIMEDOUT, | ||
| ECONNREFUSED, | ||
| EMSGSIZE | ||
| }; ///< CRT errno values before including Moonlight. | ||
| } | ||
|
|
||
| // local includes | ||
| // Capture errno immediately after including Moonlight. | ||
| #include <src/compat/moonlight.h> // NOSONAR(cpp:S954): The baseline must precede this include. | ||
|
|
||
| namespace { | ||
| constexpr std::array<int, 7> errno_after_moonlight { | ||
| EAGAIN, | ||
| EINTR, | ||
| EWOULDBLOCK, | ||
| EINPROGRESS, | ||
| ETIMEDOUT, | ||
| ECONNREFUSED, | ||
| EMSGSIZE | ||
| }; ///< Errno values immediately after including Moonlight. | ||
| } | ||
|
|
||
| // lib includes | ||
| // Boost must be parsed after the wrapper for this regression test. | ||
| #include <boost/system/error_code.hpp> | ||
|
|
||
| // test includes | ||
| #include "../tests_common.h" | ||
|
|
||
| namespace moonlight_common_tests { | ||
| /** | ||
| * @brief Copy the first-include errno snapshot without sharing library types across translation units. | ||
| * @param values Destination for seven errno values in the baseline array's order. | ||
| * @return Whether all seven errno names were defined. | ||
| */ | ||
| bool first_include_errno(int *values); | ||
| } // namespace moonlight_common_tests | ||
|
|
||
| /** | ||
| * @brief Including Moonlight preserves the CRT errno values. | ||
| */ | ||
| TEST(MoonlightCommonTests, PreservesCrtErrno) { | ||
| EXPECT_EQ(errno_before_moonlight, errno_after_moonlight); | ||
| } | ||
|
|
||
| /** | ||
| * @brief Boost's error constants match the original CRT errno values. | ||
| */ | ||
| TEST(MoonlightCommonTests, PreservesBoostErrno) { | ||
| const std::array<int, 7> boost_errno { | ||
| boost::system::errc::resource_unavailable_try_again, | ||
| boost::system::errc::interrupted, | ||
| boost::system::errc::operation_would_block, | ||
| boost::system::errc::operation_in_progress, | ||
| boost::system::errc::timed_out, | ||
| boost::system::errc::connection_refused, | ||
| boost::system::errc::message_size | ||
| }; | ||
| EXPECT_EQ(errno_before_moonlight, boost_errno); | ||
| } | ||
|
|
||
| /** | ||
| * @brief The wrapper initializes errno even when it is the first include. | ||
| */ | ||
| TEST(MoonlightCommonTests, FirstIncludePreservesCrtErrno) { | ||
| std::array<int, 7> first_include_values {}; | ||
| EXPECT_TRUE(moonlight_common_tests::first_include_errno(first_include_values.data())); | ||
| EXPECT_EQ(errno_before_moonlight, first_include_values); | ||
| } | ||
|
|
||
| /** | ||
| * @brief Native connection-refused errors match Boost's generic condition. | ||
| */ | ||
| TEST(MoonlightCommonTests, ConnectionRefusedCondition) { | ||
| #ifdef _WIN32 | ||
| const boost::system::error_code ec {WSAECONNREFUSED, boost::system::system_category()}; | ||
| #else | ||
| const boost::system::error_code ec {ECONNREFUSED, boost::system::system_category()}; | ||
| #endif | ||
| EXPECT_EQ(ec, boost::system::errc::connection_refused); | ||
| } | ||
|
|
||
| /** | ||
| * @brief Native timeouts match Boost's generic condition. | ||
| */ | ||
| TEST(MoonlightCommonTests, TimedOutCondition) { | ||
| #ifdef _WIN32 | ||
| const boost::system::error_code ec {WSAETIMEDOUT, boost::system::system_category()}; | ||
| #else | ||
| const boost::system::error_code ec {ETIMEDOUT, boost::system::system_category()}; | ||
| #endif | ||
| EXPECT_EQ(ec, boost::system::errc::timed_out); | ||
| } | ||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.