IRC channel logs

2024-06-03.log

back to list of logs

<lechner>Hi, i'd like to construct argv and argc for the foreign function interface. It's kind of the reverse of scm_makfromstrs, except in Guile. Will the following code help? https://git.savannah.gnu.org/cgit/g-golf.git/tree/g-golf/gi/utils.scm?h=devel#n340
<lechner>the argc is no issue, but I can't get the argv right
<janneke>lechner: seen this https://lists.gnu.org/archive/html/guix-devel/2024-06/msg00029.html ?
<janneke>ACTION just leaves make, bespoke, potato-make here too ;)
<wingo>rapprochement with ESR is a terrible idea :)
<dthompson>I saw this email when I was very much not awake and was baffled why I was seeing mail from esr
<civodul>bah, and seriously, what’s up with the name
<lechner>janneke / thanks for that pointer! first time i read about it. that work has great potential, although having spent some time with Guile I'm not sure any Makefile is human-friendly. "Autodafe's aim is to convert Autotools build recipes into a bare makefile that is human friendly."
<janneke>lechner: yeah
<lechner>civodul / the name refers to a gruesome step that resembled a public exorcism in the Spanish inquisition, which targeted Jews who converted to Christianity in order to avoid expulsion in 1492 but secretly practiced their old religion. https://en.wikipedia.org/wiki/Auto-da-f%C3%A9
<janneke>but what's interesting is that esr is very open to guile (personally, possibly not for the project), and also that i figured the parsing auto* and translating it is the hard bit; whether to spew out the recipes in make or guile might be "just add another backend"
<lechner>janneke / yeah, i'm watching!
<lechner>although he picked python
<janneke>yeah, masochist
<lechner>you have to be, in order to work on Autotools. Plus, it's a relief compared to m4
<janneke>yeah, much respect to pick this up; and i guess python is a sane choice
<janneke>ACTION rather means: there's a lovely pick of much worse choices than python ;)
<civodul>lechner: yeah, i know what it means, and i don’t like to see this word here
<civodul>but yeah, esr…
<old>so is the idea to convert autotools stuff to readable makefile for all packages?
<lechner>hi, why do pointers from string->pointer look like 32-bits on my equipment?
<old>lechner: what do you mean by look like 32-bits?
<lechner>old / $15 = #<pointer 0x1810cb0>
<old>((@ (system foreign) string->pointer) "foo") => $1 = #<pointer 0x7aedc0>
<old>hm
<old>so indeed the string is raw at this address (confirmed with GDB). So the printer simply omit to print leading 0
<old>the string is allocated in the heap
<lechner>old / ok, thanks! what's a good way to get a pointer to that pointer, please?
<old>I'm not sure to understand what you mean. You want a pointer that points to this string like (char **) but in Guile?
<lechner>not quite. for use with a foreign library, i hope to pass a pointer to the C pointer that points to string
<old>what's the signature of the foreign library call?
<lechner>i think that's a wrapped pointer to the unwrapped pointer to the string
<lechner>char **argv
<old>okay then I think you could do the following
<mwette>lechner: you'll need to generate a bytevector of the pointer-address(es) and convert that to a pointer to pass
<mwette>I assume you're still talking about passing char *argv[]
<old>mwette: I'm trying that without much success
<weary-traveler>what's the guile way to combine path components? something that handles file-name-separator-string appropriately. does such a convenience function exist?
<old>weary-traveler: no. But I do have some WIP module that implement paths stuffs like racket
<lechner>mwette / same project from two years ago. Guile-PAM is done, but this is the last piece
<old>weary-traveler: You just do string-append. the OS usually ignore double // in path anyway
<weary-traveler>old: sounds like your module will be helpful. thanks for the confirmation regd this situation
<old>mwette: okay did it. You must not passed with pointer->bytevector
<lechner>old / how?
<mwette>I think you need string->pointer, pointer-address, bytevector-u64-native-set!, bytevector->pointer
<old> https://paste.sr.ht/~old/4d00bda544f67e93bf6939d838c68e09f7bd89a9
<old>using a setter ought to be faster than ^
<old>weary-traveler: https://paste.sr.ht/~old/91c83b2bcfa2ef99e09eec6500270d9146236e50
<old>I have not touched this for months. I don't recall if it supports Windows paths
<weary-traveler>thanks for sharing. i am a little surprised something like this isn't in the standard libraries
<mwette>I think it is, I can't find it.
<lechner>mwette / yay, it worked!
<lechner>thanks so much! now i have to pass more than one string, and perhaps be more conscious of other architectures
<lechner>mwette / two years ago, you or perhaps daviid wrote I also have to keep the reference alive across the call. is that still true? it seems to wprk without
<mwette>Yes, you want to do that. If GC executes during the call that could be bad.
<lechner>mwette / thanks! i can't pass two strings. was the idea that i can write the second pointer using the index feature like this (bytevector-u64-native-set! bv 1 raw-address)
<lechner>okay, i have to use index 8
<mwette>you need to size the bytevector = (* argc (sizeof '*)) and use (bytevector-u64-native-set! bv (* i 8) ith-raw-address), assuming your pointers are 8 bytes
<mwette>i starting at 0
<lechner>wow, you are such a genius. i can only imaging the sweat and tears you went through writing ffi-helper!
<lechner>it's working
<mwette>:)
<lechner>you should get a prize
<lechner>wow, it's working. the last piece. calling legacy pam modules from Guile-PAM
<lechner>also, Guile is so underrated
<lechner>mwette / should GC ever executing during a foreign function call?
<lechner>execute
<mwette>guile is multi-threaded, so you have to assume it may
<lechner>ok, thanks!
<lechner>is a pointless, unassigned reference like (list argv) enough to keep the variable alive, or will it be optimized away?
<dthompson>if you follow along with spritely stuff or are interested in lisp game dev, you will probably enjoy this new blog post: https://spritely.institute/news/cirkoban-sokoban-meets-cellular-automata-written-in-scheme.html
<old>lechner: to protect from GC, the object needs to be protected, not just the pointer. This can be difficult. Wingo talks about it in one of his blog post. I think the trivial solution is to return the reference. That way, the compile is forced to keep the reference in the entire procedure
<janneke>mwette: do you know off-hand what nyacc 1.09.7 uses from (rnrs arithmetic bitwise) (in nyacc/lang/sx-util.scm)
<janneke>mes does not have (rnrs arithmetic bitwise) yet
<janneke>*err, 1.09.4
<janneke>mwette: headsup, some tags seem to be mising (1.08.7, 1,09.3, 1.09.4)
<janneke>oh, it seems (rnrs arithmetic bitwise) isn't needed for guile-3 or mes
<janneke>hmm, guess i'll add an empty module to mes then
<janneke>hmm, we already have that, just not a guile-style variant
<janneke>oops, sorry for the noise, thanks for listening! :)
<daviid>old, mwette and lechner: afaict, string->pointer makes a copy of the string, to produce a null terminated string, so cmiiw, but you don't need to keep a ref to the original string, just the result of the string->pointer call - and as in the char **argv argument, as you need to construct a bytevector, just olding a ref to the bv (or even just the bytevector->pointer (?)) should be enough to protect the bv and its content from being gc'ed
<daviid>lechner: yes, you could have re-used https://git.savannah.gnu.org/cgit/g-golf.git/tree/g-golf/gi/utils.scm?h=devel#n340 'out of the box - it returns both the bv-ptr, and the list of the pointers to the strings, probably not needed, but .. fine
<daviid>lechner: nearly 'out of the box', as you do not use g-golf, it needs a few adaptation, p-size as (sizeof '*), probably rename o-ptr to bv-ptr, renaming the procedure and not keeping intermediate ptr (nor return them) should be fine
<daviid>oh well, you also need to snarf https://git.savannah.gnu.org/cgit/g-golf.git/tree/g-golf/support/bytevector.scm?h=devel - from line 73 to 102, in a module and exporting bv-ptr-ref, bv-ptr-set!