IRC channel logs

2023-02-08.log

back to list of logs

<jfred>I'm probably just missing something, but how does one register some code that should run when `cancel-thread` is called? I'm creating some GOOPS objects within my thread when it starts, and I need to be able to call a `destroy` method on it when the thread gets shut down. I see in Guile 2.0 there was `set-thread-cleanup!`, but that seems gone in Guile 3.0 and I haven't found what the replacement is
<daviid>jfred: those instances (unless you hold a ref in another thread) should just be gc'ed on the next gc run, so (i think, but i didn't recently test) there is nothing to do, unless by 'destroy' you mean you need to 'clean' some external resource(s), then i'd use a guardian and implement that 'clean' as part of an after-gc-hook
<jfred>Hmm. I could be misinterpreting my issue, or perhaps the GC just doesn't run very often. 🙂 To be specific, I'm using the v4l2 module in AIscm. Under the hood, that uses a C module that seems to indicate that it should call its `videodev2_destroy()` function on free, but e.g. on thread cancellation this seems not to happen (for a while?) during which the camera remains on
<jfred>The v4l2 object has a `destroy` method that immediately calls `videodev2-destroy`, which seems to shut off the camera
<daviid>'... seems to indicate that it should call its `videodev2_destroy()` function on free', guile's gc does not call nor does it free any C struct/object - that is what you should do in a guardian, if that applies
<daviid>guile gc's its own objects (as in any scheme objects, not just gops instances, but if one of your 'object' hold a pointer to a C 'thing', then you are responsible to free it ... which you should do as part of a guardian mechanism
<jfred>Ahh I see... so I don't have a direct reference to anything from C (AIscm does have a Guile module wrapping it), but its Guile module for this doesn't seem to have a guardian itself that would tear anything down on GC, so I suppose I need to handle that myself (or submit a patch)
<daviid>i think you should talk to the aiscm maintainer, surely they know about 'aiscm guile objects' being garbage collected
<daviid>or look to some examplethey may have, i doubt they don't provide a 'safe' mechanism for 'all this'
<daviid>jfred: unless the aiscm doc explicitely says users have to call (a wrapped) v4l2*-destroy method ... 'themsleves', then you're responsible indeed ... i don't know
<jfred>Yeah, I might reach out to the maintainer at some point. The docs don't explicitly say you have to call `destroy` manually, but some of the examples do use it
<daviid>jfred: do you hve a link of such an example, just curious
<jfred>First snippet under the V4L2 section: https://wedesoft.github.io/aiscm/io.html
<daviid>jfred: ok tx - it seems yu have to implement those calls yourself, i would try to do that 'in a guardian' - and see how that goes
<daviid>jfred: i can paste an example you'd need to adapt, let me know
<jfred>Makes sense. I worked around it for now by getting a reference to the v4l2 object outside the thread and calling `destroy` directly after cancelling the thread, but a guardian would indeed be cleaner. Will have to try that when I have some more time. Thanks for the help!
<jfred>An example might save some time if it's not too much trouble
<daviid>ok, let me paste something that you'll have to adapt ... but a start
<daviid>jfred: here https://git.savannah.gnu.org/cgit/g-golf.git/tree/g-golf/hl-api/gtype.scm?h=devel#n183 - till line 228 but the method def that sarts line 212, you'd have to change to do moreless this
<daviid>(define-method (initialize (self <v4l2>) initargs) (next-method) (g-v4l2-guard self ...))
<BitPuffin>hey someone once tipped me off of a guile parser generator library that could be used to generate ffi C bindings somehow, does anyone know which one it was? Have been searching for it periodically for a long time lol
<jfred>daviid: thank you!
<daviid>you'd change those names g-inst-guard -> g-v4l2-guard
<BitPuffin>ah wait is it nyacc
<daviid>jfred: then you'd need a weak key or value hash table, here the one used by this g-golf (old) example - https://git.savannah.gnu.org/cgit/g-golf.git/tree/g-golf/gi/cache-others.scm?h=devel lines 59 - 99 but you'd use the line 73 (which i commented because now i use another technique that needs a real hash table, not a weak hasht table anomore ...
<BitPuffin>oh yes I think it was
<daviid>jfred: in your case, i'd use a weak key hashtabl and store the instance as the key and the value (in g-golf, the value was the GObject pointer instance, but in y9ur aiscm 'case', you only have the schgeme goops instance ... it should work, let me know ...
<daviid>BitPuffin: it is called the ffi-helper, and indeed is part of nyacc
<BitPuffin>thanks <3
<BitPuffin>gotta see if I can figure out how to use it
<mwette> https://www.nongnu.org/nyacc/nyacc-fh-ug.html
<daviid>mwette: that page scares a bit :) - ity says July 2019, With NYACC Version 1.04.1
<daviid>i thought i had a wrong link be3cause of that :)
<mwette>The web page has not been updated lately. Latest version is 1.08.somthing
<mwette>IIRC I ran into issues last time I tried to update. (savannah web files based on CVS)
<BitPuffin>ah but guix installed info pages that I can read in emacs
<BitPuffin>however I am not sure why in the info directory it doesn't load, feels like I always gotta restart emacs after installing things with guix (especially emacs libs)
<BitPuffin>in either case could open it manually with C-u C-h i
<daviid>mwette: i also use savannah for all my projects, and use sxml, then copy the sxml->html generated pages to the local savannah web pages, then call "cvs commit -m 'Updating blablabla'", which shoud just work for you to, the last command i mean ...
<daviid>mwette: you might 1st wana try "cvs up -d" in your 'local' web page repo, and see if you have conflicts
<ArneBab_>wingo: that you for your great talk/writeup!
<BitPuffin>ArneBab_: linky?
<BitPuffin>or ah this? http://wingolog.org/archives/2023/02/07/whippet-towards-a-new-local-maximum
<janneke>ArneBab_: thank you! :)
<lloda>ACTION is lazy about moving from smobs to fobs
<ArneBab_>lloda: what are fobs?
<lloda>foreign objects
<ArneBab_>ah, thanks!
<lloda>^^
<mirai>is this expected? https://paste.centos.org/view/481b81da
<mirai>my bad, this was for #guix
<mwette>daviid: thanks
<daviid>mwette: np! quite a few of us are hosting on savannah, have to use cvs for the web pages, so if you encounter some difficulties, i think you may ask here, we can try to help (we all tend to forget how cvs works :))
<civodul>too bad psyntax doesn't record the provenance of an expression that's the result of macro expansion
<sneek>Welcome back civodul, you have 1 message!
<sneek>civodul, unmatched-paren says: IT IS DONE. >https://issues.guix.gnu.org/61214>