unofficial mirror of guile-devel@gnu.org 
 help / color / mirror / Atom feed
From: Jean Abou Samra <jean@abou-samra.fr>
To: "Dr. Arne Babenhauserheide" <arne_bab@web.de>
Cc: guile-devel@gnu.org
Subject: Re: Minimal example of extending Guile with Rust?
Date: Mon, 29 Jan 2024 16:31:03 +0100	[thread overview]
Message-ID: <7B5F7998-3F58-4665-A68B-856B0C8A792B@abou-samra.fr> (raw)

[-- Attachment #1: Type: text/plain, Size: 1335 bytes --]


There are a number of crates with Rust bindings to the Guile C API: https://lib.rs/search?q=guile

Most of them are just the result of running the bindgen tool, which autogenerates Rust bindings from C header files. A few of them have slightly more convenient wrapper but none is really well-developed AFAICS.

Honestly, I think the easiest at this time is to do the interfacing with Guile from C. Create a Rust module which exports a function through C FFI, and convert between C and Guile types in C. Alternatively, use the Guile FFI facilities for the conversion. It is probably simpler than doing these conversions in Rust. It is, in any case, safer, because I'm quite sure that the Rust compiler will be happy to do optimizations that defeat conservative GC, by hiding pointers in local variables (which Rust can more easily do, thanks to its aliasing guarantees).

Be careful with calling Guile code from Rust code. This is fraught, because Guile code can raise exceptions, which are basically propagated through longjmp, and it is UB in Rust to unwind through Rust code with longjmp. Basically, if you call Guile from Rust then it must be wrapped in exception handling. An exception must not propagate through Rust stack frames. call/cc would be a problem too, so you likely want to use with-continuation-barrier.


[-- Attachment #2: Type: text/html, Size: 1838 bytes --]

             reply	other threads:[~2024-01-29 15:31 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-01-29 15:31 Jean Abou Samra [this message]
  -- strict thread matches above, loose matches on Subject: below --
2024-01-29 15:04 Minimal example of extending Guile with Rust? Dr. Arne Babenhauserheide
2024-01-29 15:33 ` Olivier Dion
2024-01-29 15:49 ` M

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=7B5F7998-3F58-4665-A68B-856B0C8A792B@abou-samra.fr \
    --to=jean@abou-samra.fr \
    --cc=arne_bab@web.de \
    --cc=guile-devel@gnu.org \
    /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).