unofficial mirror of guile-user@gnu.org 
 help / color / mirror / Atom feed
From: Neil Jerram <neil@ossau.uklinux.net>
To: "Marco Maggi" <marco.maggi-ipsu@poste.it>
Cc: guile-user <guile-user@gnu.org>
Subject: Re: packed structures usefulness
Date: Sat, 03 Nov 2007 10:43:02 +0000	[thread overview]
Message-ID: <87ir4jvccp.fsf@ossau.uklinux.net> (raw)
In-Reply-To: <JQVDG5$B062C824FC50E8D9E7A64E401D609CFB@poste.it> (Marco Maggi's message of "Fri, 2 Nov 2007 09:12:05 +0100")

"Marco Maggi" <marco.maggi-ipsu@poste.it> writes:

> one can define a SMOB whose internal
> representation is equivalent to the C language
> type:
>
> struct triplet {
>   int one;
>   double two;
>   int64_t three[3];
> }; 

I implemented something like this for an application whose basic
control mechanism is message passing using flat C structures ("flat"
=> no pointers), because I wanted to be able to build and manipulate
the structures from Scheme.

I handled the padding issue by autogenerating structure definitions
like this (from the header files that define the structures):

struct struct_desc triplet_desc[] =
{
  { "one", offsetof(struct triplet, one), sizeof(one) },
  { "two", offsetof(struct triplet, two), sizeof(two) },
  ...
};

(It was more complex than shown here, to handle embedded structures,
array fields, etc., but I'm sure you get the idea.)

Then writing C code to read these definitions and export them to the
Scheme level.

I didn't use SMOBs.  On the Scheme level the structure is just a
uniform byte array, and there are procedures for reading and writing
fields (identified by name), using the structure definition
information.

So to answer your actual question: yes, I think this is useful, but
only in a rather specific kind of application context.

(One could also consider using this approach for reading and writing
binary network protocols, but that feels less robust to me than the
traditional approach of reading and writing a sequential byte stream.)

Regards,
        Neil



_______________________________________________
Guile-user mailing list
Guile-user@gnu.org
http://lists.gnu.org/mailman/listinfo/guile-user


  parent reply	other threads:[~2007-11-03 10:43 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2007-11-02  8:12 packed structures usefulness Marco Maggi
2007-11-02 10:42 ` Ludovic Courtès
2007-11-02 12:18 ` Thien-Thi Nguyen
2007-11-03 10:43 ` Neil Jerram [this message]
  -- strict thread matches above, loose matches on Subject: below --
2007-11-06 20:53 Marco Maggi
2007-11-07 13:16 ` Thien-Thi Nguyen

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://www.gnu.org/software/guile/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=87ir4jvccp.fsf@ossau.uklinux.net \
    --to=neil@ossau.uklinux.net \
    --cc=guile-user@gnu.org \
    --cc=marco.maggi-ipsu@poste.it \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).