unofficial mirror of guile-user@gnu.org 
 help / color / mirror / Atom feed
From: David Pirotte <david@altosw.be>
To: Matija Obid <matija.obid@posteo.net>
Cc: guile-user@gnu.org
Subject: Re: G-Golf - Callback segmentation fault
Date: Wed, 21 Aug 2024 21:21:29 -0300	[thread overview]
Message-ID: <20240821212129.7647d035@tintin> (raw)
In-Reply-To: <87msl6c4lf.fsf@posteo.net>


[-- Attachment #1.1: Type: text/plain, Size: 3221 bytes --]

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!

[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #1.2: nix-set-draw-func.scm --]
[-- Type: text/x-scheme, Size: 1527 bytes --]

#! /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 #2: OpenPGP digital signature --]
[-- Type: application/pgp-signature, Size: 488 bytes --]

  parent reply	other threads:[~2024-08-22  0:21 UTC|newest]

Thread overview: 30+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-08-21 14:50 G-Golf - Callback segmentation fault Matija Obid
2024-08-21 15:19 ` pelzflorian (Florian Pelz)
2024-08-23 23:57   ` David Pirotte
2024-08-24 16:01     ` pelzflorian (Florian Pelz)
2024-08-25  5:09       ` David Pirotte
2024-08-25 13:28         ` pelzflorian (Florian Pelz)
2024-08-26  6:40           ` pelzflorian (Florian Pelz)
2024-08-22  0:21 ` David Pirotte [this message]
2024-08-27 20:09   ` Matija Obid
2024-08-28 10:50     ` pelzflorian (Florian Pelz)
2024-08-29  0:18     ` David Pirotte
2024-08-31 16:35       ` Matija Obid
2024-09-02 15:30         ` pelzflorian (Florian Pelz)
2024-09-02 21:18         ` David Pirotte
2024-09-03  1:01           ` David Pirotte
2024-09-05  4:00             ` David Pirotte
2024-09-05  7:24               ` pelzflorian (Florian Pelz)
2024-09-05  7:42                 ` pelzflorian (Florian Pelz)
2024-09-05 21:23                   ` David Pirotte
2024-09-05 21:44                     ` David Pirotte
2024-09-05 20:48                 ` David Pirotte
2024-09-05 13:37               ` Matija Obid
2024-09-05 22:14                 ` David Pirotte
2024-09-06  6:29                   ` David Pirotte
2024-09-06  9:44                     ` pelzflorian (Florian Pelz)
2024-09-06 18:37                       ` David Pirotte
2024-09-06 22:08                         ` David Pirotte
2024-09-06 23:16                           ` David Pirotte
2024-09-07 14:08                             ` pelzflorian (Florian Pelz)
2024-09-07 11:53                           ` Matija Obid

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://www.gnu.org/software/guile/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20240821212129.7647d035@tintin \
    --to=david@altosw.be \
    --cc=guile-user@gnu.org \
    --cc=matija.obid@posteo.net \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).