Skip to content

Commit

Permalink
Revert "alias IntPtr to Pointer"
Browse files Browse the repository at this point in the history
This partially reverts commit 2871b30.
  • Loading branch information
CamJN committed Dec 19, 2023
1 parent 7b3bdd9 commit 75c79bc
Showing 1 changed file with 7 additions and 9 deletions.
16 changes: 7 additions & 9 deletions Getargv/Getargv.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@
using System.Runtime.InteropServices;
using System.Runtime.Versioning;

using Pointer = System.IntPtr;

namespace Getargv;

[SupportedOSPlatform("macos")]
Expand Down Expand Up @@ -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<byte>();
if ((IntPtr)res.start_pointer == IntPtr.Zero || (IntPtr)res.end_pointer == IntPtr.Zero || res.start_pointer == res.end_pointer) return Array.Empty<byte>();
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;
}
Expand Down Expand Up @@ -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);
Expand Down

0 comments on commit 75c79bc

Please sign in to comment.