From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: Maxime Devos Newsgroups: gmane.lisp.guile.user Subject: Re: Need help embedding Guile Date: Tue, 21 Dec 2021 11:37:45 +0000 Message-ID: <2a789e248ef8d1922caec7af553cf26e9b360619.camel@telenet.be> References: 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="3412"; mail-complaints-to="usenet@ciao.gmane.io" User-Agent: Evolution 3.38.3-1 To: Dimitris Papavasiliou , "guile-user@gnu.org" Original-X-From: guile-user-bounces+guile-user=m.gmane-mx.org@gnu.org Tue Dec 21 12:38:35 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 1mzdTW-0000jN-Ab for guile-user@m.gmane-mx.org; Tue, 21 Dec 2021 12:38:34 +0100 Original-Received: from localhost ([::1]:54320 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1mzdTU-0003sG-K8 for guile-user@m.gmane-mx.org; Tue, 21 Dec 2021 06:38:32 -0500 Original-Received: from eggs.gnu.org ([209.51.188.92]:52080) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mzdT1-0003rm-IV for guile-user@gnu.org; Tue, 21 Dec 2021 06:38:05 -0500 Original-Received: from [2a02:1800:120:4::f00:13] (port=33624 helo=baptiste.telenet-ops.be) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1mzdSv-0001D1-WA for guile-user@gnu.org; Tue, 21 Dec 2021 06:38:01 -0500 Original-Received: from ptr-bvsjgyhxw7psv60dyze.18120a2.ip6.access.telenet.be ([IPv6:2a02:1811:8c09:9d00:3c5f:2eff:feb0:ba5a]) by baptiste.telenet-ops.be with bizsmtp id Yzdl2600e4UW6Th01zdmBW; Tue, 21 Dec 2021 12:37:46 +0100 In-Reply-To: DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=telenet.be; s=r21; t=1640086666; bh=DypBr6olqpXrx/YV2aLdBruvalqBdJuHtnjsVl/GMxg=; h=Subject:From:To:Date:In-Reply-To:References; b=a9uVBX/w3r9qxIJ9eEiAQ0KUi7Hu7ml/EO8XvtcJeegYwVQtZvZzhf4C8b/p3uyzL nn5pBXUdR3STJTeF7Bgkr53rV1DkpLoDw/etf9S4+TIaODJJm/bGfByrMS2sJAZrpW PPpVal7iy8MuhdxMZyu4JsYpbwIUZ5zQhprALZnUPG7Qsl0YEVQyT9JkdzJMnZTUCv W1Tz8IT00H9IkOYz1NjS6I82xY1pgY8a8t1OpREOFGpvlLTVW6WZtqENMPmGqy81Lf kSY6zymaEzjCjmWez5JNU9SDXcCW4xV6BsmbJ+o3zkLGQJhzuGt1c1+KRVv1d/ULt5 1OozX8tP0M7ig== X-Host-Lookup-Failed: Reverse DNS lookup failed for 2a02:1800:120:4::f00:13 (failed) Received-SPF: pass client-ip=2a02:1800:120:4::f00:13; envelope-from=maximedevos@telenet.be; helo=baptiste.telenet-ops.be X-Spam_score_int: -19 X-Spam_score: -2.0 X-Spam_bar: -- X-Spam_report: (-2.0 / 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, RCVD_IN_DNSWL_LOW=-0.7, RDNS_NONE=0.793, SPF_HELO_NONE=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.29 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:17894 Archived-At: Dimitris Papavasiliou schreef op di 21-12-2021 om 11:12 [+0000]: > [1...] > . The manual is not very specific about how and when finalizers are > run.  The >    approach above seems to correctly finalize all objects created as > the Scheme >    code executes, but if references are kept, say via (define), they > are not >    finalized and I get memory leaks.  Is there some way to arrange > for the >    complete deinitialization of Guile after I've finished evaluating > Scheme code >    and making sure that all finalizers are run? The manual is not very specific on when finalizers are run, because there aren't many formal guarantees (e.g., BDW-GC is a conservative GC, so it might think an object is not finalizable even though it is). About deinitialising guile: I don't know. About finalizers: No. From the BDW-GC faq: I want to ensure that all my objects are finalized and reclaimed before process exit. How can I do that? You can't, and you don't really want that. This would require finalizing reachable objects. Finalizers run later would have to be able to handle this, and would have to be able to run with randomly broken libraries, because the objects they rely on where previously finalized. In most environments, you would also be replacing the operating systems mechanism for very efficiently reclaiming process memory at process exit with a significantly slower mechanism. You do sometimes want to ensure that certain particular resources are explicitly reclaimed before process exit, whether or not they become unreachable. Programming techniques for ensuring this are discussed in ``Destructors, Finalizers, and Synchronization'', Proceeedings of the 2003 ACM SIGPLAN-SIGACT Symposium on Principles of Programming Languages, Jan. 2003, pp. 262-272. Official version. Technical report version. HTML slides. PDF slides. > 2. If, in `run_body', I simply do > >        scm_c_primitive_load(context->input); > >    then the code is evaluated, but on error I get no locations in the > stack >    trace.  The error is said to have occurred "in an unknown file" > with no line >    numbers.  Evaluating `load' as shown above, seems to produce > proper source >    locations in the stack trace.  Is there something else I should be > preferably >    doing? Due to bootstrapping reasons, there are multiple readers and evaluators in Guile, of varying debugability. I'm not 100% sure, but I think the 'primitive-load' reader+evaluator has low debugability and the 'load' procedure has higher debugability? > 3. More generally, is there a preferable way to go about embedding > Guile for my >    use case? Instead of reinitialising and deinitialising guile repeatedly (seems inefficient!), I would suggest initialising Guile once at program start and do Guile stuff whenever needed. However, that might be incompatible with your memory management approach ... Greetings, Maxime.