From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: Vivien Kraus via General Guile related discussions Newsgroups: gmane.lisp.guile.user Subject: Re: foreign objects and the garbage collector Date: Sat, 04 Sep 2021 15:35:23 +0200 Message-ID: <42b93d9ba50eceff320f3dde53ffd6ad77ab6070.camel@planete-kraus.eu> References: Reply-To: Vivien Kraus Mime-Version: 1.0 Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: 8bit Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="35748"; mail-complaints-to="usenet@ciao.gmane.io" User-Agent: Evolution 3.34.2 To: Tim Meehan , guile-user Original-X-From: guile-user-bounces+guile-user=m.gmane-mx.org@gnu.org Sat Sep 04 15:36:03 2021 Return-path: Envelope-to: guile-user@m.gmane-mx.org Original-Received: from lists.gnu.org ([209.51.188.17]) by ciao.gmane.io with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1mMVpz-000944-Pe for guile-user@m.gmane-mx.org; Sat, 04 Sep 2021 15:36:03 +0200 Original-Received: from localhost ([::1]:48250 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1mMVpx-0007V8-S4 for guile-user@m.gmane-mx.org; Sat, 04 Sep 2021 09:36:01 -0400 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]:52656) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mMVpY-0007Uz-EK for guile-user@gnu.org; Sat, 04 Sep 2021 09:35:36 -0400 Original-Received: from planete-kraus.eu ([2a00:5881:4008:2810::309]:42674) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_CHACHA20_POLY1305:256) (Exim 4.90_1) (envelope-from ) id 1mMVpW-0006RU-F0 for guile-user@gnu.org; Sat, 04 Sep 2021 09:35:36 -0400 Original-Received: from planete-kraus.eu (localhost.lan [127.0.0.1]) by planete-kraus.eu (OpenSMTPD) with ESMTP id 5b8727f4; Sat, 4 Sep 2021 13:35:27 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha1; c=relaxed; d=planete-kraus.eu; h= message-id:subject:from:to:date:in-reply-to:references :content-type:mime-version:content-transfer-encoding; s=*; bh=08 WNxE9h/XbXYMmoZiy5KxpB/us=; b=YaBxwIZZEEW9Yl3P1pnJo8jDX1Z9SjNG+U gyf72YrmlXHMFibOU6xk6LskS/5VKLpFhMueDsSxUag4A/3LoU7Zg4M4Yu6GemSL G1Xjpfmpr91SDM65LvSzxLN7Habr/Y6oOFv8bjEdmGAACl7qYb92vmgFRCOfDFbx 1G836PeDc= Original-Received: by planete-kraus.eu (OpenSMTPD) with ESMTPSA id b885f12b (TLSv1.3:AEAD-CHACHA20-POLY1305-SHA256:256:NO); Sat, 4 Sep 2021 13:35:25 +0000 (UTC) In-Reply-To: Received-SPF: pass client-ip=2a00:5881:4008:2810::309; envelope-from=vivien@planete-kraus.eu; helo=planete-kraus.eu X-Spam_score_int: -16 X-Spam_score: -1.7 X-Spam_bar: - X-Spam_report: (-1.7 / 5.0 requ) BAYES_00=-1.9, DKIM_INVALID=0.1, DKIM_SIGNED=0.1, SPF_HELO_PASS=-0.001, SPF_PASS=-0.001 autolearn=no autolearn_force=no X-Spam_action: no action X-BeenThere: guile-user@gnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: General Guile related discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: guile-user-bounces+guile-user=m.gmane-mx.org@gnu.org Original-Sender: "guile-user" Xref: news.gmane.io gmane.lisp.guile.user:17709 Archived-At: 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