Skip to content
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

Replace custom path handling in MRT #908

Merged
merged 3 commits into from
Jun 4, 2021
Merged

Conversation

huichen123
Copy link
Contributor

also removed custom build configurations in mrt build task.

DWORD lastError = GetLastError();
std::unique_ptr<wchar_t[]> pathAllocated;
wil::unique_cotaskmem_string path;
RETURN_IF_FAILED((wil::GetModuleFileNameW<wil::unique_cotaskmem_string, 256>(nullptr, path)));
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You can leave off the , 256 parameter and then remove the additional ( ) on this.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

256 is what i want to override. the default is 128. Many times, the path created by the reunion template is fairly long. Thus i want to bump up the default.

}
pointerToPath++;
}
PCWSTR name = wil::find_last_path_segment(path.get());
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should this use the std::filesystem APIs instead?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The file contains no-throwing code only. with std, i am going to worry about whether it throws, and std::filesystem API does throw.

DWORD lastError = GetLastError();
std::unique_ptr<wchar_t[]> pathAllocated;
wil::unique_cotaskmem_string path;
RETURN_IF_FAILED((wil::GetModuleFileNameW<wil::unique_cotaskmem_string, 256>(nullptr, path)));
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Isn't it better to use MAX_PATH instead of 256 here? MAX_PATH may be greater than 256 after a user modification, no?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

256 is just twice of the default (128). Some people may just don't like MAX_PATH. I doubt anyone is going to modify MAX_PATH. If it does, that's just one more reason to not use MAX_PATH.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You're trading codebase readability for a perceived micro-optimization. Other folks coming across this code are going to scratch their heads as to why the initial buffer size was not used here. Something to consider.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's better to use no number here. WIL always produces a heap-allocated string from this method, and the buffer parameter is just a seed to know where to start growing the buffer. Just don't specify, let WIL do its thing, then there's no Mysterious Constant hanging out here. (Mysterious Constants in library implementations are fine.)

pointerToPath++;
}
PCWSTR name = wil::find_last_path_segment(path.get());
wchar_t moduleFilename[MAX_PATH];
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

883-884 can go into the "// Prep for the second iteration" if block where if name is empty/null, we just break. We can avoid the unnecessary setting of module name to path and then a second iteration.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

at that time, path is already modified, and lost the name.

@huichen123
Copy link
Contributor Author

/azp run

@azure-pipelines
Copy link

Azure Pipelines successfully started running 1 pipeline(s).

@huichen123 huichen123 merged commit c1653e8 into main Jun 4, 2021
@huichen123 huichen123 deleted the user/huichen/pathparse branch June 4, 2021 17:05
DrusTheAxe pushed a commit that referenced this pull request Jun 14, 2021
* Replace custom path handling

* use default size
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants