From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: Zhu Zihao Newsgroups: gmane.lisp.guile.user Subject: Can Dynamic FFI in Guile handle pass by value struct? Date: Sat, 06 Feb 2021 22:10:14 +0800 Message-ID: <86h7mp5ltl.fsf@163.com> Mime-Version: 1.0 Content-Type: multipart/signed; boundary="=-=-="; micalg=pgp-sha256; protocol="application/pgp-signature" Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="9164"; mail-complaints-to="usenet@ciao.gmane.io" User-Agent: mu4e 1.4.14; emacs 27.1 To: guile-user@gnu.org Original-X-From: guile-user-bounces+guile-user=m.gmane-mx.org@gnu.org Sat Feb 06 16:10:56 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 1l8PEe-0002I8-0x for guile-user@m.gmane-mx.org; Sat, 06 Feb 2021 16:10:56 +0100 Original-Received: from localhost ([::1]:44634 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1l8PEd-0004h9-3x for guile-user@m.gmane-mx.org; Sat, 06 Feb 2021 10:10:55 -0500 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]:43262) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1l8OXH-0000KY-9N for guile-user@gnu.org; Sat, 06 Feb 2021 09:26:07 -0500 Original-Received: from m12-17.163.com ([220.181.12.17]:52160) by eggs.gnu.org with esmtps (TLS1.2:DHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.90_1) (envelope-from ) id 1l8OX6-0000UC-7v for guile-user@gnu.org; Sat, 06 Feb 2021 09:26:04 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=163.com; s=s110527; h=From:Subject:Date:Message-ID:MIME-Version; bh=9LzvL Obmhx7iwTqrw40eeul5T46sWcbsQfsxJxTKajc=; b=SroCC+jNoT5zUXca2tQ5A qgkjZwYEvTlVikXaOHEZ1zNLSkTUGqjkGQGM7etpTS/obKnHKOoDmhvrauVB0MPT DQado++3T/jw8iFy4t7jVo3uvkxwbPY1m42H+kRT2ZI3HxuuM5RFHgK+VvxFizBN uzCco7WCFFDx9re1V4b2NY= Original-Received: from asus-laptop (unknown [113.100.121.212]) by smtp13 (Coremail) with SMTP id EcCowAAHvXlKox5gdRRRjw--.29886S2; Sat, 06 Feb 2021 22:10:18 +0800 (CST) X-CM-TRANSID: EcCowAAHvXlKox5gdRRRjw--.29886S2 X-Coremail-Antispam: 1Uf129KBjvdXoW7JFyDKFyxXry7Aw1kZw4ktFb_yoWfCrb_Gr n5Zan5ur15Zr4ktrs7Kay3tFZFkrnrur1xur1ftrnIva4qvan8W3sagr9ak397tFsrJr1j 93ZYkr10yFy5ujkaLaAFLSUrUUUUUb8apTn2vfkv8UJUUUU8Yxn0WfASr-VFAUDa7-sFnT 9fnUUvcSsGvfC2KfnxnUUI43ZEXa7IU0dnY7UUUUU== X-Originating-IP: [113.100.121.212] X-CM-SenderInfo: pdoosuxxwbztlvw6il2tof0z/xtbB8RIxr12MY6i0UQAAsC Received-SPF: pass client-ip=220.181.12.17; envelope-from=all_but_last@163.com; helo=m12-17.163.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 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, RCVD_IN_MSPIKE_H2=-0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-Mailman-Approved-At: Sat, 06 Feb 2021 10:10:42 -0500 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:17228 Archived-At: --=-=-= Content-Type: text/plain Content-Transfer-Encoding: quoted-printable Hi, Guile users! I'm working on a Guile binding to tree-sitter, an incremental parsing library. Consider we have something like(actually taken from tree-sitter's header file) ``` typedef struct { uint32_t context[4]; const void *id; const TSTree *tree; } TSNode; uint32_t ts_node_end_byte(TSNode); ``` I'd like to write binding like ``` (pointer->procedure uint32 (dynamic-func "ts_node_end_byte" %libtree-sitter= ) `((,uint32 * *))) ``` As the function defined in header, we need to pass a TSNode struct by value to ts_node_end_type. But I'm not sure how to do it in Dynamic FFI. There's make-c-struct in (system foreign), but it'll return a pointer to the struct. I check the doc but can't find something useful, Can guile Dynamic FFI pass a C struct by value or we must do it in static FFI? =2D-=20 Retrieve my PGP public key: gpg --recv-keys D47A9C8B2AE3905B563D9135BE42B352A9F6821F Zihao --=-=-= Content-Type: application/pgp-signature; name="signature.asc" -----BEGIN PGP SIGNATURE----- iIsEARYIADMWIQTUepyLKuOQW1Y9kTW+QrNSqfaCHwUCYB6jRhUcYWxsX2J1dF9s YXN0QDE2My5jb20ACgkQvkKzUqn2gh+SDgEAmJvlO8w5VPNIC2UllIT6NnFGVRUS JQWtrpb9zA7yg24BAJn4sV/SuObek6pEXmWM12+KYgKK4KBZ5RfFkMKoM+cJ =Oa0A -----END PGP SIGNATURE----- --=-=-=--