Thanks to visit codestin.com
Credit goes to github.com

Skip to content
Merged
Changes from 1 commit
Commits
Show all changes
19 commits
Select commit Hold shift + click to select a range
9d8e214
Revert 1af7327454f9cafbf3aaaa8b3d615489aad480ab
mdaigle Aug 5, 2025
4763951
Revert "Fix TryReadPlpBytes throws ArgumentException (#3470) (#3474)"
mdaigle Aug 5, 2025
93a86d0
Revert 44762d90913ac93ffd78f58a0d87e59cf3d65a43
mdaigle Aug 5, 2025
2c83dc9
Revert "Improve async string perf and fix reading chars with initial …
mdaigle Aug 5, 2025
37db170
Revert "Refine handling of moving between replay and continue states …
mdaigle Aug 5, 2025
0d2807f
Revert "Fix SqlCached buffer async read with continue edge case. (#33…
mdaigle Aug 5, 2025
7fb7041
Revert "Add `async` snapshot continue capability for multipacket fiel…
mdaigle Aug 5, 2025
006cd12
Revert "Add partial packet detection and fixup (#2714)"
mdaigle Aug 6, 2025
40c19a6
Remove methods previously moved to common file.
mdaigle Aug 6, 2025
6cea8df
Supply byte buffer to vector read.
mdaigle Aug 6, 2025
11d3b43
Minor compilation fixes that were missed in the reverts.
mdaigle Aug 6, 2025
f6691f4
Remove partial packet context switch helpers.
mdaigle Aug 6, 2025
6944ab6
Remove accidental duplication of SqlDataReader
mdaigle Aug 8, 2025
1ac8090
Revert len change
mdaigle Aug 11, 2025
a4ac40a
Undo buff rental in netfx to simplify 6.0 diff.
mdaigle Aug 11, 2025
73a3a19
Fix missed rented buff code.
mdaigle Aug 11, 2025
865b774
Merge branch 'release/6.1' of github.com:dotnet/SqlClient into dev/md…
mdaigle Aug 12, 2025
089e72c
Merge branch 'release/6.1' into dev/mdaigle/revert-partial-packet
cheenamalhotra Aug 13, 2025
9a6817f
Merge branch 'release/6.1' of github.com:dotnet/SqlClient into dev/md…
mdaigle Aug 13, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Undo buff rental in netfx to simplify 6.0 diff.
  • Loading branch information
mdaigle committed Aug 11, 2025
commit a4ac40a5f628dd334bf2f3b8b971a6773e79a833
Original file line number Diff line number Diff line change
Expand Up @@ -6220,35 +6220,19 @@ private TdsOperationStatus TryReadSqlStringValue(SqlBuffer value, byte type, int
if (isPlp)
{
char[] cc = null;
bool buffIsRented = false;
result = TryReadPlpUnicodeChars(ref cc, 0, length >> 1, stateObj, out length, supportRentedBuff: true, rentedBuff: ref buffIsRented);
result = TryReadPlpUnicodeChars(ref cc, 0, length >> 1, stateObj, out length);

if (result == TdsOperationStatus.Done)
if (result != TdsOperationStatus.Done)
{
if (length > 0)
{
s = new string(cc, 0, length);
}
else
{
s = string.Empty;
}
return result;
}

if (buffIsRented)
if (length > 0)
{
// do not use clearArray:true on the rented array because it can be massively larger
// than the space we've used and we would incur performance clearing memory that
// we haven't used and can't leak out information.
// clear only the length that we know we have used.
cc.AsSpan(0, length).Clear();
ArrayPool<char>.Shared.Return(cc, clearArray: false);
cc = null;
s = new string(cc, 0, length);
}

if (result != TdsOperationStatus.Done)
else
{
return result;
s = string.Empty;
}
}
else
Expand Down Expand Up @@ -13270,13 +13254,12 @@ internal TdsOperationStatus TryReadPlpUnicodeChars(
int offst,
int len,
TdsParserStateObject stateObj,
out int totalCharsRead,
bool supportRentedBuff,
ref bool rentedBuff)
out int totalCharsRead)
{
int charsRead = 0;
int charsLeft = 0;
char[] newbuf;
TdsOperationStatus result;

if (stateObj._longlen == 0)
{
Expand All @@ -13285,29 +13268,18 @@ internal TdsOperationStatus TryReadPlpUnicodeChars(
return TdsOperationStatus.Done; // No data
}

Debug.Assert((ulong)stateObj._longlen != TdsEnums.SQL_PLP_NULL, "Out of sync plp read request");
Debug.Assert(((ulong)stateObj._longlen != TdsEnums.SQL_PLP_NULL),
"Out of sync plp read request");

Debug.Assert((buff == null && offst == 0) || (buff.Length >= offst + len), "Invalid length sent to ReadPlpUnicodeChars()!");
charsLeft = len;

// If total length is known up front, the length isn't specified as unknown
// and the caller doesn't pass int.max/2 indicating that it doesn't know the length
// allocate the whole buffer in one shot instead of realloc'ing and copying over each time
if (buff == null && stateObj._longlen != TdsEnums.SQL_PLP_UNKNOWNLEN && len < (int.MaxValue >> 1))
// If total length is known up front, allocate the whole buffer in one shot instead of realloc'ing and copying over each time
if (buff == null && stateObj._longlen != TdsEnums.SQL_PLP_UNKNOWNLEN)
{
if (supportRentedBuff && len < 1073741824) // 1 Gib
{
buff = ArrayPool<char>.Shared.Rent((int)Math.Min((int)stateObj._longlen, len));
rentedBuff = true;
}
else
{
buff = new char[(int)Math.Min((int)stateObj._longlen, len)];
rentedBuff = false;
}
buff = new char[(int)Math.Min((int)stateObj._longlen, len)];
}

TdsOperationStatus result;
if (stateObj._longlenleft == 0)
{
result = stateObj.TryReadPlpLength(false, out _);
Expand All @@ -13329,26 +13301,11 @@ internal TdsOperationStatus TryReadPlpUnicodeChars(
charsRead = (int)Math.Min((stateObj._longlenleft + 1) >> 1, (ulong)charsLeft);
if ((buff == null) || (buff.Length < (offst + charsRead)))
{
bool returnRentedBufferAfterCopy = rentedBuff;
if (supportRentedBuff && (offst + charsRead) < 1073741824) // 1 Gib
{
newbuf = ArrayPool<char>.Shared.Rent(offst + charsRead);
rentedBuff = true;
}
else
{
newbuf = new char[offst + charsRead];
rentedBuff = false;
}

// Grow the array
newbuf = new char[offst + charsRead];
if (buff != null)
{
Buffer.BlockCopy(buff, 0, newbuf, 0, offst * 2);
if (returnRentedBufferAfterCopy)
{
buff.AsSpan(0, offst).Clear();
ArrayPool<char>.Shared.Return(buff, clearArray: false);
}
}
buff = newbuf;
}
Expand Down
Loading