unofficial mirror of guile-devel@gnu.org 
 help / color / mirror / Atom feed
From: Andy Wingo <wingo@pobox.com>
To: Doug Evans <xdje42@gmail.com>
Cc: guile-devel <guile-devel@gnu.org>
Subject: Re: RFC: Foreign objects facility
Date: Tue, 29 Apr 2014 20:25:08 +0200	[thread overview]
Message-ID: <87ha5cuh6j.fsf@pobox.com> (raw)
In-Reply-To: <CAP9bCMTRt02tRcj=OOuwjJL5_h7_2_wVywgL8R1VSk2sxOgKvg@mail.gmail.com> (Doug Evans's message of "Tue, 29 Apr 2014 08:56:39 -0700")

Hi!

Thanks for the feedback, it's really useful.

On Tue 29 Apr 2014 17:56, Doug Evans <xdje42@gmail.com> writes:

> The struct interface, contrary to what the documentation says, takes a
> stdarg list beginning with the number of fields (and not terminated
> with SCM_UNDEFINED), instead of _1, _2, _3

This is what the documentation says (in the info node 'Structure
Basics'):

 -- C Function: SCM scm_make_struct (SCM vtable, SCM tail_size, SCM
          init_list)
 -- C Function: SCM scm_c_make_struct (SCM vtable, SCM tail_size, SCM
          init, ...)
 -- C Function: SCM scm_c_make_structv (SCM vtable, SCM tail_size,
          size_t n_inits, scm_t_bits init[])

I believe this to be correct.

> fwiw, I would use that over the _n version.

I thought so too and so I used this in my first attempt ;) However
scm_make_struct expects the scm_t_bits to actually be unpacked SCM
values -- which is to say, it expects them to be tagged.  A bit wonky.
SCM is a perfectly valid varargs type, as evinced by scm_list_n and
friends.  But that's how it is and for ABI reasons we can't really
change that.

Then we had the points that Mark brought up about portable type-casting,
and that really we should provide separate signed/unsigned integer
interfaces and also pointer interfaces.  It gets into a combinatoric
mess on the constructor level, though perhaps for N<=3 it's manageable.
Anyway then you also have to match the types that are passed as
initializers to the field type (unboxed 'u' or tagged 'p') and it's just
a big mess.  I thought that the given foreign object API would cover the
majority of cases, like SMOB cases, and that for multi-field types the
ref/set accessors would be sufficient.

> fwiw, structs already provide most of what is needed.
> I have a few gdb objects using them, and it doesn't seem too bad.

Yes.  The API doesn't support this use case so well.  It also doesn't
support GOOPS method dispatch, subclassing, or named fields (unless you
start getting into records territory).

> I think you should fix/extend the struct interface instead of
> inventing something new: given that structs already have
> "uninterpreted" it is most of the way there already.  It's already
> intended to solve the problem you're trying to solve.
> Its API just needs a way to set/ref "uninterpreted" values directly.

Good point.  Though, it can hard to square with the existing smob/struct
cases.  You could have scm_struct_unsigned_ref -- would it then untag a
'p' value?  It seems to me that there are some combinatorics that we do
away with by saying that "this is a foreign object.  It's also a struct,
and a GOOPS instance, and you can treat it that way, but the API we
expose to C is the most useful way to treat these objects."

WDYT?

Andy

p.s. Will reply to your other mail, but see the updated master docs
here:
http://www.gnu.org/software/guile/docs/master/guile.html/Programming-in-C.html#Programming-in-C
http://www.gnu.org/software/guile/docs/master/guile.html/API-Reference.html#API-Reference
-- 
http://wingolog.org/



  reply	other threads:[~2014-04-29 18:25 UTC|newest]

Thread overview: 14+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2014-04-27 13:17 RFC: Foreign objects facility Andy Wingo
2014-04-27 16:00 ` Mark H Weaver
2014-04-27 16:46   ` Stefan Israelsson Tampe
2014-04-28 17:47     ` Andy Wingo
2014-04-27 17:51   ` Andy Wingo
2014-05-03  4:57     ` Doug Evans
2014-04-28 16:08   ` Andy Wingo
2014-04-29 16:08     ` Doug Evans
2014-04-29 18:27       ` Andy Wingo
2014-04-28  8:24 ` Ludovic Courtès
2014-04-28 18:05   ` Andy Wingo
2014-04-29 15:56 ` Doug Evans
2014-04-29 18:25   ` Andy Wingo [this message]
2014-05-03  5:45     ` Doug Evans

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=87ha5cuh6j.fsf@pobox.com \
    --to=wingo@pobox.com \
    --cc=guile-devel@gnu.org \
    --cc=xdje42@gmail.com \
    /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).