From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: adriano Newsgroups: gmane.lisp.guile.user Subject: Re: foreign objects and the garbage collector Date: Sun, 19 Sep 2021 08:14:39 +0200 Message-ID: References: <42b93d9ba50eceff320f3dde53ffd6ad77ab6070.camel@planete-kraus.eu> 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="30822"; mail-complaints-to="usenet@ciao.gmane.io" To: guile-user Original-X-From: guile-user-bounces+guile-user=m.gmane-mx.org@gnu.org Sun Sep 19 08:16:18 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 1mRq7e-0007nV-53 for guile-user@m.gmane-mx.org; Sun, 19 Sep 2021 08:16:18 +0200 Original-Received: from localhost ([::1]:33078 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1mRq7c-0003uy-FI for guile-user@m.gmane-mx.org; Sun, 19 Sep 2021 02:16:16 -0400 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]:35936) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mRq6Z-0003un-DJ for guile-user@gnu.org; Sun, 19 Sep 2021 02:15:11 -0400 Original-Received: from mx1.riseup.net ([198.252.153.129]:55128) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mRq6V-0005tG-PI for guile-user@gnu.org; Sun, 19 Sep 2021 02:15:11 -0400 Original-Received: from fews1.riseup.net (fews1-pn.riseup.net [10.0.1.83]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256 client-signature RSA-PSS (2048 bits) client-digest SHA256) (Client CN "fews1.riseup.net", Issuer "R3" (not verified)) by mx1.riseup.net (Postfix) with ESMTPS id 4HBy8n0b36zDsdh; Sat, 18 Sep 2021 23:15:05 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=riseup.net; s=squak; t=1632032105; bh=yuKUN6h4KBZ3OVBYouWprJMjAhAsvdN+/Lh3qjy8UvU=; h=Subject:From:To:Cc:Date:In-Reply-To:References:From; b=ZX4RABkvkdM+S/vabexrDE9Oh2U9jnzeqEa+KbqP/8ZkCMKGKfn+n5WN5s2igOr4c 2jqhLgYjop5R0EDzlSaU2X8/MmcPZlR5S/0A/m/r1BD9hP9DPtcdrupZTnQ1ngz8Sm 6i/Tu/fJBdDqa2VSLZ5CYqTNzVwz6g/oocSMDJ2w= X-Riseup-User-ID: E3E66CB7BDA87B01B81FCEA8241502858D70B010C7306AE76ADD6D52418BA779 Original-Received: from [127.0.0.1] (localhost [127.0.0.1]) by fews1.riseup.net (Postfix) with ESMTPSA id 4HBy8l21mPz5vNL; Sat, 18 Sep 2021 23:15:03 -0700 (PDT) In-Reply-To: <42b93d9ba50eceff320f3dde53ffd6ad77ab6070.camel@planete-kraus.eu> Received-SPF: pass client-ip=198.252.153.129; envelope-from=randomlooser@riseup.net; helo=mx1.riseup.net X-Spam_score_int: -27 X-Spam_score: -2.8 X-Spam_bar: -- X-Spam_report: (-2.8 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_LOW=-0.7, RCVD_IN_MSPIKE_H3=0.001, RCVD_IN_MSPIKE_WL=0.001, SPF_HELO_PASS=-0.001, SPF_PASS=-0.001 autolearn=ham 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:17749 Archived-At: Il giorno sab, 04/09/2021 alle 15.35 +0200, Vivien Kraus via General Guile related discussions ha scritto: > 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. It'd be so nice to have an example > That being said, make-pointer (from (system foreign-library)) is > probably what you are expecting. It should work with gps_close. Another exmple of what you mean, here, would be so nice :-)