unofficial mirror of guile-devel@gnu.org 
 help / color / mirror / Atom feed
From: Andy Wingo <wingo@pobox.com>
To: Neil Jerram <neil@ossau.uklinux.net>
Cc: guile-devel <guile-devel@gnu.org>
Subject: Re: ffi docs
Date: Sat, 17 Apr 2010 12:38:47 +0200	[thread overview]
Message-ID: <m3wrw6xt1k.fsf@pobox.com> (raw)
In-Reply-To: <87wrw7t4ad.fsf@ossau.uklinux.net> (Neil Jerram's message of "Fri, 16 Apr 2010 23:34:50 +0100")

Greets,

On Sat 17 Apr 2010 00:34, Neil Jerram <neil@ossau.uklinux.net> writes:

> I agree that it will make sense for me to handle these doc changes.

Thank you very much for this; I have been writing too many docs
recently, and long for the hack.

>> The facility is typically
>> called a "foreign function interface", but that name doesn't appear in
>> e.g. "dynamic-link", so I was trying to explain.
>
> Ah yes, I see now.  In that case I think it's just the last clause that
> doesn't quite work for me.  I would say that the _immediately_ following
> text is about "components of foreign libraries", so why say "as we see
> in future sections"?
>
> Maybe: "... really is foreign to Scheme.  Foreign function and data
> pointers, obtained via `dynamic-func' and `dynamic-pointer', or as
> return values from a foreign function call, are inherently untyped, and
> depend on the Scheme programmer using them in a way that is consistent
> with the library's documented interface.  Any other usage is unsafe and
> can easily cause the containing Scheme program to crash, and the Guile
> low-level FFI cannot protect against this.  (This is quite different
> from computations on Scheme values; Scheme values are typed, and so
> operations on them can check in advance that the value types are as
> expected.)"

That looks great to me. I also think it's nice to preface this section,
as you do, with a brief mention of unsafety.

>>> - isn't it actually much more to do with the ELF binary format, rather
>>>   than with C?  If libguile could read and parse C, it would be able to
>>>   infer the type of any variable that the Scheme layer might request.
>>>   The problem is precisely that what we are linking with is *not* C
>>>   anymore...  It's just untyped pointers.
>>
>> I guess you're right, this is confusing. C doesn't really exist at
>> runtime, and this API is all about accessing runtime values.
>
> On further reflection, I think I'm not completely right.  Functions
> assume that they will be called according to well known C calling
> conventions.  So I guess there are vestiges of C.
>
> Out of interest, do other languages that compile to library format use
> different calling conventions, and if so can dlopen/dlsym and FFIs work
> with them?

AFAIK, the only thing you should rely on is the standard ABI for your
architecture. For example for Intel 386, there is

  http://www.sco.com/developers/devspecs/abi386-4.pdf

Yes, hosted on SCO. See chapter 3. I believe there are similar documents
for other architectures. There are mentions of C there, but there are
also attempts to make it known that it's the convention that matters,
not the language.

Not sure if that helps, though. It certainly doesn't have to do with ELF
though, as far as I know.

Andy
-- 
http://wingolog.org/




  reply	other threads:[~2010-04-17 10:38 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2010-04-06 21:36 ffi docs Andy Wingo
2010-04-07 21:38 ` Ludovic Courtès
2010-04-07 22:01   ` Andy Wingo
2010-04-15 22:36 ` Neil Jerram
2010-04-16  8:43   ` Ludovic Courtès
2010-04-16  9:33   ` Andy Wingo
2010-04-16 22:34     ` Neil Jerram
2010-04-17 10:38       ` Andy Wingo [this message]
2010-07-27  8:24   ` Ludovic Courtès

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=m3wrw6xt1k.fsf@pobox.com \
    --to=wingo@pobox.com \
    --cc=guile-devel@gnu.org \
    --cc=neil@ossau.uklinux.net \
    /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).