hugopl / gi-crystal

Tool to generate Crystal bindings for gobject-based libraries (i.e. GTK)
BSD 3-Clause "New" or "Revised" License
45 stars 3 forks source link

Latest glib API changes #145

Closed GeopJr closed 5 months ago

GeopJr commented 6 months ago

On the latest glib, the following:

  fun g_once_init_enter(location : Pointer(Void)) : LibC::Int
  fun g_once_init_enter(location : Pointer(Void)) : LibC::Int
  fun g_once_init_leave(location : Pointer(Void), result : UInt64) : Void
  fun g_once_init_leave(location : Pointer(Void), result : UInt64) : Void

became:

  fun g_once_init_enter(location : Pointer(Pointer(Void))) : LibC::Int
  fun g_once_init_enter(location : Pointer(Pointer(Void))) : LibC::Int
  fun g_once_init_enter_impl(location : Pointer(UInt64)) : LibC::Int
  fun g_once_init_enter_impl(location : Pointer(UInt64)) : LibC::Int
  fun g_once_init_enter_pointer(location : Pointer(Void)) : LibC::Int
  fun g_once_init_enter_pointer(location : Pointer(Void)) : LibC::Int
  fun g_once_init_leave(location : Pointer(Pointer(Void)), result : UInt64) : Void
  fun g_once_init_leave(location : Pointer(Pointer(Void)), result : UInt64) : Void
  fun g_once_init_leave_pointer(location : Pointer(Void), result : Pointer(Void)) : Void
  fun g_once_init_leave_pointer(location : Pointer(Void), result : Pointer(Void)) : Void

g_once_init_enter and g_once_init_leave are used in object and enum

hugopl commented 5 months ago

What glib version changed this? I'm running on 2.78.4 here and it seems fine.

GeopJr commented 5 months ago

>= 2.79 https://gitlab.gnome.org/GNOME/glib/-/commit/726eca7c898ade4c69ca03220c1a2d69b1842074

gthread: introduce g_onceinit{enter,leave}_pointer

These functions can be used to initalize pointer-type variables rather than a gsize. This is required to support CHERI-enabled platforms where gsize cannot be used to store pointers. Follow-up changes will migrate the uses of g_once_init that store pointers to the new API

Helps: #2842

And my guess on location becoming pointer of pointer in gi is https://gitlab.gnome.org/GNOME/glib/-/commit/56daac02d1fff1a268c61e07562af19189b0859e

hugopl commented 5 months ago

If I understood correctly these changes only matter if we desire to support these architectures, and if I use the new added functions instead the current one I'll need to do some checks to work with new and old glib.

So I think the better thing to do meanwhile is nothing πŸ˜… , since I believe no one is using gi-crystal on those architectures.

GeopJr commented 5 months ago

100% agree! But it also changed location from Pointer(Void) to Pointer(Pointer(Void)) and the compiler complains:

Showing last frame. Use --error-trace for full trace.

There was a problem expanding macro 'inherited'

Code in src/collision/window.cr:27:3

 27 | class Window < Adw::ApplicationWindow
      ^
Called macro defined in lib/gi-crystal/src/bindings/g_object/object.cr:63:5

 63 | macro inherited

Which expanded to:

 > 21 | 
 > 22 |         def self.g_type : UInt64
 > 23 |           if LibGLib.g_once_init_enter(pointerof(@@_g_type)) != 0
                                               ^--------
Error: undefined method 'to_unsafe' for Pointer(UInt64)
Error: module collision: Child process exited with code 1

edit: or am I completely off mark and the problem is somewhere else?

hugopl commented 5 months ago

now it needs to be fixed 😁.

GeopJr commented 5 months ago

Thanks for the quick fix :heart:

hugopl commented 5 months ago

I was waiting the package land on ArchLinux and become a blocker for me too πŸ˜…, so I wouldn't need to compile g_lib, setup a lot of environment variables, etc...