From 75c79bc2ee038a9ae99af4ecf8493c83c6cf26cb Mon Sep 17 00:00:00 2001 From: Camden Narzt Date: Mon, 18 Dec 2023 22:02:25 -0700 Subject: [PATCH] Revert "alias IntPtr to Pointer" This partially reverts commit 2871b30bb40658a23a9fe0ab1f5707c24b850f70. --- Getargv/Getargv.cs | 16 +++++++--------- 1 file changed, 7 insertions(+), 9 deletions(-) diff --git a/Getargv/Getargv.cs b/Getargv/Getargv.cs index b9dc16c..aaf3b4c 100644 --- a/Getargv/Getargv.cs +++ b/Getargv/Getargv.cs @@ -2,8 +2,6 @@ using System.Runtime.InteropServices; using System.Runtime.Versioning; -using Pointer = System.IntPtr; - namespace Getargv; [SupportedOSPlatform("macos")] @@ -89,10 +87,10 @@ public static byte[] asBytes(int pid, bool nuls = false, uint skip = 0) ArgvResult res = new ArgvResult(); if (get_argv_of_pid(in opt, out res)) { unsafe { - if ((Pointer)res.start_pointer == Pointer.Zero || (Pointer)res.end_pointer == Pointer.Zero || res.start_pointer == res.end_pointer) return Array.Empty(); + if ((IntPtr)res.start_pointer == IntPtr.Zero || (IntPtr)res.end_pointer == IntPtr.Zero || res.start_pointer == res.end_pointer) return Array.Empty(); var len = Convert.ToInt32(res.end_pointer - res.start_pointer + 1); byte[] ret = new byte[len]; - Marshal.Copy((Pointer)res.start_pointer, ret, 0, len); + Marshal.Copy((IntPtr)res.start_pointer, ret, 0, len); free_ArgvResult(ref res); return ret; } @@ -150,22 +148,22 @@ public static byte[][] asBytesArray(int pid) if (pid < 0 || pid > PID_MAX) throw new ArgumentOutOfRangeException($"pid {pid} out of range"); ArgvArgcResult res = new ArgvArgcResult(); if (get_argv_and_argc_of_pid(pid, out res)) { - int ptrSize = Marshal.SizeOf(typeof(Pointer)); + int ptrSize = Marshal.SizeOf(typeof(IntPtr)); int byteSize = Marshal.SizeOf(typeof(byte)); byte[][] ret = new byte[res.argc][]; for (uint i = 0; i < res.argc; i++) { unsafe { - byte* ptr = (byte*)Marshal.ReadIntPtr((Pointer)res.argv, ptrSize * (int)i); + byte* ptr = (byte*)Marshal.ReadIntPtr((IntPtr)res.argv, ptrSize * (int)i); ulong len = 0; if (i < res.argc-1) { - byte* nextptr = (byte*)Marshal.ReadIntPtr((Pointer)res.argv, ptrSize * ((int)i+1)); + byte* nextptr = (byte*)Marshal.ReadIntPtr((IntPtr)res.argv, ptrSize * ((int)i+1)); len = (ulong)((nextptr-ptr)/byteSize); } else { - while (Marshal.ReadByte((Pointer)ptr, (int)len) != 0){len++;} + while (Marshal.ReadByte((IntPtr)ptr, (int)len) != 0){len++;} len++;// len was index of nul, add one to get length of byte[] including nul } ret[i] = new byte[len]; - Marshal.Copy((Pointer)ptr, ret[i], 0, (int)len); + Marshal.Copy((IntPtr)ptr, ret[i], 0, (int)len); } } free_ArgvArgcResult(ref res);