Am I creating a PtrArray the right way? #1344
-
|
I'm using this binding generator to create a binding for libfprint and I found that PtrArray isn't always supported by the source generator, so I wanted to write the function binding manually. Am I doing anything wrong? In case it's helpful, I found I can replicate the issue by following these steps:
GLib.Module.Initialize();
while (true) {
using var arr = new GLib.PtrArray();
Thread.Sleep(100);
}
It prints repeatedly: |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 1 reply
-
|
I will check in the coming days. Thanks for the detailed report. |
Beta Was this translation helpful? Give feedback.
-
|
This is actually some kind of bug in GirCore. Unfortunately there is not even the New function be generated which would do this for you. A workaround for now is to call the new method manually: using System.Runtime.InteropServices;
Console.WriteLine("Hello, World!");
GLib.Module.Initialize();
while (true)
{
var handle = new GLib.Internal.PtrArrayOwnedHandle(New());
using var arr = new GLib.PtrArray(handle);
Thread.Sleep(100);
}
[DllImport("libgobject-2.0.so.0", EntryPoint = "g_ptr_array_new")]
static extern nint New();You need to update your dllimport to the one matching your system. It probably is:
Edit: The api in general is not very usable in the moment. You would need to workaround the missing stuff yourself. There is #748 to improve the situation. I created #1349 as a first step. But more work is needed. Feel free to contribute. |
Beta Was this translation helpful? Give feedback.
This is actually some kind of bug in GirCore.
PtrArrayis a record from GObject perspective. I assumed that records can just be created manually in memory. Which is at least not true forPtrArrayas it requires some specific initialization.Unfortunately there is not even the New function be generated which would do this for you.
A workaround for now is to call the new method manually: