Skip to content

Commit

Permalink
Use NativeMemory in System.Data.Odbc
Browse files Browse the repository at this point in the history
  • Loading branch information
xtqqczze committed May 9, 2023
1 parent 7afd85d commit a99952d
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 47 deletions.

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -14,21 +14,12 @@ internal abstract class DbBuffer : SafeHandle
{
private readonly int _bufferLength;

protected DbBuffer(int initialSize) : base(IntPtr.Zero, true)
protected unsafe DbBuffer(int initialSize) : base(IntPtr.Zero, true)
{
if (0 < initialSize)
{
_bufferLength = initialSize;

try { }
finally
{
base.handle = SafeNativeMethods.LocalAlloc((IntPtr)initialSize);
}
if (IntPtr.Zero == base.handle)
{
throw new OutOfMemoryException();
}
base.handle = (IntPtr)NativeMemory.AllocZeroed((uint)initialSize);
}
}

Expand Down Expand Up @@ -368,15 +359,12 @@ internal unsafe float ReadSingle(int offset)
return BitConverter.Int32BitsToSingle(value);
}

protected override bool ReleaseHandle()
protected override unsafe bool ReleaseHandle()
{
// NOTE: The SafeHandle class guarantees this will be called exactly once.
IntPtr ptr = base.handle;
base.handle = IntPtr.Zero;
if (IntPtr.Zero != ptr)
{
SafeNativeMethods.LocalFree(ptr);
}
NativeMemory.Free((void*)ptr);
return true;
}

Expand Down Expand Up @@ -639,7 +627,7 @@ internal unsafe void WriteSingle(int offset, float value)
WriteInt32(offset, BitConverter.SingleToInt32Bits(value));
}

internal void ZeroMemory()
internal unsafe void ZeroMemory()
{
bool mustRelease = false;

Expand All @@ -648,7 +636,7 @@ internal void ZeroMemory()
DangerousAddRef(ref mustRelease);

IntPtr ptr = DangerousGetHandle();
SafeNativeMethods.ZeroMemory(ptr, Length);
NativeMemory.Clear((void*)ptr, (uint)Length);
}
finally
{
Expand Down
1 change: 0 additions & 1 deletion src/libraries/System.Data.Odbc/src/System.Data.Odbc.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,6 @@ System.Data.Odbc.OdbcTransaction</PackageDescription>
<Compile Include="$(CommonPath)System\Data\Common\NameValuePair.cs"
Link="Common\System\Data\Common\NameValuePair.cs" />
<Compile Include="Common\System\Data\Common\NameValuePermission.cs" />
<Compile Include="Common\System\Data\Common\SafeNativeMethods.cs" />
<Compile Include="Common\System\Data\DataStorage.cs" />
<Compile Include="Common\System\Data\ProviderBase\DbBuffer.cs" />
<Compile Include="$(CommonPath)System\Data\Common\FieldNameLookup.cs"
Expand Down

0 comments on commit a99952d

Please sign in to comment.