From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: divoplade Newsgroups: gmane.lisp.guile.user Subject: Re: Passing SCM values around as void * Date: Mon, 21 Sep 2020 22:32:44 +0200 Message-ID: <502b002d726f0181e2ce3fa0af59865caefa5c20.camel@divoplade.fr> References: <79326277f06bf9b50890a16f54b009e7b2c1a03b.camel@divoplade.fr> 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="9854"; mail-complaints-to="usenet@ciao.gmane.io" User-Agent: Evolution 3.34.2 To: guile-user Original-X-From: guile-user-bounces+guile-user=m.gmane-mx.org@gnu.org Mon Sep 21 22:33:05 2020 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 1kKSUj-0002Tn-F8 for guile-user@m.gmane-mx.org; Mon, 21 Sep 2020 22:33:05 +0200 Original-Received: from localhost ([::1]:43666 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1kKSUi-00065K-6s for guile-user@m.gmane-mx.org; Mon, 21 Sep 2020 16:33:04 -0400 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]:38490) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kKSUY-00065A-C6 for guile-user@gnu.org; Mon, 21 Sep 2020 16:32:54 -0400 Original-Received: from relay4-d.mail.gandi.net ([217.70.183.196]:41151) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kKSUV-0006pQ-Tn for guile-user@gnu.org; Mon, 21 Sep 2020 16:32:54 -0400 X-Originating-IP: 86.194.83.229 Original-Received: from divoplade.home (lfbn-lyo-1-1007-229.w86-194.abo.wanadoo.fr [86.194.83.229]) (Authenticated sender: d@divoplade.fr) by relay4-d.mail.gandi.net (Postfix) with ESMTPSA id 8B11AE0002 for ; Mon, 21 Sep 2020 20:32:45 +0000 (UTC) In-Reply-To: <79326277f06bf9b50890a16f54b009e7b2c1a03b.camel@divoplade.fr> Received-SPF: pass client-ip=217.70.183.196; envelope-from=d@divoplade.fr; helo=relay4-d.mail.gandi.net X-detected-operating-system: by eggs.gnu.org: First seen = 2020/09/21 16:32:46 X-ACL-Warn: Detected OS = Linux 3.11 and newer [fuzzy] X-Spam_score_int: -18 X-Spam_score: -1.9 X-Spam_bar: - X-Spam_report: (-1.9 / 5.0 requ) BAYES_00=-1.9, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H3=0.001, RCVD_IN_MSPIKE_WL=0.001, SPF_HELO_NONE=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:16944 Archived-At: Please ignore, the fix does not work. Le lundi 21 septembre 2020 à 22:18 +0200, divoplade a écrit : > Hello guile users, > > I have just found out a non-reproducible bug in my code on a (more > complex) version of this. Since it is not reproducible anyway, I will > not put a full example. This is just pseudo-code. > > /* This function calls get with ctx until it is satisfied. get should > fill its third argument with as many bytes as its second argument. */ > void work (void *ctx, int (*get) (void *, size_t, char *)); > > /* The guile callback returns a bytevector */ > static void > get_as_scm (void *ctx, size_t n, char *dest) > { > SCM *f = ctx; > SCM ret = scm_call_1 (*f, scm_from_size_t (n)); > SCM_ASSERT (scm_c_bytevector_length (ret) == n, > *f, SCM_ARG1, "work"); > memcpy (dest, SCM_BYTEVECTOR_CONTENTS (ret), n); > } > > static SCM > guile_work (SCM arg) > { > void *ctx = &arg; > work (ctx, get_as_scm); > > // This fixes the bug, it seems. > scm_remember_upto_here_1 (arg); > } > > I do not seem to have a bug if the callback does not allocate a > return > value. > > The underlying question is: how to pass SCM values as void *, and > still > protect them from garbage collection? Do I need to call > scm_remember_upto_here_1 manually like I did, without any hint in the > manual, or is it just hiding the bug? It seems that the problem does > not happen with guile 2.2. > > Best regards, > > divoplade > >