guile-user
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: foreign objects and the garbage collector


From: Vivien Kraus
Subject: Re: foreign objects and the garbage collector
Date: Sat, 04 Sep 2021 15:35:23 +0200
User-agent: Evolution 3.34.2

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 via email to

[Prev in Thread] Current Thread [Next in Thread]