From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: Olivier Dion via General Guile related discussions Newsgroups: gmane.lisp.guile.user Subject: Re: Need help embedding Guile Date: Wed, 22 Dec 2021 09:46:28 -0500 Message-ID: <878rwcsnnf.fsf@laura> References: <2a789e248ef8d1922caec7af553cf26e9b360619.camel@telenet.be> <87ee65shtv.fsf@laura> Reply-To: Olivier Dion Mime-Version: 1.0 Content-Type: text/plain Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="14770"; mail-complaints-to="usenet@ciao.gmane.io" Cc: Maxime Devos , "guile-user@gnu.org" To: Dimitris Papavasiliou Original-X-From: guile-user-bounces+guile-user=m.gmane-mx.org@gnu.org Wed Dec 22 15:47:08 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 1n02tX-0003aB-VP for guile-user@m.gmane-mx.org; Wed, 22 Dec 2021 15:47:07 +0100 Original-Received: from localhost ([::1]:39666 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1n02tW-0003GD-2L for guile-user@m.gmane-mx.org; Wed, 22 Dec 2021 09:47:06 -0500 Original-Received: from eggs.gnu.org ([209.51.188.92]:58118) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1n02t4-0003DN-4u for guile-user@gnu.org; Wed, 22 Dec 2021 09:46:38 -0500 Original-Received: from smtp.polymtl.ca ([132.207.4.11]:40068) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1n02t1-0002Ta-Mw for guile-user@gnu.org; Wed, 22 Dec 2021 09:46:37 -0500 Original-Received: from localhost (modemcable094.169-200-24.mc.videotron.ca [24.200.169.94]) by smtp.polymtl.ca (8.14.7/8.14.7) with ESMTP id 1BMEkSkb016063 (version=TLSv1/SSLv3 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Wed, 22 Dec 2021 09:46:33 -0500 DKIM-Filter: OpenDKIM Filter v2.11.0 smtp.polymtl.ca 1BMEkSkb016063 In-Reply-To: X-Poly-FromMTA: (modemcable094.169-200-24.mc.videotron.ca [24.200.169.94]) at Wed, 22 Dec 2021 14:46:28 +0000 Received-SPF: pass client-ip=132.207.4.11; envelope-from=olivier.dion@polymtl.ca; helo=smtp.polymtl.ca X-Spam_score_int: -41 X-Spam_score: -4.2 X-Spam_bar: ---- X-Spam_report: (-4.2 / 5.0 requ) BAYES_00=-1.9, RCVD_IN_DNSWL_MED=-2.3, 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.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:17902 Archived-At: On Wed, 22 Dec 2021, Dimitris Papavasiliou wrote: > Foreign objects currently come in two categories: > > 1. Complete geometric operations such as `cube' and `difference' > above. These are allocated on the C++ side and a so-called "smart > pointer" (shared_ptr) is exported to Scheme. Failure to finalize > this retains a reference on the C++ side, which would prevent > destroying the operation. Since these can get quite large in terms > of memory, destroying them after they're no longer needed can be > essential. Since you have a graph of all the primitives in the second phase, you're basicaly doing garbage collection there. But from: > Creating the complete graph before evaluation begins in the second > phase is probably not necessary (nodes could be evaluated as they're > created), but it creates the opportunity for certain optimizations > (like dead code elimination for instance). This makes some sort of > forcing/ensuring that Guile has terminated desirable. If I understood, objects can be garbage before phase 2, thus not appearing in the final graph of operations. > One idea would be to simply call `scm_gc()' and `scm_run_finalizers()' > until the latter returns 0. As far as I can see, this should ensure > all finalizers are called, assumming no references to any foreign > objects remain, but I see no way of ensuring the latter short of > process termination... One way I think you could do this is to evaluate all the user operations in a sandbox environment. Example: -------------------------------------------------------------------------------- (use-modules (ice-9 sandbox)) ;; ... (let ([mod (make-sandbox-module (cons '((my-app primitives)) all-pure-bindings))]) (eval-in-sandbox '(eval-user-file "...") #:module mod)) -------------------------------------------------------------------------------- >From `eval-in-sandbox` documentation: If SEVER-MODULE? is true (the default), the module will be unlinked from the global module tree after the evaluation returns, to allow MOD to be garbage-collected. So I _think_ you're guarantee here that all references in your module will be garbage collected. You can then do a single `gc/finalizer`. -- Olivier Dion Polymtl