From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: Chris Vine Newsgroups: gmane.lisp.guile.user Subject: Re: Calling back scheme from C Date: Tue, 22 Sep 2020 10:50:26 +0100 Message-ID: <20200922105026.5783d9ab0dd3641391cdd8c9@gmail.com> References: <3a0ccd31a195f1544038b4ccc5ff1d15667a8e0d.camel@divoplade.fr> Mime-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="22606"; mail-complaints-to="usenet@ciao.gmane.io" To: guile-user@gnu.org Original-X-From: guile-user-bounces+guile-user=m.gmane-mx.org@gnu.org Tue Sep 22 11:51:30 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 1kKexN-0005kp-Mq for guile-user@m.gmane-mx.org; Tue, 22 Sep 2020 11:51:29 +0200 Original-Received: from localhost ([::1]:54904 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1kKexM-0006zk-Ou for guile-user@m.gmane-mx.org; Tue, 22 Sep 2020 05:51:28 -0400 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]:44542) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kKewm-0006y5-E7 for guile-user@gnu.org; Tue, 22 Sep 2020 05:50:52 -0400 Original-Received: from mail-wm1-x32b.google.com ([2a00:1450:4864:20::32b]:52258) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1kKewk-0001F4-OX for guile-user@gnu.org; Tue, 22 Sep 2020 05:50:52 -0400 Original-Received: by mail-wm1-x32b.google.com with SMTP id q9so2647472wmj.2 for ; Tue, 22 Sep 2020 02:50:50 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=date:from:to:subject:message-id:in-reply-to:references:mime-version :content-transfer-encoding; bh=/Qa8LMVNFIPhI69/dZoxH/SOXHNAgjXCTWrsTPF5sik=; b=Z4sRlwYKertFyyVhatAurJ1eseejZY29rUuXpVpuPKJKdubXplFQ8JHyu+53UCJ8xU gQR8sNSsypKzVAti0nsVm1+48bJZUQXXvZjMEqIPZWLEWiGircANp69+kaCqMkwVUvLn fDZCms6wyzE00qEu5oyPo9z8mt2OJRvhbsux+0ci1bkBfUwAQxyY2VzdknLl/0+nYQMv HHO8P8gfr/duYLtYmKFhAup00m1GCRuXpuDlHzD6K+PzZDtoDqwRfYGRhovX4EIU4O8O RyH+qx1CGie4MPrL4EG8xyruQXIAxvXMiqbKNMFd3Rh3JuDqPHsNgP+mFD/6WSuaHpoJ YZpg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:subject:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=/Qa8LMVNFIPhI69/dZoxH/SOXHNAgjXCTWrsTPF5sik=; b=s8QAgh0RYKvJvrTGLcMwFxoirRCTQOET80HEZ97DWvYYCbF1wr8RRoNKwmA++UP1q2 9/auR5hBW/Fs5vA2cDba0y4TxOCj3ZfYKsm2IdHAsVBpRRb5mjiag4ZEarobMiDSuVYw WoSurMSA1v0vPxcczVa+xLEg9b4hW/ENRkkZqCzhX4L+miWgmUTA7xGGf1fp0pS0LVBX cHRtINFIhwUYlMbWjtaFTsqr7cxtK/ULPax/WpeqSxbC06kkXSQK3CdKvB9dnRHVM1+K mu8GXJ5Vne3DZU8Onba+V++If8E9izEiS+YN9euE9AgRdLt1UzwysmU2u2GIh5kOhOEr rDZw== X-Gm-Message-State: AOAM5335dUlhmgAKEJ71nk//vPGIl8uZmpjmdkFSV4w+i6DcQ2Sv21zw x325Vqloyk/lAWZnMk1vEE0gRVLsL0w= X-Google-Smtp-Source: ABdhPJzJ6kLYz3Xb1kI5FXwfs209DSm4CiC3pSgZ27xm6lB2L+pJBgq/4NVM5dLksHHP56mEDRcOCQ== X-Received: by 2002:a1c:7f8b:: with SMTP id a133mr51117wmd.155.1600768248722; Tue, 22 Sep 2020 02:50:48 -0700 (PDT) Original-Received: from dell.homenet (81-174-209-196.pth-as2.dial.plus.net. [81.174.209.196]) by smtp.gmail.com with ESMTPSA id r15sm3579174wmn.24.2020.09.22.02.50.47 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 22 Sep 2020 02:50:48 -0700 (PDT) Original-Received: from dell.homenet (localhost [127.0.0.1]) by dell.homenet (Postfix) with SMTP id 18A5A422374 for ; Tue, 22 Sep 2020 10:50:27 +0100 (BST) In-Reply-To: <3a0ccd31a195f1544038b4ccc5ff1d15667a8e0d.camel@divoplade.fr> X-Mailer: Sylpheed 3.7.0 (GTK+ 2.24.32; x86_64-unknown-linux-gnu) Received-SPF: pass client-ip=2a00:1450:4864:20::32b; envelope-from=vine35792468@gmail.com; helo=mail-wm1-x32b.google.com X-detected-operating-system: by eggs.gnu.org: No matching host in p0f cache. That's all we know. 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, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, FREEMAIL_ENVFROM_END_DIGIT=0.25, FREEMAIL_FROM=0.001, NICE_REPLY_A=-0.001, RCVD_IN_DNSWL_NONE=-0.0001, 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:16946 Archived-At: On Tue, 22 Sep 2020 08:25:25 +0200 divoplade wrote: > Hello guile, > > I am having a hard time understanding what I do wrong when trying to > pass a guile function as a C callback (from C). > > You should be able to trigger the bug by saving the 3 attached files > and running: > > guix build -L . pkg-with-the-bug > > The bug disappears when ignoring the scheme callback, so I suspect it > has something to do with the callback and not further functions: > > guix build -L . pkg-without-the-bug > > Does anyone see an error? I haven't looked at your code but note that GC'ed objects held only in the C or C++ heap (say as closures of a C function) are not visible to the GC and need protection with scm_gc_protect_object, otherwise they can be collected while still in use by C code. If you have one-shot C callbacks taking guile objects as closures which are stored as pointers in the C heap, you can call scm_gc_unprotect_object as the last thing the callback does in order to get the object collected subsequently. This may not be your issue. I offer it as something I had to deal with in code of my own to prevent incorrect collection for closures of callbacks executed by a C event loop.