unofficial mirror of guile-devel@gnu.org 
 help / color / mirror / Atom feed
From: Doug Evans <xdje42@gmail.com>
To: Andy Wingo <wingo@pobox.com>
Cc: guile-devel <guile-devel@gnu.org>
Subject: Re: RFC: Foreign objects facility
Date: Fri, 2 May 2014 22:45:52 -0700	[thread overview]
Message-ID: <CAP9bCMQBmG2TfwUX0NV6rJYratuytQ7-ZRofAzFx=x=VUERb6A@mail.gmail.com> (raw)
In-Reply-To: <87ha5cuh6j.fsf@pobox.com>

On Tue, Apr 29, 2014 at 11:25 AM, Andy Wingo <wingo@pobox.com> wrote:
> 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.

Almost. git struct.c has:

SCM
scm_c_make_struct (SCM vtable, size_t n_tail, size_t n_init,
scm_t_bits init, ...)


>> 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.

I'm not suggesting changing the API of course. :-)

Plus scm_make_struct is callable from Scheme so it doesn't really
support passing "uninterpretered" values (except hackily).

> 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.

Technically, one could provide just intptr/uintptr and skip void*, but
the latter would be sufficiently convenient I think.

re: The combinatoric mess, I'm not suggesting adding that.

Plus, if an app wants to have an SCM in their "foreign object" they
can't store it in a slot, whereas they can with structs.

>> 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).

IIUC, goops already had <foreign-slot>, which is what the foreign
object API uses.
So I still don't see what creating a whole new class of data structure
provides that can't be provided by extending existing ones.  And if
there is something, doesn't that mean that the existing ones
(goops/structs) are still broken?


>> 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?

I would flag referencing or setting a 'p' field via the
"uninterpreted" accessors as errors.

> 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."

OTOH, yet another compound data structure with its own API now exists.



      reply	other threads:[~2014-05-03  5:45 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
2014-05-03  5:45     ` Doug Evans [this message]

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='CAP9bCMQBmG2TfwUX0NV6rJYratuytQ7-ZRofAzFx=x=VUERb6A@mail.gmail.com' \
    --to=xdje42@gmail.com \
    --cc=guile-devel@gnu.org \
    --cc=wingo@pobox.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).