commit b8c1a63015a39c544815fc406e930be03c804104 Author: Alan McGovern <a...@linux-se59.site> Date: Sat Jun 12 18:53:15 2010 +0100
Use GLib.Marshaller to handle our string freeing and marshalling This guarantees that we'll g_free and g_alloc as is required. Signed-off-by: Nathaniel McCallum <nathan...@natemccallum.com> bindings/mono/libgpod-sharp/GPodBase.cs | 24 +++++------------------- 1 files changed, 5 insertions(+), 19 deletions(-) --- diff --git a/bindings/mono/libgpod-sharp/GPodBase.cs b/bindings/mono/libgpod-sharp/GPodBase.cs index 84341c3..a854eae 100644 --- a/bindings/mono/libgpod-sharp/GPodBase.cs +++ b/bindings/mono/libgpod-sharp/GPodBase.cs @@ -27,38 +27,24 @@ namespace GPod { } public abstract class GPodBase<T> : IGPodBase, IDisposable { - protected static IntPtr StringToPtrUTF8 (string s) - { - if (s == null) - return IntPtr.Zero; - // We should P/Invoke g_strdup with 's' and return that pointer. - return Marshal.StringToHGlobalAuto (s); - } protected static string PtrToStringUTF8 (IntPtr ptr) { - // FIXME: Enforce this to be UTF8, this actually uses platform encoding - // which is probably going to be utf8 on most linuxes. - return Marshal.PtrToStringAuto (ptr); + return GLib.Marshaller.Utf8PtrToString (ptr); } protected static void ReplaceStringUTF8 (ref IntPtr ptr, string str) { - if (ptr != IntPtr.Zero) { - // FIXME: g_free it - } - ptr = StringToPtrUTF8 (str); + GLib.Marshaller.Free (ptr); + ptr = GLib.Marshaller.StringToPtrGStrdup (str); } protected static IntPtr DateTimeTotime_t (DateTime time) { - DateTime epoch = new DateTime (1970, 1, 1, 0, 0, 0); - return new IntPtr (((int) time.ToUniversalTime().Subtract(epoch).TotalSeconds)); + return GLib.Marshaller.DateTimeTotime_t (time); } protected static DateTime time_tToDateTime (IntPtr time_t) { - DateTime epoch = new DateTime (1970, 1, 1, 0, 0, 0); - int utc_offset = (int)(TimeZone.CurrentTimeZone.GetUtcOffset (DateTime.Now)).TotalSeconds; - return epoch.AddSeconds((int)time_t + utc_offset); + return GLib.Marshaller.time_tToDateTime (time_t); } internal IntPtr Native { ------------------------------------------------------------------------------ This SF.net email is sponsored by Sprint What will you do first with EVO, the first 4G phone? Visit sprint.com/first -- http://p.sf.net/sfu/sprint-com-first _______________________________________________ gtkpod-cvs2 mailing list gtkpod-cvs2@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/gtkpod-cvs2