Skip to content
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
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
Next Next commit
Use NativeMemory in System.Data.Odbc
  • Loading branch information
xtqqczze committed May 9, 2023
commit a99952d7e73e1028e4c38489fa221e2106fd5ea7

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