IRC channel logs

2020-05-23.log

back to list of logs

<jasom>So, I'm writing an extension to xbindkeys (uses guile 2.2.x) and find that if I allocate in a key handler, the whole program eventually crashes shortly after a GC. Do C programs have to do anything special to keep references to scheme objects alive?
<jasom>Looking at the C program, It enters the main of the program via: scm_boot_guile(0,(char**)NULL,(void *)inner_main,NULL); loads a single scheme file, which may pass closures back to the program via a scheme function defined in C, then enters an X11 event loop that periodically calls into one of the closures via scm_call_0().
<jasom>Is there anything obviously wrong with doing that?
<dsmith>Heya jasom, I don't your answer, but it's a good question. Might take a while for people who know to answer.
<dsmith>jasom: Have you seen https://www.gnu.org/software/guile/manual/html_node/Garbage-Collection-Functions.html ?
<dsmith>Sepecifically, the protect-object and remember-upto stuff?
<jasom>dsmith: saw that, but footnotes say that it's only needed in 1.8 and older
<dsmith>Ah
<jasom>I will try those though and see if it makes a difference
<dsmith>Also, (may or mayb not apply to your code) make sure that any SCM's are *never* NULL. Bad things happen.
<jasom>that made the problem go away. Is it required to use scm_gc_malloc() to allocate from the heap? I'll try making that change and see if it fixes things.
<jasom>I've read https://www.gnu.org/software/guile/manual/html_node/Memory-Blocks.html about 3 times and I'm still not sure what the requirement is for allocating from the heap something that will include a mixture of C and scheme objects...
<jasom>I see "Memory blocks that are associated with Scheme objects (for example a foreign object) should be allocated with scm_gc_malloc or scm_gc_malloc_pointerless." But I understand that as meaning "pointers that will be held by scheme objects" not "pointers that hold references to scheme objects"
<jasom>well using either explicit protection or gc_malloc causes the bug to stop reproducing, so I'm guessing that the GC doesn't scan malloc() allocations for roots.
<RhodiumToad>that's possible.
<dsmith>jasom: It's also fun to force a gc instead of waiting for one.
<jasom>dsmith: yeah, that can make it happen faster certainly
<jasom>dsmith: good point; fastest way to reproduce is to do something that allocates in the press event and gc in the release. Crashes on second click every time. Should help in getting fix upstream
***sneek_ is now known as sneek
***sneek_ is now known as sneek
<dsmith>sneek: botsnack
<sneek>:)
<jasom>dsmith: thanks for the help; I've submitted a patch upstream now.
<dsmith>Wow. Glad I could help.
***jonsger1 is now known as jonsger
<dsmith>jasom: Looking at that 1.8 comment more carefully. I belive it says for 1.8 and before, you *must* use scm_gc_protect_object. After 1.8, you can use that function or store it in a C gloabal variable.
<ryanprior>Are there any quality GTK3 applications written in Guile that I should check out to research how I might write my own?
<daviid>ryanprior: I don't think so, but we have basic examples, both for guile-gi and g-golf ...
<daviid>ryanprior: guile-gi is here https://spk121.github.io/guile-gi/
<daviid>ryanprior: g-golf is here https://www.gnu.org/software/g-golf/
<ryanprior>Thank you, I will check out the basic examples for sure.
<daviid>ryanprior: don't know about guile-gi, but the g-golf repo does not have the examples, but i can paste when/if you wish, le me know ... the first think for you is t decid if you go with guile-gi or g-golf I can't recommend because i'm the g-golf author :):)
<daviid>str1ngs: do t still have a nomad vrsion that uses guile-gi?
<chrislck>tutorials are painfully lacking in guix and numerous guile code
<chrislck>the video posted here or guix was really good: https://www.youtube.com/watch?v=t4vKPhjcMZg
<ryanprior>daviid: what's your brief pitch for g-golf over guile-gi? Are there certain areas or use cases where guile-gi is clearly stronger?
<ryanprior>Also, feel free to hit me with the examples in whatever format, I will save or bookmark them.
<daviid>ryanprior: here is what i wrote for a similar user rqust a few days ago https://lists.gnu.org/archive/html/guile-gtk-general/2020-05/msg00001.html
<daviid>ryanprior: here is a g-golf (very) basic example https://paste.debian.net/1148378/
<daviid>i hope someone can post a basic guile-gi example, i can't ...
<daviid>because i don't have any
<daviid>i think there i a nomad guile-gi example 'out there' ...
<tohoyn>is it possible to expand macros to Scheme code? macroexpand makes tree-il.
***apteryx is now known as Guest93436
***apteryx_ is now known as apteryx
<chrislck>sneek: botsnack
<sneek>:)
***sneek_ is now known as sneek
<janneke>tohoyn: in the REPL, try: ,expand (cond (#t #t))
<tohoyn>janneke: tx. works.
***jonsger1 is now known as jonsger
<mwette>o/
<emys>I want to use (ice-9 getopt-long) but the docs don't really say how I can access the command line arguments
<emys>what I got working is to define a main procedure and add to the shebang that guile should call that procedure
<emys>are there other options?
<emys>ah, found what I was looking for, never mind
<emys>(program-arguments)
<RhodiumToad>or (command-line)
<mwette>(srfi srfi-37) is option to getopt-long if you run into issues (e.g., repeated flags) like I did
<janneke>mwette: if i understand you correctly, i'm using something like this
<janneke>(define (option-ref-multi options name) (map cdr (filter (compose (cut eq? <> name) car) options)))
<mwette>janneke: Thanks. The problems I had occured a while ago, so I don't remember all the nuances. I switched to srfi-37 after wingo said it was preferred.
<str1ngs>daviid: nomad has only ever used g-golf.
<str1ngs>guile-gi has an example folder IIRC
<daviid>str1ngs: ah ok
<janneke>mwette: ah...right
<janneke>i didn't like the mixing of code and data, i'll have another look
<daviid>str1ngs: ot - it seems I can't connect to irc.gnome.org today, can you?
<str1ngs>daviid: I'm connected via znc
<daviid>str1ngs: emacs erc mode here - i can't connect