From 75a3c2b6529f2c94318df74a6d38a3843def8b62 Mon Sep 17 00:00:00 2001 From: Sebastien Pouliot Date: Fri, 22 Apr 2022 15:41:14 -0400 Subject: [PATCH 1/3] [glib] Fix `g_filename_from_utf8` signature for 64 bits platforms Fixes https://github.com/GtkSharp/GtkSharp/issues/345 --- Source/Libs/GLibSharp/Marshaller.cs | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/Source/Libs/GLibSharp/Marshaller.cs b/Source/Libs/GLibSharp/Marshaller.cs index 449e5b7f3..3603a50d9 100644 --- a/Source/Libs/GLibSharp/Marshaller.cs +++ b/Source/Libs/GLibSharp/Marshaller.cs @@ -117,7 +117,7 @@ namespace GLib { return ret; } [UnmanagedFunctionPointer(CallingConvention.Cdecl)] - delegate IntPtr d_g_filename_from_utf8(IntPtr mem, int len, IntPtr read, out IntPtr written, out IntPtr error); + delegate IntPtr d_g_filename_from_utf8(IntPtr mem, IntPtr len, IntPtr read, out IntPtr written, out IntPtr error); static d_g_filename_from_utf8 g_filename_from_utf8 = FuncLoader.LoadFunction(FuncLoader.GetProcAddress(GLibrary.Load(Library.GLib), "g_filename_from_utf8")); public static IntPtr StringToFilenamePtr (string str) @@ -125,9 +125,8 @@ namespace GLib { if (str == null) return IntPtr.Zero; - IntPtr dummy, error; IntPtr utf8 = StringToPtrGStrdup (str); - IntPtr result = g_filename_from_utf8 (utf8, -1, IntPtr.Zero, out dummy, out error); + IntPtr result = g_filename_from_utf8 (utf8, (IntPtr)(-1), IntPtr.Zero, out _, out var error); g_free (utf8); if (error != IntPtr.Zero) From 7391aac88d232e2d03e95c836a7618daae146d2c Mon Sep 17 00:00:00 2001 From: Sebastien Pouliot Date: Fri, 22 Apr 2022 21:01:12 -0400 Subject: [PATCH 2/3] [glib] Fix g_filename_to_utf8 signature for 64 bits platforms --- Source/Libs/GLibSharp/Marshaller.cs | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/Source/Libs/GLibSharp/Marshaller.cs b/Source/Libs/GLibSharp/Marshaller.cs index 3603a50d9..bb70434da 100644 --- a/Source/Libs/GLibSharp/Marshaller.cs +++ b/Source/Libs/GLibSharp/Marshaller.cs @@ -48,15 +48,14 @@ namespace GLib { g_free (ptrs [i]); } [UnmanagedFunctionPointer(CallingConvention.Cdecl)] - delegate IntPtr d_g_filename_to_utf8(IntPtr mem, int len, IntPtr read, out IntPtr written, out IntPtr error); + delegate IntPtr d_g_filename_to_utf8(IntPtr mem, IntPtr len, IntPtr read, out IntPtr written, out IntPtr error); static d_g_filename_to_utf8 g_filename_to_utf8 = FuncLoader.LoadFunction(FuncLoader.GetProcAddress(GLibrary.Load(Library.GLib), "g_filename_to_utf8")); public static string FilenamePtrToString (IntPtr ptr) { if (ptr == IntPtr.Zero) return null; - IntPtr dummy, error; - IntPtr utf8 = g_filename_to_utf8 (ptr, -1, IntPtr.Zero, out dummy, out error); + IntPtr utf8 = g_filename_to_utf8 (ptr, (IntPtr)(-1), IntPtr.Zero, out _, out var error); if (error != IntPtr.Zero) throw new GLib.GException (error); From fd3eb0c839e5686a2a10bd8a8fe2f25417c88812 Mon Sep 17 00:00:00 2001 From: Sebastien Pouliot Date: Sun, 24 Apr 2022 11:18:36 -0400 Subject: [PATCH 3/3] Add FileChooserDialog to samples app This shows the original issue on macOS/arm64 (if the rest of the PR is not applied) ``` GLib.GException: Invalid byte sequence in conversion input at GLib.Marshaller.FilenamePtrToString(IntPtr ptr) in /Users/poupou/git/external/GtkSharp/Source/Libs/GLibSharp/Marshaller.cs:line 62 at GLib.Marshaller.FilenamePtrToStringGFree(IntPtr ptr) in /Users/poupou/git/external/GtkSharp/Source/Libs/GLibSharp/Marshaller.cs:line 68 at Gtk.FileChooserDialog.get_Filename() in /Users/poupou/git/external/GtkSharp/Source/Libs/GtkSharp/Generated/Gtk/FileChooserDialog.cs:line 222 at Samples.FileChooserDialogDemo.OnPressed() in /Users/poupou/git/external/GtkSharp/Source/Samples/Sections/Dialogs/FileChooserDialogSection.cs:line 28 at Gtk.Button.Pressed_cb(IntPtr inst) in /Users/poupou/git/external/GtkSharp/Source/Libs/GtkSharp/Generated/Gtk/Button.cs:line 388 at GLib.ExceptionManager.RaiseUnhandledException(Exception e, Boolean is_terminal) in /Users/poupou/git/external/GtkSharp/Source/Libs/GLibSharp/ExceptionManager.cs:line 58 at Gtk.Button.Pressed_cb(IntPtr inst) in /Users/poupou/git/external/GtkSharp/Source/Libs/GtkSharp/Generated/Gtk/Button.cs:line 388 at Gtk.Application.Run() in /Users/poupou/git/external/GtkSharp/Source/Libs/GtkSharp/Application.cs:line 115 at Samples.Program.Main(String[] args) in /Users/poupou/git/external/GtkSharp/Source/Samples/Program.cs:line 44 ``` --- .../Dialogs/FileChooserDialogSection.cs | 32 +++++++++++++++++++ 1 file changed, 32 insertions(+) create mode 100644 Source/Samples/Sections/Dialogs/FileChooserDialogSection.cs diff --git a/Source/Samples/Sections/Dialogs/FileChooserDialogSection.cs b/Source/Samples/Sections/Dialogs/FileChooserDialogSection.cs new file mode 100644 index 000000000..6c75a366a --- /dev/null +++ b/Source/Samples/Sections/Dialogs/FileChooserDialogSection.cs @@ -0,0 +1,32 @@ +using Gtk; + +namespace Samples +{ + [Section(ContentType = typeof(FileChooserDialog), Category = Category.Dialogs)] + class FileChooserDialogSection : ListSection + { + public FileChooserDialogSection () + { + AddItem ($"Press button to open {nameof(FileChooserDialog)} :", new FileChooserDialogDemo ("Press me")); + } + } + + class FileChooserDialogDemo : Button + { + public FileChooserDialogDemo (string text) : base (text) { } + + protected override void OnPressed () + { + var fcd = new FileChooserDialog ("Open File", null, FileChooserAction.Open); + fcd.AddButton (Stock.Cancel, ResponseType.Cancel); + fcd.AddButton (Stock.Open, ResponseType.Ok); + fcd.DefaultResponse = ResponseType.Ok; + fcd.SelectMultiple = false; + + ResponseType response = (ResponseType) fcd.Run (); + if (response == ResponseType.Ok) + ApplicationOutput.WriteLine (fcd.Filename); + fcd.Destroy (); + } + } +} \ No newline at end of file