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: Passing SCM values around as void * Date: Mon, 21 Sep 2020 22:18:29 +0200 Message-ID: <79326277f06bf9b50890a16f54b009e7b2c1a03b.camel@divoplade.fr> Mime-Version: 1.0 Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: 7bit Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="30247"; 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:19:15 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 1kKSHK-0007lQ-SO for guile-user@m.gmane-mx.org; Mon, 21 Sep 2020 22:19:14 +0200 Original-Received: from localhost ([::1]:39898 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1kKSHJ-0003KF-SC for guile-user@m.gmane-mx.org; Mon, 21 Sep 2020 16:19:13 -0400 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]:35378) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kKSGn-0003Jj-O4 for guile-user@gnu.org; Mon, 21 Sep 2020 16:18:42 -0400 Original-Received: from relay3-d.mail.gandi.net ([217.70.183.195]:44397) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kKSGi-00053e-B7 for guile-user@gnu.org; Mon, 21 Sep 2020 16:18:41 -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 relay3-d.mail.gandi.net (Postfix) with ESMTPSA id 298A360007 for ; Mon, 21 Sep 2020 20:18:29 +0000 (UTC) Received-SPF: pass client-ip=217.70.183.195; envelope-from=d@divoplade.fr; helo=relay3-d.mail.gandi.net X-detected-operating-system: by eggs.gnu.org: First seen = 2020/09/21 16:18:30 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:16943 Archived-At: 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