Skip to content

Commit

Permalink
The tests discovered a real bug. The WINRT_IMPL_SHIM macro only keeps…
Browse files Browse the repository at this point in the history
… the temporary alive until the semicolon. Remove that macro from where I need to call the check method to fix this crash
  • Loading branch information
dmachaj committed Oct 29, 2024
1 parent 83c846b commit 4a1dd03
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 10 deletions.
22 changes: 13 additions & 9 deletions cppwinrt/code_writers.h
Original file line number Diff line number Diff line change
Expand Up @@ -1131,19 +1131,21 @@ namespace cppwinrt
// we intentionally ignore errors when unregistering event handlers to be consistent with event_revoker
format = R"( template <typename D%> auto consume_%<D%>::%(%) const noexcept
{%
const auto castedResult = WINRT_IMPL_SHIM(%);
check_cast_result(castedResult);
castedResult->%(%);%
const auto castedResult = static_cast<% const&>(static_cast<D const&>(*this));
const auto abiType = *(abi_t<%>**)&castedResult;
check_cast_result(abiType);
abiType->%(%);%
}
)";
}
else
{
format = R"( template <typename D%> auto consume_%<D%>::%(%) const noexcept
{%
const auto castedResult = WINRT_IMPL_SHIM(%);
check_cast_result(castedResult);
WINRT_VERIFY_(0, castedResult->%(%));%
const auto castedResult = static_cast<% const&>(static_cast<D const&>(*this));
const auto abiType = *(abi_t<%>**)&castedResult;
check_cast_result(abiType);
WINRT_VERIFY_(0, abiType->%(%));%
}
)";
}
Expand All @@ -1152,9 +1154,10 @@ namespace cppwinrt
{
format = R"( template <typename D%> auto consume_%<D%>::%(%) const
{%
const auto castedResult = WINRT_IMPL_SHIM(%);
check_cast_result(castedResult);
check_hresult(castedResult->%(%));%
const auto castedResult = static_cast<% const&>(static_cast<D const&>(*this));
const auto abiType = *(abi_t<%>**)&castedResult;
check_cast_result(abiType);
check_hresult(abiType->%(%));%
}
)";
}
Expand All @@ -1167,6 +1170,7 @@ namespace cppwinrt
bind<write_consume_params>(signature),
bind<write_consume_return_type>(signature, false),
type,
type,
get_abi_name(method),
bind<write_abi_args>(signature),
bind<write_consume_return_statement>(signature));
Expand Down
2 changes: 1 addition & 1 deletion strings/base_error.h
Original file line number Diff line number Diff line change
Expand Up @@ -530,7 +530,7 @@ WINRT_EXPORT namespace winrt
}

template <typename T>
WINRT_IMPL_NOINLINE void check_cast_result(T const& from WINRT_IMPL_SOURCE_LOCATION_ARGS)
WINRT_IMPL_NOINLINE void check_cast_result(T* from WINRT_IMPL_SOURCE_LOCATION_ARGS)
{
if (!from)
{
Expand Down

0 comments on commit 4a1dd03

Please sign in to comment.