Skip to content

Commit 21eb38c

Browse files
committed
Workaround access_token issue. More tests.
1 parent f9b0871 commit 21eb38c

File tree

5 files changed

+53
-24
lines changed

5 files changed

+53
-24
lines changed

strings/base_security.h

Lines changed: 29 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -69,31 +69,38 @@ WINRT_EXPORT namespace winrt
6969
check_bool(WINRT_IMPL_SetThreadToken(nullptr, get()));
7070
}
7171

72-
auto operator()() const
73-
{
74-
struct guard
75-
{
76-
guard(access_token&& previous) noexcept : m_previous(std::move(previous))
77-
{
78-
}
79-
80-
~guard()
81-
{
82-
m_previous.revert();
83-
}
84-
85-
guard(guard const&)
86-
{
87-
// A Visual C++ compiler bug (550631) requires the copy constructor even though it is never called.
88-
WINRT_ASSERT(false);
89-
}
72+
auto operator()() const;
73+
};
74+
}
9075

91-
private:
76+
WINRT_EXPORT namespace winrt
77+
{
78+
struct access_token_guard
79+
{
80+
access_token_guard(handle&& previous) noexcept : m_previous(std::move(previous))
81+
{
82+
}
9283

93-
access_token const m_previous;
94-
};
84+
~access_token_guard()
85+
{
86+
check_bool(WINRT_IMPL_SetThreadToken(nullptr, m_previous.get()));
87+
}
9588

96-
return guard(impersonate());
89+
access_token_guard(access_token_guard const&)
90+
{
91+
// A Visual C++ compiler bug (550631) requires the copy constructor even though it is never called.
92+
WINRT_ASSERT(false);
9793
}
94+
95+
private:
96+
// Work around modules bug that claims access_token is undefined/incomplete here.
97+
handle m_previous;
9898
};
99+
100+
inline auto access_token::operator()() const
101+
{
102+
auto previous = thread();
103+
check_bool(WINRT_IMPL_SetThreadToken(nullptr, get()));
104+
return access_token_guard(std::move(previous));
105+
}
99106
}

test/old_tests/UnitTests/Security.cpp

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,14 @@
1+
#ifndef WINRT_TEST_MODULES
12
#include "pch.h"
3+
#endif
24
#include "catch.hpp"
35

6+
#ifdef WINRT_TEST_MODULES
7+
#include <Windows.h>
8+
import std;
9+
import winrt;
10+
#endif
11+
412
using namespace winrt;
513
using namespace Windows::Foundation;
614

test/test/await_adapter.cpp

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,12 @@
1+
#ifdef WINRT_TEST_MODULES
2+
#include <catch.hpp>
3+
#include <Windows.h>
4+
import std;
5+
import winrt;
6+
#else
17
#include "pch.h"
28
#include "winrt/Windows.System.h"
9+
#endif
310

411
using namespace std::literals;
512
using namespace winrt;

test/test/coro_threadpool.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,12 @@
11
// Intentionally not using pch...
22
#include "catch.hpp"
33

4+
#ifdef WINRT_TEST_MODULES
5+
import winrt;
6+
#else
47
// Only need winrt/base.h for coroutine thread pool support.
58
#include "winrt/base.h"
9+
#endif
610

711
using namespace winrt;
812

test/test_cpp20_module/test_cpp20_module.vcxproj

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,7 @@
9999
<ItemDefinitionGroup>
100100
<ClCompile>
101101
<AdditionalIncludeDirectories>$(OutputPath);..\;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
102-
<PreprocessorDefinitions>NOMINMAX;WINRT_LEAN_AND_MEAN;WINRT_IMPORT_STD;%(PreprocessorDefinitions)</PreprocessorDefinitions>
102+
<PreprocessorDefinitions>NOMINMAX;WINRT_LEAN_AND_MEAN;WINRT_IMPORT_STD;WINRT_TEST_MODULES;%(PreprocessorDefinitions)</PreprocessorDefinitions>
103103
<PrecompiledHeader>NotUsing</PrecompiledHeader>
104104
<BuildStlModules>true</BuildStlModules>
105105
</ClCompile>
@@ -127,11 +127,14 @@
127127
</ItemDefinitionGroup>
128128
<ItemGroup>
129129
<ClCompile Include="$(OutDir)winrt\winrt.ixx" />
130+
<ClCompile Include="..\old_tests\UnitTests\Security.cpp" />
131+
<ClCompile Include="..\test\await_adapter.cpp" />
132+
<ClCompile Include="..\test\coro_threadpool.cpp" />
130133
<ClCompile Include="async.cpp" />
131134
<ClCompile Include="interop.cpp" />
132135
<ClCompile Include="main.cpp" />
133136
</ItemGroup>
134137
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
135138
<ImportGroup Label="ExtensionTargets">
136139
</ImportGroup>
137-
</Project>
140+
</Project>

0 commit comments

Comments
 (0)