Skip to content

Commit c149786

Browse files
Copilotjkotas
andcommitted
Revert Utf8StringMarshaller.cs changes and replace remaining Marshal.PtrToStringUTF8 calls
Co-authored-by: jkotas <6668460+jkotas@users.noreply.github.com>
1 parent 136c6d1 commit c149786

File tree

18 files changed

+49
-78
lines changed

18 files changed

+49
-78
lines changed

src/coreclr/System.Private.CoreLib/src/System/GC.CoreCLR.cs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
using System.Runtime.CompilerServices;
1313
using System.Runtime.ExceptionServices;
1414
using System.Runtime.InteropServices;
15+
using System.Runtime.InteropServices.Marshalling;
1516
using System.Runtime.Versioning;
1617
using System.Threading;
1718

@@ -886,7 +887,7 @@ private static unsafe void ConfigCallback(void* configurationContext, void* name
886887
Debug.Assert(context.Configurations != null);
887888
Dictionary<string, object> configurationDictionary = context.Configurations!;
888889

889-
string nameAsString = Marshal.PtrToStringUTF8((IntPtr)name)!;
890+
string nameAsString = Utf8StringMarshaller.ConvertToManaged((IntPtr)name)!;
890891
switch (type)
891892
{
892893
case GCConfigurationType.Int64:
@@ -895,7 +896,7 @@ private static unsafe void ConfigCallback(void* configurationContext, void* name
895896

896897
case GCConfigurationType.StringUtf8:
897898
{
898-
string? dataAsString = Marshal.PtrToStringUTF8((nint)data);
899+
string? dataAsString = Utf8StringMarshaller.ConvertToManaged((IntPtr)data);
899900
configurationDictionary[nameAsString] = dataAsString ?? string.Empty;
900901
break;
901902
}

src/libraries/Common/src/Interop/Android/System.Security.Cryptography.Native.Android/Interop.Err.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
using System;
55
using System.Diagnostics;
66
using System.Runtime.InteropServices;
7+
using System.Runtime.InteropServices.Marshalling;
78
using System.Security.Cryptography;
89

910
internal static partial class Interop
@@ -34,7 +35,7 @@ private static unsafe string ErrErrorStringN(ulong error)
3435
fixed (byte* buf = &buffer[0])
3536
{
3637
ErrErrorStringN(error, buf, buffer.Length);
37-
return Marshal.PtrToStringUTF8((IntPtr)buf)!;
38+
return Utf8StringMarshaller.ConvertToManaged((IntPtr)buf)!;
3839
}
3940
}
4041

src/libraries/Common/src/Interop/FreeBSD/Interop.Process.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
using System.ComponentModel;
77
using System.Diagnostics;
88
using System.Runtime.InteropServices;
9+
using System.Runtime.InteropServices.Marshalling;
910

1011
#pragma warning disable CA1823 // analyzer incorrectly flags fixed buffer length const (https://github.com/dotnet/roslyn/issues/37593)
1112

@@ -117,7 +118,7 @@ public static unsafe ProcessInfo GetProcessInfoById(int pid)
117118
// Get the process information for the specified pid
118119
info = new ProcessInfo();
119120

120-
info.ProcessName = Marshal.PtrToStringUTF8((IntPtr)kinfo->ki_comm)!;
121+
info.ProcessName = Utf8StringMarshaller.ConvertToManaged((IntPtr)kinfo->ki_comm)!;
121122
info.BasePriority = kinfo->ki_nice;
122123
info.VirtualBytes = (long)kinfo->ki_size;
123124
info.WorkingSet = kinfo->ki_rssize;

src/libraries/Common/src/Interop/OSX/Interop.CoreFoundation.CFString.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
using System;
55
using System.Diagnostics;
66
using System.Runtime.InteropServices;
7+
using System.Runtime.InteropServices.Marshalling;
78
using System.Text;
89
using Microsoft.Win32.SafeHandles;
910

@@ -42,7 +43,7 @@ internal static string CFStringToString(SafeCFStringHandle cfString)
4243

4344
if (interiorPointer != IntPtr.Zero)
4445
{
45-
return Marshal.PtrToStringUTF8(interiorPointer)!;
46+
return Utf8StringMarshaller.ConvertToManaged(interiorPointer)!;
4647
}
4748

4849
SafeCFDataHandle cfData = CFStringCreateExternalRepresentation(

src/libraries/Common/src/Interop/Unix/System.Native/Interop.MountPoints.FormatInfo.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
using System;
55
using System.IO;
66
using System.Runtime.InteropServices;
7+
using System.Runtime.InteropServices.Marshalling;
78

89
internal static partial class Interop
910
{
@@ -59,7 +60,7 @@ internal static unsafe Error GetFileSystemTypeNameForMountPoint(string name, out
5960
int result = GetFileSystemTypeNameForMountPoint(name, formatBuffer, MountPointFormatBufferSizeInBytes, &formatType);
6061
if (result == 0)
6162
{
62-
format = formatType == -1 ? Marshal.PtrToStringUTF8((IntPtr)formatBuffer)!
63+
format = formatType == -1 ? Utf8StringMarshaller.ConvertToManaged((IntPtr)formatBuffer)!
6364
: (Enum.GetName(typeof(UnixFileSystemTypes), formatType) ?? "");
6465
return Error.SUCCESS;
6566
}

src/libraries/Common/src/Interop/Unix/System.Native/Interop.MountPoints.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
using System.Runtime.CompilerServices;
88
using System.Runtime.ExceptionServices;
99
using System.Runtime.InteropServices;
10+
using System.Runtime.InteropServices.Marshalling;
1011

1112
internal static partial class Interop
1213
{
@@ -27,7 +28,7 @@ private static unsafe void AddMountPoint(void* context, byte* name)
2728
AllMountPointsContext* callbackContext = (AllMountPointsContext*)context;
2829
try
2930
{
30-
callbackContext->_results.Add(Marshal.PtrToStringUTF8((IntPtr)name)!);
31+
callbackContext->_results.Add(Utf8StringMarshaller.ConvertToManaged((IntPtr)name)!);
3132
}
3233
catch (Exception e)
3334
{

src/libraries/Common/src/Interop/Unix/System.Net.Security.Native/Interop.GssApiException.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
using System.Collections.Generic;
66
using System.Diagnostics;
77
using System.Runtime.InteropServices;
8+
using System.Runtime.InteropServices.Marshalling;
89

910
internal static partial class Interop
1011
{
@@ -85,7 +86,7 @@ private static string GetGssApiDisplayStatus(Status majorStatus, Status minorSta
8586
Interop.NetSecurityNative.Status displayCallStatus = isMinor ?
8687
DisplayMinorStatus(out minStat, status, ref displayBuffer) :
8788
DisplayMajorStatus(out minStat, status, ref displayBuffer);
88-
return (Status.GSS_S_COMPLETE != displayCallStatus) ? null : Marshal.PtrToStringUTF8(displayBuffer._data);
89+
return (Status.GSS_S_COMPLETE != displayCallStatus) ? null : Utf8StringMarshaller.ConvertToManaged(displayBuffer._data);
8990
}
9091
finally
9192
{

src/libraries/Common/src/Interop/Unix/System.Security.Cryptography.Native/Interop.Ssl.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -330,7 +330,7 @@ internal static bool AddExtraChainCertificates(SafeSslHandle ssl, ReadOnlyCollec
330330

331331
internal static string? GetOpenSslCipherSuiteName(SafeSslHandle ssl, TlsCipherSuite cipherSuite, out bool isTls12OrLower)
332332
{
333-
string? ret = Marshal.PtrToStringUTF8(GetOpenSslCipherSuiteName(ssl, (int)cipherSuite, out int isTls12OrLowerInt));
333+
string? ret = Utf8StringMarshaller.ConvertToManaged(GetOpenSslCipherSuiteName(ssl, (int)cipherSuite, out int isTls12OrLowerInt));
334334
isTls12OrLower = isTls12OrLowerInt != 0;
335335
return ret;
336336
}

src/libraries/Common/src/Interop/Unix/System.Security.Cryptography.Native/Interop.SslCtx.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
using System.Diagnostics;
99
using System.Net.Security;
1010
using System.Runtime.InteropServices;
11+
using System.Runtime.InteropServices.Marshalling;
1112
using System.Security.Cryptography.X509Certificates;
1213
using System.Text;
1314
using System.Threading;
@@ -219,7 +220,7 @@ internal void RemoveSession(IntPtr namePtr, IntPtr session)
219220
{
220221
Debug.Assert(_sslSessions != null);
221222

222-
string? targetName = Marshal.PtrToStringUTF8(namePtr);
223+
string? targetName = Utf8StringMarshaller.ConvertToManaged(namePtr);
223224
Debug.Assert(targetName != null);
224225

225226
if (_sslSessions != null && targetName != null)

src/libraries/Common/src/Interop/Unix/System.Security.Cryptography.Native/Interop.X509.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
using System;
55
using System.Diagnostics.CodeAnalysis;
66
using System.Runtime.InteropServices;
7+
using System.Runtime.InteropServices.Marshalling;
78
using System.Security.Cryptography;
89
using System.Security.Cryptography.X509Certificates;
910
using Microsoft.Win32.SafeHandles;
@@ -252,7 +253,7 @@ internal static unsafe void X509StoreCtxSetVerifyCallback(SafeX509StoreCtxHandle
252253

253254
internal static string GetX509VerifyCertErrorString(int n)
254255
{
255-
return Marshal.PtrToStringUTF8(CryptoNative_X509VerifyCertErrorString(n))!;
256+
return Utf8StringMarshaller.ConvertToManaged(CryptoNative_X509VerifyCertErrorString(n))!;
256257
}
257258

258259
[LibraryImport(Libraries.CryptoNative)]

0 commit comments

Comments
 (0)