Re: Need help understanding how scm_init_guile works (with FUSE)

Nala Ginrut <[email protected]>
Newsgroups gmane.lisp.guile.user
Message-ID <CAPjoZoeut9kkwrs7zwac6JSY_RDfFj252WpBWLfhh4Eb7jZ67g@mail.gmail.com>
Hi Daniel!
Just simply took a glance at the code, I'm curious why you don't just call
scm_init_guile() in fuse operation init function?
This should let you call scm_init_guile() just once.

Best regards.


On Mon, Mar 3, 2025 at 6:41 PM Daniel Littlewood via General Guile related
discussions <[email protected]> wrote:

> Hi guile-users,
>
> I am working on a guile program to interact with FUSE. The code is at
> https://gitlab.com/danielittlewood0/diffuse. I have managed to get it to
> basically work, but there are some things I don't understand. It
> consists of essentially two files at the moment:
>
>   * other.scm, which implements the actual logic of the filesystem in
> guile.
>   * hello.c, which does the plumbing into the FUSE library.
>
> I managed to get it to work by doing the following in each of the FUSE
> handlers:
>
> scm_init_guile()
> scm_c_primitive_load("/full/path/to/other.scm")
> scm_call_1(scm_variable_ref(scm_c_lookup("whatever-function-I-want")))
>
> That worked fine, but I was a bit confused about having to call
> scm_init_guile so many times. I expected to just call it once in main
> and then never again. If I do that, i.e. just move scm_init_guile to
> main and remove all the other callers (rest of the code unchanged) I get
> a segfault.
>
> I was also surprised that I had to give the absolute file path of my
> guile script to scm_c_primitive_load. If I called it from main then I
> didn't have to do that. If I call scm_c_primitive_load from main then I
> can give a relative path, but from e.g. hello_read I get a "No such file
> or directory" error and have to provide the absolute path.
>
> I think this is something peculiar to how FUSE is set up, but I don't
> know what exactly. I don't actually call the handlers, I pass the
> function pointers to the library and the library calls them for me. For
> instance if I try to print the current working directory from within one
> of the handlers, I get / - which probably refers to the root of the FUSE
> filesystem tree. I managed to avoid giving the absolute path by calling
> scm_init_guile() and then scm_c_primitive_load("other.scm") from main.
> This works (with the relative path). What's surprising to me is:
>
>   * I still have to call scm_init_guile before every use of guile within
>     the current function, even if I called it in main.
>   * When I call scm_init_guile a second time, I don't have to call
>     scm_primitive_load a second time. I can just call scm_variable_ref
>     immediately.
>
> This is a bit confusing to me. I could understand if I had to load the
> code every time I call scm_init_guile (although then I'd want to reduce
> the boilerplate) and I could understand calling scm_init_guile and
> scm_c_primitive_load only once, but the arrangement above doesn't make
> sense to me. I feel like I must be missing something.
>
> Note that this is the first project I've really written in either C or
> guile, so I might be missing something obvious.
>
> Best wishes,
> Dan
>
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.