From cbe3a4481f986de3e848f882f9d70ef629425553 Mon Sep 17 00:00:00 2001 From: Raki <46581776+mdrakiburrahman@users.noreply.github.com> Date: Mon, 7 Oct 2024 23:29:59 -0400 Subject: [PATCH] PtrToStringAnsi -> PtrToStringUTF8 --- .../Kernel/Arrow/Extensions/ArrowContextExtensions.cs | 8 ++++---- .../Kernel/Arrow/Handlers/ArrowFFIInterOpHandler.cs | 8 ++++---- .../Kernel/Callbacks/Errors/AllocateErrorCallbacks.cs | 2 +- src/DeltaLake/Kernel/Callbacks/Errors/KernelReadError.cs | 2 +- src/DeltaLake/Kernel/Core/Table.cs | 4 ++-- 5 files changed, 12 insertions(+), 12 deletions(-) diff --git a/src/DeltaLake/Kernel/Arrow/Extensions/ArrowContextExtensions.cs b/src/DeltaLake/Kernel/Arrow/Extensions/ArrowContextExtensions.cs index 027f51f..19e3fa5 100644 --- a/src/DeltaLake/Kernel/Arrow/Extensions/ArrowContextExtensions.cs +++ b/src/DeltaLake/Kernel/Arrow/Extensions/ArrowContextExtensions.cs @@ -146,8 +146,8 @@ private static unsafe Schema AddPartitionColumnsToSchema(Apache.Arrow.Schema ori for (int i = 0; i < partitionsPtr->Len; i++) { #pragma warning disable CS8600, CS8604 // If Kernel sends us back null pointers, we are in trouble anyway - string colName = Marshal.PtrToStringAnsi((IntPtr)partitionsPtr->ColNames[i]); - string colValue = Marshal.PtrToStringAnsi((IntPtr)partitionsPtr->ColValues[i]); + string colName = Marshal.PtrToStringUTF8((IntPtr)partitionsPtr->ColNames[i]); + string colValue = Marshal.PtrToStringUTF8((IntPtr)partitionsPtr->ColValues[i]); IArrowType dataType = DeterminePartitionColumnType(colName, colValue); #pragma warning restore CS8600, CS8604 @@ -179,8 +179,8 @@ private static unsafe RecordBatch AddPartitionColumnsToRecordBatch(RecordBatch r StringArray.Builder columnBuilder = new(); #pragma warning disable CS8600 - string colName = Marshal.PtrToStringAnsi((IntPtr)partitionsPtr->ColNames[i]); - string colValue = Marshal.PtrToStringAnsi((IntPtr)partitionsPtr->ColValues[i]); + string colName = Marshal.PtrToStringUTF8((IntPtr)partitionsPtr->ColNames[i]); + string colValue = Marshal.PtrToStringUTF8((IntPtr)partitionsPtr->ColValues[i]); #pragma warning restore CS8600 Field field = new(colName, StringType.Default, nullable: true); diff --git a/src/DeltaLake/Kernel/Arrow/Handlers/ArrowFFIInterOpHandler.cs b/src/DeltaLake/Kernel/Arrow/Handlers/ArrowFFIInterOpHandler.cs index ecea3fc..b3dabdd 100644 --- a/src/DeltaLake/Kernel/Arrow/Handlers/ArrowFFIInterOpHandler.cs +++ b/src/DeltaLake/Kernel/Arrow/Handlers/ArrowFFIInterOpHandler.cs @@ -96,9 +96,9 @@ KernelBoolSlice selectionVector ) { #pragma warning disable CS8600 - string tableRoot = Marshal.PtrToStringAnsi((IntPtr)context->TableRoot); + string tableRoot = Marshal.PtrToStringUTF8((IntPtr)context->TableRoot); #pragma warning restore CS8600 - string parquetAbsolutePath = $"{tableRoot}{Marshal.PtrToStringAnsi((IntPtr)path.ptr, (int)path.len)}"; + string parquetAbsolutePath = $"{tableRoot}{Marshal.PtrToStringUTF8((IntPtr)path.ptr, (int)path.len)}"; (GCHandle parquetAbsolutePathHandle, IntPtr gcPinnedParquetAbsolutePathPtr) = parquetAbsolutePath.ToPinnedSBytePointer(); KernelStringSlice parquetAbsolutePathSlice = new() { ptr = (sbyte*)gcPinnedParquetAbsolutePathPtr, len = (nuint)parquetAbsolutePath.Length }; @@ -146,7 +146,7 @@ private static unsafe ParquetStringPartitions ParseParquetStringPartitions( for (int i = 0; i < partitionCols->Len; i++) { #pragma warning disable CS8600 - string colName = Marshal.PtrToStringAnsi((IntPtr)partitionCols->Cols[i]); + string colName = Marshal.PtrToStringUTF8((IntPtr)partitionCols->Cols[i]); #pragma warning restore CS8600 // The Kernel can currently only report String values back as @@ -166,7 +166,7 @@ private static unsafe ParquetStringPartitions ParseParquetStringPartitions( }, Marshal.GetFunctionPointerForDelegate(StringAllocatorCallbacks.AllocateString) ); - string colVal = colValPtr != null ? Marshal.PtrToStringAnsi((IntPtr)colValPtr) : String.Empty; + string colVal = colValPtr != null ? Marshal.PtrToStringUTF8((IntPtr)colValPtr) : String.Empty; #pragma warning restore CS1024, CS8629, CS8600 if (!string.IsNullOrEmpty(colName) && !string.IsNullOrEmpty(colVal)) diff --git a/src/DeltaLake/Kernel/Callbacks/Errors/AllocateErrorCallbacks.cs b/src/DeltaLake/Kernel/Callbacks/Errors/AllocateErrorCallbacks.cs index 3fde0ec..407e6c4 100644 --- a/src/DeltaLake/Kernel/Callbacks/Errors/AllocateErrorCallbacks.cs +++ b/src/DeltaLake/Kernel/Callbacks/Errors/AllocateErrorCallbacks.cs @@ -31,7 +31,7 @@ internal class AllocateErrorCallbacks KernelStringSlice msg ) { - string message = Marshal.PtrToStringAnsi((IntPtr)msg.ptr) ?? string.Empty; + string message = Marshal.PtrToStringUTF8((IntPtr)msg.ptr) ?? string.Empty; throw new InvalidOperationException( $"Kernel engine error of type {etype} occurred with message: {message}" ); diff --git a/src/DeltaLake/Kernel/Callbacks/Errors/KernelReadError.cs b/src/DeltaLake/Kernel/Callbacks/Errors/KernelReadError.cs index b3eb571..2c1c247 100644 --- a/src/DeltaLake/Kernel/Callbacks/Errors/KernelReadError.cs +++ b/src/DeltaLake/Kernel/Callbacks/Errors/KernelReadError.cs @@ -26,7 +26,7 @@ internal struct KernelReadError #pragma warning disable CS8603, IDE0251 // Possible pointer null reference return is possible when we work with Kernel if the Kernel has a bug public string Message { - get => Marshal.PtrToStringAnsi(msg); + get => Marshal.PtrToStringUTF8(msg); set => msg = Marshal.StringToHGlobalAnsi(value); } #pragma warning restore CS8603, IDE0251 diff --git a/src/DeltaLake/Kernel/Core/Table.cs b/src/DeltaLake/Kernel/Core/Table.cs index 47f6ef5..6d0a8fb 100644 --- a/src/DeltaLake/Kernel/Core/Table.cs +++ b/src/DeltaLake/Kernel/Core/Table.cs @@ -237,7 +237,7 @@ internal override string Uri() // Kernel returns an extra "/", delta-rs does not // - return Marshal.PtrToStringAnsi(tableRootPtr)?.TrimEnd('/') ?? string.Empty; + return Marshal.PtrToStringUTF8(tableRootPtr)?.TrimEnd('/') ?? string.Empty; } finally { @@ -331,7 +331,7 @@ private List PartitionColumns() for (int i = 0; i < numPartitions; i++) { partitionColumns.Add( - Marshal.PtrToStringAnsi((IntPtr)managedPartitionListPtr->Cols[i]) + Marshal.PtrToStringUTF8((IntPtr)managedPartitionListPtr->Cols[i]) ?? throw new InvalidOperationException( $"Delta Kernel returned a null partition column name despite reporting {numPartitions} > 0 partition(s) exist." )