From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: Maxime Devos via General Guile related discussions Newsgroups: gmane.lisp.guile.user Subject: RE: Custom foreign types Date: Thu, 20 Jun 2024 00:16:43 +0200 Message-ID: <20240620001642.daGh2C00N0K6dk401aGiWj@andre.telenet-ops.be> References: Reply-To: Maxime Devos Mime-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="5066"; mail-complaints-to="usenet@ciao.gmane.io" To: Ryan Raymond , Guile User Original-X-From: guile-user-bounces+guile-user=m.gmane-mx.org@gnu.org Thu Jun 20 00:17:22 2024 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 1sK3cI-00018O-Cy for guile-user@m.gmane-mx.org; Thu, 20 Jun 2024 00:17:22 +0200 Original-Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1sK3bn-0004kn-Q7; Wed, 19 Jun 2024 18:16:51 -0400 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1sK3bl-0004jT-CJ for guile-user@gnu.org; Wed, 19 Jun 2024 18:16:49 -0400 Original-Received: from andre.telenet-ops.be ([2a02:1800:120:4::f00:15]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1sK3bi-0006Ij-HF for guile-user@gnu.org; Wed, 19 Jun 2024 18:16:49 -0400 Original-Received: from [IPv6:2a02:1811:8c0e:ef00:ad11:ee0:137f:2aa4] ([IPv6:2a02:1811:8c0e:ef00:ad11:ee0:137f:2aa4]) by andre.telenet-ops.be with bizsmtp id daGh2C00N0K6dk401aGiWj; Thu, 20 Jun 2024 00:16:42 +0200 Importance: normal X-Priority: 3 In-Reply-To: DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=telenet.be; s=r24; t=1718835402; bh=DWZzd1Hz8zL8HLJouvULK/54pwkVX5uv18TVSMl1X2M=; h=To:From:Subject:Date:In-Reply-To:References; b=Nl8jCgUQGQl899kVtVR1HBtKo3/vjYvSo/QccWY5f0KQP9iiFlVCzwVepjIj++pGo c+bF3ce2lTtFwscVpzWQBQ5CLX2rNbHzTRlv60tIgPsM2X4s1Ob7+avAMVcs62naw/ NgX786W7pym5veMde1ngyMZrlndRfegvTyaTxx2ETDwe8jC8BxM9cGEK5y9wiCHAEv U1wdhTALhVh971btjiAj+NddKI0Le6wBTeSL9CzQwTCq6GFbxaFr/ep3chyuH2K24b Ga5XhdrmAa569gwYvX1fqfPynY+YqMkOEqDkOri9BKfXYBIVp7zXIOmYMZVvSb2bYE KAcrxVvazrlSg== Received-SPF: pass client-ip=2a02:1800:120:4::f00:15; envelope-from=maximedevos@telenet.be; helo=andre.telenet-ops.be X-Spam_score_int: -27 X-Spam_score: -2.8 X-Spam_bar: -- X-Spam_report: (-2.8 / 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, HTML_MESSAGE=0.001, RCVD_IN_DNSWL_LOW=-0.7, SPF_HELO_PASS=-0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=ham autolearn_force=no X-Spam_action: no action X-Content-Filtered-By: Mailman/MimeDel 2.1.29 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-bounces+guile-user=m.gmane-mx.org@gnu.org Xref: news.gmane.io gmane.lisp.guile.user:19720 Archived-At: >Hello, all. >I know we can create pointers to structs with make-c-struct, but I would like to pass structs directly as arguments to foreign functions. I can do that by using bytevector-uint-ref, and setting the size to that of the struct, but when it is time to specify the type in pointer->procedure, I am out of luck if the sizes don't match. Instead of searching for a type of the same size of the struct, why not pas= s the struct type and struct directly to Guile? From the manual: >One may also pass structs as values, passing structs as foreign pointers. = See=C2=A0Foreign Structs, for more information on how to express struct typ= es and struct values. I=E2=80=99m not really clear on what the precise API is for setting struct = arguments and whether I interpreted that sentence correctly(*), but ... > Is there a cleaner way to do this? ... I think the answer is =E2=80=98yes=E2=80=99 , though I don=E2=80=99t kn= ow what this cleaner way is. You may want to look at the implementation for clarity (and if you find the= answer, an addition to the manual would be appreciated). Best regards, Maxime Devos. (*) I think what it means is that as type you set (list this-field-type tha= t-field-type ...) and as =E2=80=98Scheme value=E2=80=99 you set a foreign p= ointer that contains the struct. If it doesn=E2=80=99t mean that, you could= try letting the value be (list this-field-value that-field-value ...).