-
Notifications
You must be signed in to change notification settings - Fork 263
Avoid LoadLibraryExW
#1414
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
Closed
Closed
Avoid LoadLibraryExW
#1414
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
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
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 |
|---|---|---|
| @@ -1,5 +1,6 @@ | ||
| #pragma once | ||
|
|
||
| #define WINRT_REG_FREE | ||
| #include "catch.hpp" | ||
| #include "winrt/Windows.Foundation.Collections.h" | ||
|
|
||
|
|
||
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 |
|---|---|---|
| @@ -1,5 +1,6 @@ | ||
| #pragma once | ||
|
|
||
| #define WINRT_REG_FREE | ||
| #include "catch.hpp" | ||
| #include "winrt/Windows.Foundation.Collections.h" | ||
|
|
||
|
|
||
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you add ODR checks for this define? If it mismatches then it will be undefined behavior whether you get regfree or not.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Feel free to push a contribution. That's not something I've ever played with. 😊
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm catching up after more than a week OOF so I have very limited time today. That's the diff that detects the mismatch. The test projects have several build breaks when this is enforced because they are not consistent. I don't have time today to follow up and fix them all. I'm not going to push a build break so that will have to wait. Or you are welcome to fix it up first if you have time :).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Here's an example of the breaks:
Error LNK2038 mismatch detected for 'WINRT_REG_FREE': value 'false' doesn't match value 'true' in Composition.obj test_slow V:\T\cppwinrt\test\test_slow\main.obj 1There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sweet thanks, I'll take a look.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If you don't have the linker errors then you won't have confidence that this define is having an effect (or is missing). Every translation unit will have a potentially different version of this function. The linker will choose one unpredicatbly. Does it have regfree? Does it not? Who knows?! It might even change the next time you add a new cpp file to your project.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The OS should likely default to "not regfree" - I'm not aware of any outliers that want it.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
External users would most likely prefer reg-free, because consuming libraries like Win2D can be a painful endeavour for less experienced users otherwise (knowing why you get class not registered and what the solution is, is less than obvious to even knowledgeable users sometimes).
I would suggest making this opt out rather than opt in, especially since the existing published versions use reg-free, otherwise we should expect some amount of "class not registered after upgrading cppwinrt" tickets.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could these specific examples be because the main.cpp doesn't include the PCH? Defining this macro at the VS project level rather than in the PCH might be the ideal move here.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sure, it's easy enough to fix this build. The bigger question is harder to answer. The options are:
WINRT_REG_FREEWINRT_NO_REG_FREEThere are pros and cons to all of them. I think option 3 is good enough - and secure enough thanks to #1293 - and is certainly far less problematic from a compatibility point of view. I also don't want to add to the growing set of compatibility issues that someone will have to deal with when trying to update a large code base like Windows. This does serve as another good example of how hard it is to update a C++ library. Rust for examples does not have this problem since source code is not the unit of integration.
@dmachaj, @oldnewthing, and I have had a bit of an offline discussion with different perspectives. I'm not personally invested in the outcome as I'm not the customer here, so I'll leave this here as an example and let someone who is more invested in the outcome take it from here.