Hello Matija,

> I'm facing the problem mentioned in [1]. Problematic are all examples
> with virtual methods.

Ok, so you are facing the same problem as Guix and HomeBrew, all other
distro (that tried g-golf) work fine, i use Debian.

> I have tried simpler example (attached) with same result. There is no
> problem, when try same thing with guile-gi library. Somehow, callbacks
> are not callable back from C code. Any clue?

        afaict, guile-gi does not support the definition of virtual
        functions - you can try this example using guile-gi
        (which afaict is unmaintained) because you are calling a
        'regular' method, set-draw-func

        no problem, just saying that a mechanism to define vfunc in
        the GI lang binding of your choice is absolutely crucial for any
        'real serious' gnome stack (type)libs use

        one big diffference in between guile-gi and g-golf is that in
        g-golf, the callback closure marshal code is written in scheme,
        the one in guile-gi is written in C - it could be that the
        pointer of the vfunc 'is fine' in guix/nix as well, but that for
        some reason, the %g-golf-callback-closure-marshal pointer
        would be the one that is damaged, i don't know

Great, never used that function. You incidentally found a small bug in
GI itself [1], and a tiny bug in G-Golf as well, though not the one
that would solve the Guix/Nix/Homebrew problem yet [2], but thanks:

        can you install from the source
        checkout the devel branch
        run the make danse and install the latest

        [ to double check, you need this commit
        [ 134b57f52bc23cea8e3e02b974c7b909bb7cf56e

So, here, after i patched g-golf to deal with this GI destroy notify
callback tiny problem, so i can pass #f as its argument, then it works
fine, as expected:

        https://imgur.com/a/tX8bn16

I slightly patched your example so it allows you to call it passing a
-d [--debug] argument on the command line, which triggers the
display of useful information while debugging ...

> I'm using Nix.

It would be interesting to try to understand the difference in between
Debian (and most other distro) and Guix/Nix: when a vfunc is defined,
it sets the upstream class structure field to a pointer, the result of
calling g-callable-info-make-closure (defined in (g-golf hl-api
callback).

For some reason, that pointer is 'damaged' in Guix/Nix/Homebrew, and
not in Debian (and most other distro), and as the gdb backtrace shows,
in the msg link you are referring to, when Gtk tries to make a snapshot,
it needs to access and 'call that pointer', which segfault ...

I hope you'll be able to help, feel free to come and join us in #guile
or #guix and try to get some help from a guix expert ...

Thanks,
David

[1]

all destroy notify callback argument ('linked' to a user-data argument)
should always allow to be NULL, which g-golf checks by calling (>=
(!destroy clb/arg) 0)  but the signature of the destroy notify callback
argument for gtk_drawing_area_set_draw_func wrongly report -1

[2]

i did report the incident upstream, and meanwhile, patched g-golf so it
treats callback argument named "destroy" as a maybe-null-exception,
which checks itself had a tiny bug, fixed, thanks!
#! /bin/sh
# -*- mode: scheme; coding: utf-8 -*-
exec guile -e main -s "$0" "$@"
!#


(eval-when (expand load eval)
  (use-modules (oop goops))

  (default-duplicate-binding-handler
    '(merge-generics replace warn-override-core warn last))

  (use-modules (g-golf))

  (g-irepository-require "Gtk" #:version "4.0")
  (for-each (lambda (name)
              (gi-import-by-name "Gtk" name))
			'("ApplicationWindow"
			  "Application"
			  "DrawingArea")))


(define (activate app)
  (let* ((window (make <gtk-application-window>
                   #:application app
                   #:default-width 960
                   #:default-height 540
                   #:title "Title"))
	 (drawing-area (make <gtk-drawing-area>)))
    (set-child window drawing-area)
    (set-draw-func drawing-area
		   (lambda (area cr w h d)
		     (display "I'm in!")
		     (force-output))
		   #f
		   #f)
    (show window)))

(define (main args)
  (letrec ((debug? (or (member "-d" args)
                       (member "--debug" args)))
           (animate
            (lambda ()
              (let ((app (make <gtk-application>
                           #:application-id "org.gnu.g-golf.set-draw-func")))
                (connect app 'activate activate)
                (let ((status (g-application-run app '())))
                  #;(exit status)
                  (dimfi 'status status))))))
    (if debug?
        (parameterize ((%debug #t))
          (animate))
        (animate))))

Attachment: pgpkz_WxGwOVi.pgp
Description: OpenPGP digital signature

Reply via email to