gotk4 icon indicating copy to clipboard operation
gotk4 copied to clipboard

Add GLib.PID builtin

Open jgillich opened this issue 1 year ago • 5 comments

This is an early draft for feedback, doesn't work yet

Two questions.

  1. How do I best add the type PID to core/glib? I have it in ExtraGoContents now, but it gets appended every generate run so you get duplicates (which I don't think would happen elsewhere, perhaps the core files are special). I also noticed that I can't regenerate pkg from scratch, not sure if there's a different command for that

  2. Conversion in arrays is wrong:

func(op * MountOperation) showProcesses(message string, processes[] coreglib.PID, choices[] string) {
  // ...
  out: = unsafe.Slice(_arg2.data, len(processes))
  for i: = range processes {
    out[i] = C.GArray(processes[i])

  }
}

Whereas single variables get generated correctly as arg = C.GPid(pid). Not sure what I'm missing here, couldn't track down where inner.Conversion is coming from in typeconv

jgillich avatar Feb 03 '24 04:02 jgillich

externGLibType actually requires the type to be in core/glib! The name "extern" is just a really old name: core/glib was referred to as externGLib internally before I changed some (but not all!) of it to coreGLib.

  1. I also noticed that I can't regenerate pkg from scratch, not sure if there's a different command for that

You shouldn't have to. The generator already wipes pkg.

2. Conversion in arrays is wrong:

Whats the GIR definition for this parameter?

diamondburned avatar Feb 03 '24 04:02 diamondburned

externGLibType actually requires the type to be in core/glib

Right, but it doesn't exist because it's filtered. So I have to add a type definition to core/glib. When I add it to ExtraGoContents and run the generator multiple times, this is what happens:

Screenshot from 2024-02-03 06-02-57

Which then lead me to try to delete pkg before every build. Regenerating fails with all kinds of errors such as

2024/02/03 05:07:01 error verifying generation: missing file/folder "cairo"
2024/02/03 05:07:33 error verifying generation: missing file/folder "core"

Probably doesn't matter though, I just thought I'd mention it

Whats the GIR definition for this parameter?

          <parameter name="processes" transfer-ownership="none">
            <doc xml:space="preserve"
                 filename="gio-2.0.c"
                 line="2549">an array of #GPid for processes
  blocking the operation.</doc>
            <array name="GLib.Array">
              <type name="GLib.Pid"/>
            </array>
          </parameter>

jgillich avatar Feb 03 '24 05:02 jgillich

Oh, both core and cairo are completely manually written so they're not generated. ExtraGoContents is only used for generated packages, not manually written ones.

Once you add the code to handle the core/glib.PID type, you can take GPid off the type ignore list.

diamondburned avatar Feb 03 '24 17:02 diamondburned

Aha, that explains a lot. But when I take it off the ignore list, it still gets generated

So re the array issue, I can "fix" it by hardcoding the type conversion, but then there are still other build errors:

gio/v2/gio.go:66179:30: cannot use false (untyped bool constant) as _Ctype_int value in argument to (_Cfunc_g_array_sized_new)

Seems like g_array_sized_new takes gboolean and not regular bool values. To my surprise, this newly generated function is the only place GLib.Array is used. Seems like it's not fully implemented yet

So I fixed that by reusing coreglib.Gbool. But there's more errors:

gio/v2/gio.go:66185:13: cannot use _Ctype_GPid(processes[i]) (value of type _Ctype_int) as _Ctype_char value in assignment
gio/v2/gio_export.go:4285:42: cannot convert &len (value of type *uintptr) to type *_Ctype_ulong
gio/v2/gio_export.go:4285:69: cannot use _cgo0 (variable of type **_Ctype_struct__GArray) as *_Ctype_struct__GArray value in argument to _Cfunc_g_array_steal
gio/v2/gio_export.go:4288:19: invalid operation: i < len (mismatched types int and uintptr)
gio/v2/gio_export.go:4289:33: cannot convert src[i] (variable of type _Ctype_struct__GArray) to type "github.com/diamondburned/gotk4/pkg/core/glib".PID
gio/v2/gio_export.go:4444:42: cannot convert &len (value of type *uintptr) to type *_Ctype_ulong
gio/v2/gio_export.go:4444:69: cannot use _cgo0 (variable of type **_Ctype_int) as *_Ctype_struct__GArray value in argument to _Cfunc_g_array_steal
gio/v2/gio_export.go:4447:19: invalid operation: i < len (mismatched types int and uintptr)

I think uintptr is also not fully implemented since that popped up in other places too.

jgillich avatar Feb 03 '24 22:02 jgillich

Made some progress. Here's what's passed to convertInner for the GArray

Screenshot from 2024-02-06 06-39-12

GArray is a struct, so this inner CType is wrong. The problem is in resolveCopyType, it decrements any array pointer. Fix/workaround: e66e1ff668aa5505ab8ad0c85c9896d5c26d9d6f

jgillich avatar Feb 06 '24 06:02 jgillich