Skip to content

Commit

Permalink
Support for x86 builds with Clang (#511)
Browse files Browse the repository at this point in the history
  • Loading branch information
kennykerr authored Feb 3, 2020
1 parent f092626 commit 78da673
Show file tree
Hide file tree
Showing 4 changed files with 50 additions and 54 deletions.
15 changes: 7 additions & 8 deletions strings/base_activation.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,12 @@ namespace winrt::impl

using library_handle = handle_type<library_traits>;

inline int32_t __stdcall fallback_RoGetActivationFactory(void*, guid const&, void** factory) noexcept
{
*factory = nullptr;
return error_class_not_available;
}

template <typename Interface>
hresult get_runtime_activation_factory(param::hstring const& name, void** result) noexcept
{
Expand All @@ -27,14 +33,7 @@ namespace winrt::impl
}

static int32_t(__stdcall * handler)(void* classId, guid const& iid, void** factory) noexcept;

impl::load_runtime_function("RoGetActivationFactory", handler,
[](void*, guid const&, void** factory) noexcept -> int32_t
{
*factory = nullptr;
return error_class_not_available;
});

impl::load_runtime_function("RoGetActivationFactory", handler, fallback_RoGetActivationFactory);
hresult hr = handler(*(void**)(&name), guid_of<Interface>(), result);

if (hr == impl::error_not_initialized)
Expand Down
45 changes: 22 additions & 23 deletions strings/base_agile_ref.h
Original file line number Diff line number Diff line change
Expand Up @@ -119,36 +119,35 @@ namespace winrt::impl
result = fallback;
}

inline hresult get_agile_reference(winrt::guid const& iid, void* object, void** reference) noexcept
inline int32_t __stdcall fallback_RoGetAgileReference(uint32_t, winrt::guid const& iid, void* object, void** reference) noexcept
{
static int32_t(__stdcall * handler)(uint32_t options, winrt::guid const& iid, void* object, void** reference) noexcept;

load_runtime_function("RoGetAgileReference", handler,
[](uint32_t, winrt::guid const& iid, void* object, void** reference) noexcept -> int32_t
{
*reference = nullptr;
static constexpr guid git_clsid{ 0x00000323, 0x0000, 0x0000, { 0xC0,0x00,0x00,0x00,0x00,0x00,0x00,0x46 } };
*reference = nullptr;
static constexpr guid git_clsid{ 0x00000323, 0x0000, 0x0000, { 0xC0,0x00,0x00,0x00,0x00,0x00,0x00,0x46 } };

com_ptr<IGlobalInterfaceTable> git;
hresult hr = WINRT_IMPL_CoCreateInstance(git_clsid, nullptr, 1 /*CLSCTX_INPROC_SERVER*/, guid_of<IGlobalInterfaceTable>(), git.put_void());
com_ptr<IGlobalInterfaceTable> git;
hresult hr = WINRT_IMPL_CoCreateInstance(git_clsid, nullptr, 1 /*CLSCTX_INPROC_SERVER*/, guid_of<IGlobalInterfaceTable>(), git.put_void());

if (hr < 0)
{
return hr;
}
if (hr < 0)
{
return hr;
}

uint32_t cookie{};
hr = git->RegisterInterfaceInGlobal(object, iid, &cookie);
uint32_t cookie{};
hr = git->RegisterInterfaceInGlobal(object, iid, &cookie);

if (hr < 0)
{
return hr;
}
if (hr < 0)
{
return hr;
}

*reference = new agile_ref_fallback(std::move(git), cookie);
return 0;
});
*reference = new agile_ref_fallback(std::move(git), cookie);
return 0;
}

inline hresult get_agile_reference(winrt::guid const& iid, void* object, void** reference) noexcept
{
static int32_t(__stdcall * handler)(uint32_t options, winrt::guid const& iid, void* object, void** reference) noexcept;
load_runtime_function("RoGetAgileReference", handler, fallback_RoGetAgileReference);
return handler(0, iid, object, reference);
}
}
Expand Down
31 changes: 15 additions & 16 deletions strings/base_error.h
Original file line number Diff line number Diff line change
Expand Up @@ -158,6 +158,11 @@ namespace winrt::impl
hstring const m_message;
atomic_ref_count m_references{ 1 };
};

[[noreturn]] inline void __stdcall fallback_RoFailFastWithErrorContext(int32_t) noexcept
{
std::terminate();
}
}

WINRT_EXPORT namespace winrt
Expand Down Expand Up @@ -289,19 +294,19 @@ WINRT_EXPORT namespace winrt

private:

static int32_t __stdcall fallback_RoOriginateLanguageException(int32_t error, void* message, void*) noexcept
{
com_ptr<impl::IErrorInfo> info(new (std::nothrow) impl::error_info_fallback(error, message), take_ownership_from_abi);
WINRT_VERIFY_(0, WINRT_IMPL_SetErrorInfo(0, info.get()));
return 1;
}

void originate(hresult const code, void* message) noexcept
{
static int32_t(__stdcall* handler)(int32_t error, void* message, void* exception) noexcept;

impl::load_runtime_function("RoOriginateLanguageException", handler,
[](int32_t error, void* message, void*) noexcept
{
com_ptr<impl::IErrorInfo> info(new (std::nothrow) impl::error_info_fallback(error, message), take_ownership_from_abi);
WINRT_VERIFY_(0, WINRT_IMPL_SetErrorInfo(0, info.get()));
return 1;
});

impl::load_runtime_function("RoOriginateLanguageException", handler, fallback_RoOriginateLanguageException);
WINRT_VERIFY(handler(code, message, nullptr));

com_ptr<impl::IErrorInfo> info;
WINRT_VERIFY_(0, WINRT_IMPL_GetErrorInfo(0, info.put_void()));
WINRT_VERIFY(info.try_as(m_info));
Expand Down Expand Up @@ -563,13 +568,7 @@ WINRT_EXPORT namespace winrt
inline void terminate() noexcept
{
static void(__stdcall * handler)(int32_t) noexcept;

impl::load_runtime_function("RoFailFastWithErrorContext", handler,
[](int32_t) noexcept
{
std::terminate();
});

impl::load_runtime_function("RoFailFastWithErrorContext", handler, impl::fallback_RoFailFastWithErrorContext);
handler(to_hresult());
}
}
13 changes: 6 additions & 7 deletions strings/base_events.h
Original file line number Diff line number Diff line change
Expand Up @@ -335,6 +335,11 @@ namespace winrt::impl
return { new(raw) event_array<T>(capacity), take_ownership_from_abi };
}

inline int32_t __stdcall fallback_RoTransformError(int32_t, int32_t, void*) noexcept
{
return 1;
}

template <typename Delegate, typename... Arg>
bool invoke(Delegate const& delegate, Arg const&... args) noexcept
{
Expand All @@ -347,13 +352,7 @@ namespace winrt::impl
int32_t const code = to_hresult();

static int32_t(__stdcall * handler)(int32_t, int32_t, void*) noexcept;

impl::load_runtime_function("RoTransformError", handler,
[](int32_t, int32_t, void*) noexcept
{
return 1;
});

impl::load_runtime_function("RoTransformError", handler, fallback_RoTransformError);
handler(code, 0, nullptr);

if (code == static_cast<int32_t>(0x80010108) || // RPC_E_DISCONNECTED
Expand Down

0 comments on commit 78da673

Please sign in to comment.