glib: Remove obsolete Argv-related methods in Marshaller
The ArgvToArrayPtr and ArrayPtrToArgv have been marked obsolete since 2004, and removing them allows us to remove some more code.
This commit is contained in:
parent
c2f9035625
commit
f067f5112d
1 changed files with 0 additions and 101 deletions
|
@ -239,15 +239,6 @@ namespace GLib {
|
||||||
return members;
|
return members;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Argv marshalling -- unpleasantly complex, but
|
|
||||||
// don't know of a better way to do it.
|
|
||||||
//
|
|
||||||
// Currently, the 64-bit cleanliness is
|
|
||||||
// hypothetical. It's also ugly, but I don't know of a
|
|
||||||
// construct to handle both 32 and 64 bitness
|
|
||||||
// transparently, since we need to alloc buffers of
|
|
||||||
// [native pointer size] * [count] bytes.
|
|
||||||
|
|
||||||
[DllImport (Global.GLibNativeDll, CallingConvention = CallingConvention.Cdecl)]
|
[DllImport (Global.GLibNativeDll, CallingConvention = CallingConvention.Cdecl)]
|
||||||
static extern IntPtr g_malloc(UIntPtr size);
|
static extern IntPtr g_malloc(UIntPtr size);
|
||||||
|
|
||||||
|
@ -256,98 +247,6 @@ namespace GLib {
|
||||||
return g_malloc (new UIntPtr (size));
|
return g_malloc (new UIntPtr (size));
|
||||||
}
|
}
|
||||||
|
|
||||||
static bool check_sixtyfour () {
|
|
||||||
int szint = Marshal.SizeOf (typeof (int));
|
|
||||||
int szlong = Marshal.SizeOf (typeof (long));
|
|
||||||
int szptr = IntPtr.Size;
|
|
||||||
|
|
||||||
if (szptr == szint)
|
|
||||||
return false;
|
|
||||||
if (szptr == szlong)
|
|
||||||
return true;
|
|
||||||
|
|
||||||
throw new Exception ("Pointers are neither int- nor long-sized???");
|
|
||||||
}
|
|
||||||
|
|
||||||
static IntPtr make_buf_32 (string[] args)
|
|
||||||
{
|
|
||||||
int[] ptrs = new int[args.Length];
|
|
||||||
|
|
||||||
for (int i = 0; i < args.Length; i++)
|
|
||||||
ptrs[i] = (int) Marshal.StringToHGlobalAuto (args[i]);
|
|
||||||
|
|
||||||
IntPtr buf = g_malloc (new UIntPtr ((ulong) Marshal.SizeOf(typeof(int)) *
|
|
||||||
(ulong) args.Length));
|
|
||||||
Marshal.Copy (ptrs, 0, buf, ptrs.Length);
|
|
||||||
return buf;
|
|
||||||
}
|
|
||||||
|
|
||||||
static IntPtr make_buf_64 (string[] args)
|
|
||||||
{
|
|
||||||
long[] ptrs = new long[args.Length];
|
|
||||||
|
|
||||||
for (int i = 0; i < args.Length; i++)
|
|
||||||
ptrs[i] = (long) Marshal.StringToHGlobalAuto (args[i]);
|
|
||||||
|
|
||||||
IntPtr buf = g_malloc (new UIntPtr ((ulong) Marshal.SizeOf(typeof(long)) *
|
|
||||||
(ulong) args.Length));
|
|
||||||
Marshal.Copy (ptrs, 0, buf, ptrs.Length);
|
|
||||||
return buf;
|
|
||||||
}
|
|
||||||
|
|
||||||
[Obsolete ("Use GLib.Argv instead to avoid leaks.")]
|
|
||||||
public static IntPtr ArgvToArrayPtr (string[] args)
|
|
||||||
{
|
|
||||||
if (args.Length == 0)
|
|
||||||
return IntPtr.Zero;
|
|
||||||
|
|
||||||
if (check_sixtyfour ())
|
|
||||||
return make_buf_64 (args);
|
|
||||||
|
|
||||||
return make_buf_32 (args);
|
|
||||||
}
|
|
||||||
|
|
||||||
// should we be freeing these pointers? they're marshalled
|
|
||||||
// from our own strings, so I think not ...
|
|
||||||
|
|
||||||
static string[] unmarshal_32 (IntPtr buf, int argc)
|
|
||||||
{
|
|
||||||
int[] ptrs = new int[argc];
|
|
||||||
string[] args = new string[argc];
|
|
||||||
|
|
||||||
Marshal.Copy (buf, ptrs, 0, argc);
|
|
||||||
|
|
||||||
for (int i = 0; i < ptrs.Length; i++)
|
|
||||||
args[i] = Marshal.PtrToStringAuto ((IntPtr) ptrs[i]);
|
|
||||||
|
|
||||||
return args;
|
|
||||||
}
|
|
||||||
|
|
||||||
static string[] unmarshal_64 (IntPtr buf, int argc)
|
|
||||||
{
|
|
||||||
long[] ptrs = new long[argc];
|
|
||||||
string[] args = new string[argc];
|
|
||||||
|
|
||||||
Marshal.Copy (buf, ptrs, 0, argc);
|
|
||||||
|
|
||||||
for (int i = 0; i < ptrs.Length; i++)
|
|
||||||
args[i] = Marshal.PtrToStringAuto ((IntPtr) ptrs[i]);
|
|
||||||
|
|
||||||
return args;
|
|
||||||
}
|
|
||||||
|
|
||||||
[Obsolete ("Use GLib.Argv instead to avoid leaks.")]
|
|
||||||
public static string[] ArrayPtrToArgv (IntPtr array, int argc)
|
|
||||||
{
|
|
||||||
if (argc == 0)
|
|
||||||
return new string[0];
|
|
||||||
|
|
||||||
if (check_sixtyfour ())
|
|
||||||
return unmarshal_64 (array, argc);
|
|
||||||
|
|
||||||
return unmarshal_32 (array, argc);
|
|
||||||
}
|
|
||||||
|
|
||||||
static System.DateTime local_epoch = new System.DateTime (1970, 1, 1, 0, 0, 0);
|
static System.DateTime local_epoch = new System.DateTime (1970, 1, 1, 0, 0, 0);
|
||||||
static int utc_offset = (int) (System.TimeZone.CurrentTimeZone.GetUtcOffset (System.DateTime.Now)).TotalSeconds;
|
static int utc_offset = (int) (System.TimeZone.CurrentTimeZone.GetUtcOffset (System.DateTime.Now)).TotalSeconds;
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue