+
Skip to content

Add RunWithSynchronizationContext with arguments #956

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Sep 20, 2023
Merged

Add RunWithSynchronizationContext with arguments #956

merged 2 commits into from
Sep 20, 2023

Conversation

fsobolev
Copy link
Contributor

  • I agree that my contribution may be licensed either under MIT or any version of LGPL license.

Closes #916

@badcel
Copy link
Member

badcel commented Sep 17, 2023

I think we should remove the parameterless method (Run and RunWithSynchronizationContext) as it is not available in the bindings, too. So let's keep the additions to a minimum.

Unfortunately the generated bindings are currently not 100% correct.

Meaning the encoding is probably not correct. I would ignore this for now as there are no length based platform arrays currently and it looks like it works more or less. (Should be fixed with #955.)

Additionally the length parameter is part of the public API. As it is declared to belong to the array it will vanish if #917 is merged. For this reason I would remove it already from the RunWithSynchronizationContext to avoid breaking the API again.

The last point is that the array itself is nullable. For this reason I think we should mark it as nullable, too (see #955).

If it is null you can simply pass 0 and Array.Empty<string> to the current run implementation.

(See documentation)

After updating the code: Can you confirm that it works for you with Array.Empty, null and actual data as a parameter?

@fsobolev
Copy link
Contributor Author

Unfortunately there are some problems, but I guess it's not related to this PR?

Arguments \ Flag DefaultFlags HandlesOpen HandlesCommandLine
null ✅ Calls OnActivate ✅ Calls OnActivate ⚠️ [2]
Array.Empty<string>() ✅ Calls OnActivate ✅ Calls OnActivate ⚠️ [2]
new string[] { ... } ✅ Closes with This application can not open files. ⚠️ [1] ⚠️ [2]

[1] Calls OnOpen successfully, but trying to get the files (e.Files) causes crash:

UnhandledException - unhandled exception: System.InvalidCastException: Unable to cast object of type 'System.IntPtr' to type 'Gio.File[]'.
   at GObject.Value.Extract[T]() in /home/user/.var/distrobox/fedora/Projects/gir.core/src/Libs/GObject-2.0/Public/Value.cs:line 167
   at Gio.Application.OpenSignalArgs.get_Files() in /home/user/.var/distrobox/fedora/Projects/gir.core/src/Libs/Gio-2.0/Public/Application.Signals.Generated.cs:line 114
   at org.gircore.test.Program.<>c.<.ctor>b__3_3(Application sender, OpenSignalArgs e) in /home/user/.var/distrobox/fedora/Projects/GirTest/Program.cs:line 35
   at GObject.Signal`2.<>c__DisplayClass11_0.<Connect>b__0(Value returnValue, Value[] parameters) in /home/user/.var/distrobox/fedora/Projects/gir.core/src/Libs/GObject-2.0/Public/SignalTSenderTSignalArgs.cs:line 46
   at GObject.Closure.InternalCallback(IntPtr closure, IntPtr returnValuePtr, UInt32 nParamValues, ValueData[] paramValuesData, IntPtr invocationHint, IntPtr userData) in /home/user/.var/distrobox/fedora/Projects/gir.core/src/Libs/GObject-2.0/Public/Closure.cs:line 47

[2] Calls OnCommandLine succesfully, but trying to get arguments (var argv = e.CommandLine.GetArguments(out var argc);) causes crash:

UnhandledException - unhandled exception: System.Runtime.InteropServices.MarshalDirectiveException: Cannot marshal 'return value': Invalid managed/unmanaged type combination.
   at Gio.Internal.ApplicationCommandLine.GetArguments(IntPtr cmdline, Int32& argc)
   at Gio.ApplicationCommandLine.GetArguments(Int32& argc) in /home/user/.var/distrobox/fedora/Projects/gir.core/src/Libs/Gio-2.0/Public/ApplicationCommandLine.Methods.Generated.cs:line 30
   at org.gircore.test.Program.<>c.<.ctor>b__3_2(Application sender, CommandLineSignalArgs e) in /home/user/.var/distrobox/fedora/Projects/GirTest/Program.cs:line 29
   at GObject.ReturningSignal`3.<>c__DisplayClass11_0.<Connect>b__0(Value returnValue, Value[] parameters) in /home/user/.var/distrobox/fedora/Projects/gir.core/src/Libs/GObject-2.0/Public/ReturningSignalTSenderTSignalArgs.cs:line 50
   at GObject.Closure.InternalCallback(IntPtr closure, IntPtr returnValuePtr, UInt32 nParamValues, ValueData[] paramValuesData, IntPtr invocationHint, IntPtr userData) in /home/user/.var/distrobox/fedora/Projects/gir.core/src/Libs/GObject-2.0/Public/Closure.cs:line 47

@badcel
Copy link
Member

badcel commented Sep 18, 2023

Thanks for testing things out. I will take a look at your findings later.

Can you switch the samples to use RunWithSynchrinizarionContext(null) as it probably should be the recommended way of doing it to avoid problems for new users.

@badcel
Copy link
Member

badcel commented Sep 20, 2023

I could reproduce the problems with HandleCommandLine and added the defunct code as a sample to #955.

I could not reproduce the HandlesOpen issue but this is probably because I could not get the code to raise the event. From your exception it looks like an interface (Gio.File) should be extracted from signals args which is a GObject.Value. As extracting interfaces from a value is not yet supported I opened #958 for this. Could you provide some more help on how to get the sample working in issue #958?

As those points are not related to your PR it is good to go. Thank you 👍

@badcel badcel merged commit c901059 into gircore:main Sep 20, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

RunWithSynchronizationContext With Args
3 participants
点击 这是indexloc提供的php浏览器服务,不要输入任何密码和下载