unofficial mirror of guile-user@gnu.org 
 help / color / mirror / Atom feed
From: Vivien Kraus via General Guile related discussions <guile-user@gnu.org>
To: Tim Meehan <btmeehan@gmail.com>, guile-user <guile-user@gnu.org>
Subject: Re: foreign objects and the garbage collector
Date: Sat, 04 Sep 2021 15:35:23 +0200	[thread overview]
Message-ID: <42b93d9ba50eceff320f3dde53ffd6ad77ab6070.camel@planete-kraus.eu> (raw)
In-Reply-To: <CACgrOxLjPgUv2wtGbe+nqrAYxKc1BdeQYZ=M1ixGcVyPztK9GA@mail.gmail.com>

Hello,

Le samedi 04 septembre 2021 à 07:41 -0500, Tim Meehan a écrit :
> I'd rather not compile anything in C, and just use the tools in Guile to
> interact with libgps. Is there a way to get Guile's garbage collector to
> call "gps_close" on the opaque structure returned by "gps_open"?
I think it would be best to do it yourself. Maybe the garbage collector will not run immediately (if at all), and if each creation uses "precious" resources (such as file descriptors), you might run
into a shortage before the garbage collector is triggered. This is not considered by people writing the C API of course, because they assume you would close the thing as soon as possible. (Also, if
calling the close function is mandatory, for instance to run code that’s not just freeing resources, and the garbage collector does not have a chance to run, then it’s another problem. However, I
doubt your library does something like that). 

If you want to avoid the problem, you should explicitely bind and call the gps-close function and not rely on the garbage collector to do it for you. You can use dynamic-wind to open and close
resources as needed.

That being said, make-pointer (from (system foreign-library)) is probably what you are expecting. It should work with gps_close.

Best regards,

Vivien




  reply	other threads:[~2021-09-04 13:35 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-09-04 12:41 foreign objects and the garbage collector Tim Meehan
2021-09-04 13:35 ` Vivien Kraus via General Guile related discussions [this message]
2021-09-05  0:58   ` Tim Meehan
2021-09-19  6:14   ` adriano
2021-09-19 18:11     ` Olivier Dion via General Guile related discussions
2021-09-19 18:23       ` Maxime Devos
2021-09-21 14:26         ` adriano
2021-09-21 18:49           ` Maxime Devos
2021-09-21 14:00       ` adriano
2021-09-21 14:25         ` Olivier Dion via General Guile related discussions
2021-09-21 14:51           ` adriano

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=42b93d9ba50eceff320f3dde53ffd6ad77ab6070.camel@planete-kraus.eu \
    --to=guile-user@gnu.org \
    --cc=btmeehan@gmail.com \
    --cc=vivien@planete-kraus.eu \
    /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).