-
-
Notifications
You must be signed in to change notification settings - Fork 2.4k
Code Quality: Introduced ComPtr for unmanaged COM pointers #16151
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
Changes from 6 commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
5e0acff
Init
0x5bfa 383412e
Remove bom from text files
0x5bfa a5e511d
update
0x5bfa 9e09bb2
Update Files.sln
0x5bfa ce15c04
Update Files.sln
0x5bfa 9897e54
Merge branch '5bfa/CQ-ComPtr' of https://github.com/0x5bfa/Files into…
0x5bfa cdc4231
Update Files.Core.SourceGenerator.csproj
0x5bfa 3343d51
Update src/Files.Core.SourceGenerator/Windows.Win32/Windows.Win32.Com…
0x5bfa f42c08f
Update ParserItem.cs
0x5bfa 673626b
Update Files.Core.SourceGenerator.csproj
0x5bfa ac9354a
Update ParserItem.cs
0x5bfa 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 was deleted.
Oops, something went wrong.
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
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
52 changes: 52 additions & 0 deletions
52
src/Files.Core.SourceGenerator/Windows.Win32/Windows.Win32.ComPtr.cs
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 |
---|---|---|
@@ -0,0 +1,52 @@ | ||
// Copyright (c) 2024 Files Community | ||
// Licensed under the MIT License. See the LICENSE. | ||
|
||
using System; | ||
using System.Runtime.CompilerServices; | ||
using Windows.Win32; | ||
using Windows.Win32.System.Com; | ||
|
||
namespace Windows.Win32 | ||
{ | ||
/// <summary> | ||
/// Contains a COM pointer and a set of methods to work with the pointer safely. | ||
/// </summary> | ||
public unsafe struct ComPtr<T> : IDisposable where T : unmanaged | ||
{ | ||
private T* _ptr; | ||
|
||
public bool IsNull | ||
=> _ptr == default; | ||
|
||
public ComPtr(T* ptr) | ||
{ | ||
_ptr = ptr; | ||
|
||
if (ptr is not null) | ||
((IUnknown*)ptr)->AddRef(); | ||
} | ||
|
||
[MethodImpl(MethodImplOptions.AggressiveInlining)] | ||
public readonly T* Get() | ||
{ | ||
return _ptr; | ||
} | ||
|
||
[MethodImpl(MethodImplOptions.AggressiveInlining)] | ||
public readonly T** GetAddressOf() | ||
{ | ||
return (T**)Unsafe.AsPointer(ref Unsafe.AsRef(in this)); | ||
} | ||
|
||
[MethodImpl(MethodImplOptions.AggressiveInlining)] | ||
public void Dispose() | ||
{ | ||
T* ptr = _ptr; | ||
if (ptr is not null) | ||
{ | ||
_ptr = null; | ||
((IUnknown*)pointer)->Release(); | ||
} | ||
} | ||
} | ||
} |
File renamed without changes.
Oops, something went wrong.
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.
Uh oh!
There was an error while loading. Please reload this page.