On Wed, 30 Mar 2022, LIU Hao wrote:

在 2022-03-30 16:51, Martin Storsjö 写道:
+__MINGW_SELECTANY void (WINAPI *__error_handler)(HRESULT hr,IErrorInfo *perrinfo) = _com_raise_error;
+
+inline void WINAPI _set_com_error_handler(void (WINAPI *pHandler)(HRESULT hr,IErrorInfo *perrinfo)) {
+  __error_handler = pHandler;
+}
+
+inline void WINAPI _com_issue_error(HRESULT hr) {
+  __error_handler(hr, NULL);
+}
+


I am afraid this could be auto-exported from DLLs unintentionally, in which case the name `__error_handler` is bad (`__com_error_handler` would be a better choice).

Thanks, that's indeed a very valid concern. Making the name less generic would certainly be good, but the symbol could still easily end up autoexported.

Would it be better to have these things in the CRT as they are not C++, instead of having a selectany symbol in the header?

While these functions don't seem to do anything much C++ specific, they still aren't within an 'extern "C" { .. }" block, so they do get C++ mangled and all that.

The selectany variable does need to point at _com_raise_error originally, and that function is very much C++ (as it throws an exception).

So overall, I don't think we can escape that these bits really are C++.


We could consider making a fullblown standalone libcomsupp.a. There, we could make the pointer variable static, and thus avoid the autoexport of it though. (But other statically linked functions, or inline functions from the comdef.h header, would still be autoexported, unless we add libcomsupp.a to binutils' list of libraries to exclude from autoimport.)

The other aspect about libcomsupp.a, as I mentioned, is that if we move _com_issue_error outside of the header and into a separate library, code which previously built fine now would break unless modified to explicitly add in -lcomsupp. Not sure how many such projects that would be though... Unless we'd add it to libmingwex.a of course, but that's kinda problematic as this is C++.

// Martin


_______________________________________________
Mingw-w64-public mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/mingw-w64-public

Reply via email to