-
Notifications
You must be signed in to change notification settings - Fork 7.6k
Move Windows pinvokes #18603
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
Move Windows pinvokes #18603
Conversation
I really don't mind the format that is ultimately used but it would be nice if there was a common standard set out by the pwsh team for PInvoke calls and how to structure them. I moved some of the WinTrust stuff in the PR #17545 and went with the format of
Here you've moved it to a single file per function and it's just the extern def. I'm totally not opposed to any route we ultimately go for but it would be nice to choose one rather than fragmenting it even more. |
I didn't realize it's organized as one file per function. Wouldn't that be too many files? |
The only inconvenience that many files might cause is if you tried to open them all at once in the editor. But why would you want to do that? |
An inconvenience off the top of my head is that it would be harder to search for something related to a p/invoke call, be it the use of a marshal attribute, a parameter type, or a function when you only remember partial of its name. I personally prefer to have only a few files dedicated to all p/invokes. In case that a lot of functions get used from a dll, like the WinTrust stuff, then use a single file for that dll. For the rest, use a single file per platform if possible. This doesn't prevent you from using partial classes for all p/invokes of a specific platform. |
How is a partial search related to number of files? VS Code has great and very fast multi file search (Ctrl-Shift-F). Given how unpredictable the location of code in PowerShell is sometimes, I seem to use it more often than the single-file search.
It's impossible to maintain any order in these files, especially since you're already talking about exceptions. These files are already unnecessarily huge. In fact, the code does not fit on one screen and you will anyway be forced to use search and possibly use additional editor windows even for the same file. |
Since @SteveL-MSFT agreed to adopt the .NET style for organizing the p/invokes in another PR, I will stop arguing for my personal preference. Just a side note, for existing code like WinTrust.cs, you may want to keep all those p/invoke in a single file. Splitting them into 1 file per function is lots of extra work, and also may be troublesome in case that some structs are shared by multiple functions. |
@daxian-dbw By the way, they sometimes put related pinvokes in the same file. The main convenience for the current work. |
cef6e8c
to
b761cce
Compare
b761cce
to
9b2d61f
Compare
9b2d61f
to
9b66360
Compare
03b9b22
to
db89486
Compare
This PR has Quantification details
Why proper sizing of changes matters
Optimal pull request sizes drive a better predictable PR flow as they strike a
What can I do to optimize my changes
How to interpret the change counts in git diff output
Was this comment helpful? 👍 :ok_hand: :thumbsdown: (Email) |
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.
LGTM
@daxian-dbw Could you merge? |
@iSazonov Thanks for doing this refactoring! |
🎉 Handy links: |
PR Summary
Please review commit by commit.
Contributes to #18553.
PR Context
PR Checklist
.h
,.cpp
,.cs
,.ps1
and.psm1
files have the correct copyright headerWIP:
or[ WIP ]
to the beginning of the title (theWIP
bot will keep its status check atPending
while the prefix is present) and remove the prefix when the PR is ready.(which runs in a different PS Host).