gtk: Use the GLib marshaller in IconTheme.SearchPath

This makes the code 64-bit clean (instead of assuming that a pointer
fits in a Int32) and simplifies the code.

Although the GTK doc doesn't say so, the C code shows the array is NULL
terminated, so we should be OK here.

Signed-off-by: Bertrand Lorentz <bertrand.lorentz@gmail.com>
This commit is contained in:
Carlos Martín Nieto 2012-09-02 19:25:56 +02:00 committed by Bertrand Lorentz
parent dd2cf949c1
commit 9c54fd5ae7

View file

@ -79,8 +79,6 @@ namespace Gtk {
public string[] SearchPath { public string[] SearchPath {
get { get {
string[] retval; string[] retval;
unsafe {
int length; int length;
IntPtr raw_ret; IntPtr raw_ret;
if (IsWindowsPlatform) if (IsWindowsPlatform)
@ -88,31 +86,22 @@ namespace Gtk {
else else
gtk_icon_theme_get_search_path (Handle, out raw_ret, out length); gtk_icon_theme_get_search_path (Handle, out raw_ret, out length);
int size = Marshal.SizeOf (typeof (IntPtr)); return GLib.Marshaller.NullTermPtrToStringArray (raw_ret, true);
retval = new string[length];
for (int i = 0, j = 0; i < length; i++, j += size) {
IntPtr string_ptr = Marshal.ReadIntPtr (new IntPtr (raw_ret.ToInt32 () + j));
retval[i] = GLib.Marshaller.Utf8PtrToString (string_ptr);
} }
g_strfreev (raw_ret);
}
return retval;
}
set { set {
int cnt_path = value == null ? 0 : value.Length; IntPtr[] native_path;
IntPtr[] native_path = new IntPtr [cnt_path]; if (value == null)
for (int i = 0; i < cnt_path; i++) native_path = new IntPtr [0];
native_path [i] = GLib.Marshaller.StringToPtrGStrdup (value[i]); else
native_path = GLib.Marshaller.StringArrayToNullTermPointer (value);
if (IsWindowsPlatform) if (IsWindowsPlatform)
gtk_icon_theme_set_search_path_utf8 (Handle, native_path, native_path.Length); gtk_icon_theme_set_search_path_utf8 (Handle, native_path, native_path.Length);
else else
gtk_icon_theme_set_search_path (Handle, native_path, native_path.Length); gtk_icon_theme_set_search_path (Handle, native_path, native_path.Length);
for (int i = 0; i < native_path.Length; i++) GLib.Marshaller.Free (native_path);
GLib.Marshaller.Free (native_path[i]);
} }
} }