Skip to content

Commit

Permalink
PtrToStringAnsi -> PtrToStringUTF8
Browse files Browse the repository at this point in the history
  • Loading branch information
mdrakiburrahman committed Oct 8, 2024
1 parent 968d53d commit cbe3a44
Show file tree
Hide file tree
Showing 5 changed files with 12 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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);
Expand Down
8 changes: 4 additions & 4 deletions src/DeltaLake/Kernel/Arrow/Handlers/ArrowFFIInterOpHandler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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 };
Expand Down Expand Up @@ -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
Expand All @@ -166,7 +166,7 @@ private static unsafe ParquetStringPartitions ParseParquetStringPartitions(
},
Marshal.GetFunctionPointerForDelegate<AllocateStringFn>(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))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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}"
);
Expand Down
2 changes: 1 addition & 1 deletion src/DeltaLake/Kernel/Callbacks/Errors/KernelReadError.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions src/DeltaLake/Kernel/Core/Table.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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
{
Expand Down Expand Up @@ -331,7 +331,7 @@ private List<string> 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."
)
Expand Down

0 comments on commit cbe3a44

Please sign in to comment.