Drop redundant fixed in HttpSys SetDataChunkWithPinnedData#66578
Open
unsafePtr wants to merge 1 commit intodotnet:mainfrom
Open
Drop redundant fixed in HttpSys SetDataChunkWithPinnedData#66578unsafePtr wants to merge 1 commit intodotnet:mainfrom
unsafePtr wants to merge 1 commit intodotnet:mainfrom
Conversation
Contributor
|
Thanks for your PR, @unsafePtr. Someone from the team will get assigned to your PR shortly and we'll get it reviewed. |
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Description
Drops the
fixed (byte* ptr = bytes)block from the twoSetDataChunkWithPinnedDatahelpers in HttpSys. The pin was redundant: the implementation capturesptrintochunk.pBufferfor HTTP.SYS to read later, so thefixedscope ends before the value is consumed. Safety always relied on the caller keeping the data alive, not thefixedblock — the helper's name reflects that contract.All 5 call sites verified
ResponseBody.cs:196,:248,:252Helpers.ChunkTerminator/CRLF"...\r\n..."u8— embedded in assembly RVA section, never movedResponseBody.cs:275handle.AddrOfPinnedObject() + offsetGCHandle.Alloc(..., Pinned), freed byFreeDataBuffersResponseStreamAsyncResult.cs:70,:134Helpers.CRLFUTF-8 literals (
"..."u8) live in assembly metadata, not on the GC heap. The GCHandle-pinned site keeps the buffer alive for the lifetime of the chunk's use.Behavior preservation
fixed (byte* ptr = bytes)returnsnullwhenbytes.IsEmpty, regardless of how the span was constructed.MemoryMarshal.GetReference(bytes)does not — per its documentation, for an empty span built from a non-null pointer (e.g. a zero-lengthArraySegmentof a GCHandle-pinned array) it returns a non-null ref. Thebytes.IsEmpty ? null : ...guard preserves the original null-on-empty semantic.Consistency with existing code
ResponseStreamAsyncResult.cs:80already uses the equivalent pattern for an externally-pinned array —(void*)Marshal.UnsafeAddrOfPinnedArrayElement(...)with nofixedblock. The two helpers were the outliers in this file. This change aligns them with that neighboring pattern.No behavior change at runtime; pure cleanup.