From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: neil@ossau.homelinux.net Newsgroups: gmane.lisp.guile.user Subject: Re: Bytestructures: a "type system" for bytevectors Date: Mon, 07 Sep 2015 23:57:11 +0100 Message-ID: <20150907225711.5701711.51285.15525@ossau.homelinux.net> References: <87r3mkg2iy.fsf@T420.taylan> <8737yzftyv.fsf@T420.taylan> NNTP-Posting-Host: plane.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-Trace: ger.gmane.org 1441666658 22799 80.91.229.3 (7 Sep 2015 22:57:38 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Mon, 7 Sep 2015 22:57:38 +0000 (UTC) To: =?utf-8?q?Taylan_Ulrich_Bay=C4=B1rl=C4=B1/Kammer?= , guile-user@gnu.org Original-X-From: guile-user-bounces+guile-user=m.gmane.org@gnu.org Tue Sep 08 00:57:28 2015 Return-path: Envelope-to: guile-user@m.gmane.org Original-Received: from lists.gnu.org ([208.118.235.17]) by plane.gmane.org with esmtp (Exim 4.69) (envelope-from ) id 1ZZ5Lr-0005wD-85 for guile-user@m.gmane.org; Tue, 08 Sep 2015 00:57:27 +0200 Original-Received: from localhost ([::1]:59163 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ZZ5Lr-0007VO-Bx for guile-user@m.gmane.org; Mon, 07 Sep 2015 18:57:27 -0400 Original-Received: from eggs.gnu.org ([2001:4830:134:3::10]:52408) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ZZ5Lj-0007Uo-CK for guile-user@gnu.org; Mon, 07 Sep 2015 18:57:20 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1ZZ5Lg-0007sm-4H for guile-user@gnu.org; Mon, 07 Sep 2015 18:57:19 -0400 Original-Received: from out1.ip07ir2.opaltelecom.net ([62.24.128.243]:60531) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ZZ5Lf-0007sY-Vc for guile-user@gnu.org; Mon, 07 Sep 2015 18:57:16 -0400 X-IronPort-Anti-Spam-Filtered: true X-IronPort-Anti-Spam-Result: A2CLDgBZFe5VPO4ZkU5dGQEBAYMHVGmDJLxCgkGDNgKBMU0BAQEBAQEHAQEBAUE/QQWDXQEBAQECASMzKAsIAxEEAQEDAiYCAiEYCgQICAYBEogZAwoMCbR5jw8NhQgBAQEBAQUBAQEBAQEBARYEgSKKTIJPggoeHAaCY4FDBZVViw2BagOBTIcvI4odhzyCMwMcgVVwAYM7hQ0BAQE X-IPAS-Result: A2CLDgBZFe5VPO4ZkU5dGQEBAYMHVGmDJLxCgkGDNgKBMU0BAQEBAQEHAQEBAUE/QQWDXQEBAQECASMzKAsIAxEEAQEDAiYCAiEYCgQICAYBEogZAwoMCbR5jw8NhQgBAQEBAQUBAQEBAQEBARYEgSKKTIJPggoeHAaCY4FDBZVViw2BagOBTIcvI4odhzyCMwMcgVVwAYM7hQ0BAQE X-IronPort-AV: E=Sophos;i="5.17,486,1437433200"; d="scan'208";a="240024385" Original-Received: from host-78-145-25-238.as13285.net (HELO arudy) ([78.145.25.238]) by out1.ip07ir2.opaltelecom.net with ESMTP; 07 Sep 2015 23:57:13 +0100 Original-Received: from [127.0.0.1] (host-78-145-25-238.as13285.net [78.145.25.238]) by arudy (Postfix) with ESMTPSA id 1EFB138012; Mon, 7 Sep 2015 23:54:31 +0100 (BST) X-Mailer: BlackBerry Email (10.3.1.2576) In-Reply-To: <8737yzftyv.fsf@T420.taylan> X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 62.24.128.243 X-BeenThere: guile-user@gnu.org X-Mailman-Version: 2.1.14 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.org@gnu.org Original-Sender: guile-user-bounces+guile-user=m.gmane.org@gnu.org Xref: news.gmane.org gmane.lisp.guile.user:12004 Archived-At: Sorry for not mentioning this before, but have you seen make-c-struct and p= arse-c-struct at https://www.gnu.org/software/guile/manual/html_node/Foreig= n-Structs.html#Foreign-Structs ? =C2=A0 Original Message =C2=A0 From: Taylan Ulrich Bay=C4=B1rl=C4=B1/Kammer Sent: Monday, 31 August 2015 14:47 To: guile-user@gnu.org Subject: Re: Bytestructures: a "type system" for bytevectors taylanbayirli@gmail.com (Taylan Ulrich "Bay=C4=B1rl=C4=B1/Kammer") writes: > That's all there is to it, and you could populate those bytes directly, > one by one: > > the_struct_t my_struct =3D { a, b, c, d, e, f } > Whoops, C isn't as dumb as I had in memory. You'll need to memcpy it into a char[] to be able to hack on the bytes that freely. Anyway. So I've been made aware that if I want my library to work with C data structures, I'll probably want to add alignment support. :-) I did that now, though I don't know if I did it right because I couldn't find precise information on what an FFI system should support wrt. data structure alignment. I read a little on Wikipedia and peeked into the documentation of Haskell's FFI and CL's CFFI. The struct constructor takes an `align?' argument now, which if true will enable default alignment for struct fields. E.g. struct { uint8_t; uint16_t; uint64_t; } becomes: 1: 1 byte uint8 2: 1 byte padding so uint16 is 2-byte aligned 3-4: 2 bytes uint16 5-8: 4 bytes padding so uint64 is 8-byte aligned 9-16: 8 bytes uint64 16 bytes in total. The struct's own alignment is 8, equal to the alignment of its element with the highest alignment. Vectors' alignment is equal to that of their element-type's alignment. Unions' is equal to their highest member. I see C compilers support stuff like "pack(2)" to force 2-byte alignment for >2 byte sized fields. I might add support for that too; I don't know if C libraries typically use that for their ABI? --- Next up I'll see if I can implement some example programs using the library. Something parsing a binary file format, something using the FFI to work with some C data structures, etc. On the meanwhile, testers and feedback welcome. Taylan