From de78d5717645b4213c2417d331cfa048be1ba3e4 Mon Sep 17 00:00:00 2001 From: Mike Kestner Date: Thu, 8 Nov 2007 17:27:13 +0000 Subject: [PATCH] 2007-11-08 Mike Kestner * glib/Marshaller.cs: new null-terminated string[] marshaler from Mono.Unix with adaptations by Michael Hutchinson. svn path=/trunk/gtk-sharp/; revision=89218 --- ChangeLog | 5 +++++ glib/Marshaller.cs | 18 ++++++++++++++++++ 2 files changed, 23 insertions(+) diff --git a/ChangeLog b/ChangeLog index 036d736bf..2e47f23e0 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,8 @@ +2007-11-08 Mike Kestner + + * glib/Marshaller.cs: new null-terminated string[] marshaler from + Mono.Unix with adaptations by Michael Hutchinson. + 2007-11-02 Mike Kestner * glib/SList.cs: diff --git a/glib/Marshaller.cs b/glib/Marshaller.cs index 99f1abdc1..32fdd974f 100644 --- a/glib/Marshaller.cs +++ b/glib/Marshaller.cs @@ -133,6 +133,24 @@ namespace GLib { return ret.Replace ("%", "%%"); } + public static string[] PtrToStringArrayGFree (IntPtr string_array) + { + if (string_array == IntPtr.Zero) + return new string [0]; + + int count = 0; + while (Marshal.ReadIntPtr (string_array, count*IntPtr.Size) != IntPtr.Zero) + ++count; + + string[] members = new string[count]; + for (int i = 0; i < count; ++i) { + IntPtr s = Marshal.ReadIntPtr (string_array, i * IntPtr.Size); + members[i] = GLib.Marshaller.PtrToStringGFree (s); + } + GLib.Marshaller.Free (string_array); + return members; + } + // Argv marshalling -- unpleasantly complex, but // don't know of a better way to do it. //