Skip to content
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

Wrong pointer is passed on nillable structs parameters. #162

Open
hugopl opened this issue Jul 23, 2024 · 0 comments
Open

Wrong pointer is passed on nillable structs parameters. #162

hugopl opened this issue Jul 23, 2024 · 0 comments
Labels
bug Something isn't working

Comments

@hugopl
Copy link
Owner

hugopl commented Jul 23, 2024

Generated bindings for Gtk::Popover#pointing_to= is:

    def pointing_to=(rect : Gdk::Rectangle?) : Nil
      # gtk_popover_set_pointing_to: (Method | Setter)
      # @rect: (nullable)
      # Returns: (transfer none)

      # Generator::NullableArrayPlan
      rect = if rect.nil?
               Pointer(Void).null
             else
               rect.to_unsafe
             end

      # C call
      LibGtk.gtk_popover_set_pointing_to(to_unsafe, rect)

      # Return value handling
    end

This compiles but doesn't work, type of rect in else still a union, the problem is caused by the reuse of the rect variable, if I change it to something else it works.

Monkey patch to fix that:

  class Popover
    def pointing_to=(rect : Gdk::Rectangle?) : Nil
      rect_ptr = if rect.nil?
                   Pointer(Void).null
                 else
                   rect.to_unsafe
                 end
      LibGtk.gtk_popover_set_pointing_to(to_unsafe, rect_ptr)
    end
  end
@hugopl hugopl added the bug Something isn't working label Jul 23, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

1 participant