From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: Tim Meehan Newsgroups: gmane.lisp.guile.user Subject: Re: foreign objects and the garbage collector Date: Sat, 4 Sep 2021 19:58:55 -0500 Message-ID: References: <42b93d9ba50eceff320f3dde53ffd6ad77ab6070.camel@planete-kraus.eu> Mime-Version: 1.0 Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="37267"; mail-complaints-to="usenet@ciao.gmane.io" Cc: guile-user Original-X-From: guile-user-bounces+guile-user=m.gmane-mx.org@gnu.org Sun Sep 05 02:59:36 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 1mMgVT-0009Um-DF for guile-user@m.gmane-mx.org; Sun, 05 Sep 2021 02:59:35 +0200 Original-Received: from localhost ([::1]:57710 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1mMgVS-0001c0-DX for guile-user@m.gmane-mx.org; Sat, 04 Sep 2021 20:59:34 -0400 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]:52376) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mMgV4-0001bo-0h for guile-user@gnu.org; Sat, 04 Sep 2021 20:59:10 -0400 Original-Received: from mail-qt1-x833.google.com ([2607:f8b0:4864:20::833]:41731) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1mMgV2-0006dj-HR for guile-user@gnu.org; Sat, 04 Sep 2021 20:59:09 -0400 Original-Received: by mail-qt1-x833.google.com with SMTP id u21so2609648qtw.8 for ; Sat, 04 Sep 2021 17:59:07 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=mime-version:references:in-reply-to:from:date:message-id:subject:cc; bh=1kb6/QEAhjizaFT2qwUJwGIck7+bE1Vtkd6Ynn+wzoA=; b=e0SXuwp2jj5v+Feq3aOTN+pjIjPg4YbEY9YCdXB6BVHxx/5RM79FySW6KW+NAozPpN 3S9Nx6BRJVrxkhrTH3UJzkl3a3qdzXaFc/cGMImt5aqZDskwcEmv+pXdw9E65AOcyTTm zEh+Ttqpsp6kPOY9WiZ31KwN8lXpToRULCVBh+YCWhKMeowudaQMsuXqA1GNHgF7iOTI mZD1z+FutfOl3St8DQttFhm8/WknEx7V7ZJ658cS/5pVbBsk1HCqIZG/KNDpUY1UQ60w eLW9b7b+kUC484ARgjRipX+/VRIz8fi33FIxoKsIH04ihqxUmu7Rm3AcLuIhiINui49Y euFQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:cc; bh=1kb6/QEAhjizaFT2qwUJwGIck7+bE1Vtkd6Ynn+wzoA=; b=gMkhWmWRLm5rYDz/T0KF+mZ9Xf/xhUCMeY4UBuTCm4E78yjPU93ZSYjjkYYz+CxUsI CnZqMo4H4fQ4/SA9AjKDptuPhMmXJp7Qf18KHHGm0SBQUI96tWt2Sfe4LfTkMB1IazIL 4oEv4SYLGB1TUsTTB+0r3lGLbxVjy7WFTyLkt0LGriGhhqXclL7dk1wvAYuSRA6LqS8V eyxAF4/VloadVHB5Ot00BmClaq0aO/UBUrpSUhA1/3u/Xqj6m1myZawXrhgvdaKo7ZDO xerz3gUrtLX3Kb6rvpBHk/IkJQDWA4I5BQWMC9D9naC3Hwas19nnUAARIaxQM/MIf/5I TXQA== X-Gm-Message-State: AOAM532WYtt1Jrrqd4nSgHgDlg3NKy4lfGo85tj53eqqRRpw+fRIjone H9FfWjO7CbQ3L7jmvCXkEpWAGkKX0auhEEaKtlxLzKIX X-Google-Smtp-Source: ABdhPJxpa/QVBw0PpWbc982wy4yiGDocTfP6pXc9YrdhtRflPmH8Zfyw5lPounGft7CuDg+rxpxPoZ8gyKkKgt7LZqE= X-Received: by 2002:a05:622a:c6:: with SMTP id p6mr5463282qtw.35.1630803546651; Sat, 04 Sep 2021 17:59:06 -0700 (PDT) In-Reply-To: <42b93d9ba50eceff320f3dde53ffd6ad77ab6070.camel@planete-kraus.eu> Received-SPF: pass client-ip=2607:f8b0:4864:20::833; envelope-from=btmeehan@gmail.com; helo=mail-qt1-x833.google.com X-Spam_score_int: -10 X-Spam_score: -1.1 X-Spam_bar: - X-Spam_report: (-1.1 / 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, FREEMAIL_FROM=0.001, HTML_MESSAGE=0.001, MISSING_HEADERS=1.021, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=no autolearn_force=no X-Spam_action: no action X-Content-Filtered-By: Mailman/MimeDel 2.1.23 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:17711 Archived-At: Thanks Vivien, I had not considered dynamic-wind. I'll look into that a bit more. Cheers, Tim On Sat, Sep 4, 2021 at 8:35 AM Vivien Kraus wrote= : > Hello, > > Le samedi 04 septembre 2021 =C3=A0 07:41 -0500, Tim Meehan a =C3=A9crit : > > I'd rather not compile anything in C, and just use the tools in Guile t= o > > interact with libgps. Is there a way to get Guile's garbage collector t= o > > 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=E2= =80=99s > not just freeing resources, and the garbage collector does not have a > chance to run, then it=E2=80=99s another problem. However, I > doubt your library does something like that). > > If you want to avoid the problem, you should explicitely bind and call th= e > 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 > >