unofficial mirror of guile-devel@gnu.org 
 help / color / mirror / Atom feed
* FFI supports callbacks
@ 2010-09-03 14:30 Ludovic Courtès
  2010-09-03 16:51 ` Andy Wingo
  0 siblings, 1 reply; 13+ messages in thread
From: Ludovic Courtès @ 2010-09-03 14:30 UTC (permalink / raw)
  To: guile-devel

Happy Friday Guilers!

I'm pleased to announce that (system foreign) supports callbacks via the
new ‘procedure->pointer’:

  http://git.sv.gnu.org/cgit/guile.git/commit/?id=33186356668fe7697a8f2692660aaff69178d720

The function is similar to ‘make-foreign-function’ but does things the
other way around.

How do you like it?

Besides, I’m planning to push a 1.9.12 tarball tomorrow Saturday, after
updating NEWS.

Thanks,
Ludo’.




^ permalink raw reply	[flat|nested] 13+ messages in thread

* Re: FFI supports callbacks
  2010-09-03 14:30 FFI supports callbacks Ludovic Courtès
@ 2010-09-03 16:51 ` Andy Wingo
  2010-09-03 17:27   ` Ludovic Courtès
  0 siblings, 1 reply; 13+ messages in thread
From: Andy Wingo @ 2010-09-03 16:51 UTC (permalink / raw)
  To: Ludovic Courtès; +Cc: guile-devel

Hi!

On Fri 03 Sep 2010 07:30, ludo@gnu.org (Ludovic Courtès) writes:

> I'm pleased to announce that (system foreign) supports callbacks via the
> new ‘procedure->pointer’:
>
> How do you like it?

Ludovic, that is breathtakingly great. My heart went aflutter looking at
the f-callback-1 test :-))

Only two thoughts:

 1) Do we need to trampoline through a scm_with_guile in the callback
    stub?

 2) Your commit has some tabs in it ;)

Cheers,

A
-- 
http://wingolog.org/



^ permalink raw reply	[flat|nested] 13+ messages in thread

* Re: FFI supports callbacks
  2010-09-03 16:51 ` Andy Wingo
@ 2010-09-03 17:27   ` Ludovic Courtès
  2010-09-05 15:10     ` Ludovic Courtès
  0 siblings, 1 reply; 13+ messages in thread
From: Ludovic Courtès @ 2010-09-03 17:27 UTC (permalink / raw)
  To: guile-devel

Hello!

Andy Wingo <wingo@pobox.com> writes:

> On Fri 03 Sep 2010 07:30, ludo@gnu.org (Ludovic Courtès) writes:
>
>> I'm pleased to announce that (system foreign) supports callbacks via the
>> new ‘procedure->pointer’:
>>
>> How do you like it?
>
> Ludovic, that is breathtakingly great. My heart went aflutter looking at
> the f-callback-1 test :-))

That’s the least I could expect.   :-)

> Only two thoughts:
>
>  1) Do we need to trampoline through a scm_with_guile in the callback
>     stub?

Nooo, not necessarily, ‘scm_without_guile’ is old-fashioned.  Quoting
the fine manual:

     Starting from Guile 2.0, blocked threads no longer hinder garbage
  collection.  Thus, the functions below are not needed anymore.  They can
  still be used to inform the GC that a thread is about to block, giving
  it a (small) optimization opportunity for "stop the world" garbage
  collections, should they occur while the thread is blocked.

:-)

>  2) Your commit has some tabs in it ;)

Oh?  But not in Scheme files hopefully?

BTW, while we’re at it, how about make-foreign-function => pointer->procedure?
Sounds like the ultimate rename to me.

Thanks,
Ludo’.




^ permalink raw reply	[flat|nested] 13+ messages in thread

* Re: FFI supports callbacks
  2010-09-03 17:27   ` Ludovic Courtès
@ 2010-09-05 15:10     ` Ludovic Courtès
  2010-09-05 22:23       ` Jose A. Ortega Ruiz
  2010-09-06 12:04       ` Andy Wingo
  0 siblings, 2 replies; 13+ messages in thread
From: Ludovic Courtès @ 2010-09-05 15:10 UTC (permalink / raw)
  To: guile-devel

Hi there!

ludo@gnu.org (Ludovic Courtès) writes:

> BTW, while we’re at it, how about make-foreign-function => pointer->procedure?

We briefly discussed this on IRC.  One issue with the
‘pointer->procedure’ name is that ‘->’ procedures are most of the time
one-argument procedures, whereas ‘make-foreign-function’ has 3 mandatory
arguments.

However, it occurred to me that what confuses me most about
‘make-foreign-function’ is that it actually makes a Scheme procedure out
of a foreign function.

Conversely, ‘procedure->pointer’ really makes a foreign function out of
a Scheme procedure.

In addition, I like the idea of having names that show the symmetry of
these two procedures.

So, what do you think?  :-)

(I’m also open to different names that aren’t confusing and show the
symmetry.)

Thanks,
Ludo’.




^ permalink raw reply	[flat|nested] 13+ messages in thread

* Re: FFI supports callbacks
  2010-09-05 15:10     ` Ludovic Courtès
@ 2010-09-05 22:23       ` Jose A. Ortega Ruiz
  2010-09-06 12:06         ` Andy Wingo
  2010-09-06 12:32         ` Ludovic Courtès
  2010-09-06 12:04       ` Andy Wingo
  1 sibling, 2 replies; 13+ messages in thread
From: Jose A. Ortega Ruiz @ 2010-09-05 22:23 UTC (permalink / raw)
  To: guile-devel

On Sun, Sep 05 2010, Ludovic Courtès wrote:

> Hi there!
>
> ludo@gnu.org (Ludovic Courtès) writes:
>
>> BTW, while we’re at it, how about make-foreign-function => pointer->procedure?
>
> We briefly discussed this on IRC.  One issue with the
> ‘pointer->procedure’ name is that ‘->’ procedures are most of the time
> one-argument procedures, whereas ‘make-foreign-function’ has 3 mandatory
> arguments.
>
> However, it occurred to me that what confuses me most about
> ‘make-foreign-function’ is that it actually makes a Scheme procedure out
> of a foreign function.
>
> Conversely, ‘procedure->pointer’ really makes a foreign function out of
> a Scheme procedure.
>
> In addition, I like the idea of having names that show the symmetry of
> these two procedures.
>
> So, what do you think?  :-)
>
> (I’m also open to different names that aren’t confusing and show the
> symmetry.)

import-foreign-function
export-foreign-function / export-to-foreign-function

procedure-from-foreign-function / foreign-function-to-procedure
procedure-to-foreign-function / foreign-function-from-procedure

procedure-from-foreign / foreign-to-procedure
procedure-to-foreign / foreign-from-procedure

at any rate, i find "pointer" not clear enough.

jao
-- 
Simplicity does not precede complexity, but follows it.
  - Alan Perlis, Epigrams in Programing




^ permalink raw reply	[flat|nested] 13+ messages in thread

* Re: FFI supports callbacks
  2010-09-05 15:10     ` Ludovic Courtès
  2010-09-05 22:23       ` Jose A. Ortega Ruiz
@ 2010-09-06 12:04       ` Andy Wingo
  2010-09-08 16:21         ` Ludovic Courtès
  1 sibling, 1 reply; 13+ messages in thread
From: Andy Wingo @ 2010-09-06 12:04 UTC (permalink / raw)
  To: Ludovic Courtès; +Cc: guile-devel

Greets,

On Sun 05 Sep 2010 17:10, ludo@gnu.org (Ludovic Courtès) writes:

> ludo@gnu.org (Ludovic Courtès) writes:
>
>> BTW, while we’re at it, how about make-foreign-function => pointer->procedure?
>
> We briefly discussed this on IRC.  One issue with the
> ‘pointer->procedure’ name is that ‘->’ procedures are most of the time
> one-argument procedures, whereas ‘make-foreign-function’ has 3 mandatory
> arguments.
>
> However, it occurred to me that what confuses me most about
> ‘make-foreign-function’ is that it actually makes a Scheme procedure out
> of a foreign function.
>
> Conversely, ‘procedure->pointer’ really makes a foreign function out of
> a Scheme procedure.
>
> In addition, I like the idea of having names that show the symmetry of
> these two procedures.
>
> So, what do you think?  :-)

I guess I'm OK with it. The new names do convey the types better to the
programmer. I'm hesitant regarding "pointer" though; the name is just so
general. I guess I prefer "machine-pointer" or something. But I would
also be OK with the change as you propose it.

Andy
-- 
http://wingolog.org/



^ permalink raw reply	[flat|nested] 13+ messages in thread

* Re: FFI supports callbacks
  2010-09-05 22:23       ` Jose A. Ortega Ruiz
@ 2010-09-06 12:06         ` Andy Wingo
  2010-09-07  0:30           ` Jose A. Ortega Ruiz
  2010-09-06 12:32         ` Ludovic Courtès
  1 sibling, 1 reply; 13+ messages in thread
From: Andy Wingo @ 2010-09-06 12:06 UTC (permalink / raw)
  To: Jose A. Ortega Ruiz; +Cc: guile-devel

On Mon 06 Sep 2010 00:23, "Jose A. Ortega Ruiz" <jao@gnu.org> writes:

> procedure-from-foreign-function / foreign-function-to-procedure
> procedure-to-foreign-function / foreign-function-from-procedure
>
> procedure-from-foreign / foreign-to-procedure
> procedure-to-foreign / foreign-from-procedure

I don't think anything is gained by writing "from" or "to"; "->" is
indeed pronounced "too".

> at any rate, i find "pointer" not clear enough.

Agreed, though at least it is consistent. The subject does not lend
itself to a natural clarity.

Also consider that this is a low-level interface; presumably people
should be programming with some sort of `define-c-wrapper' macro that
presents a nicer interface.

Andy
-- 
http://wingolog.org/



^ permalink raw reply	[flat|nested] 13+ messages in thread

* Re: FFI supports callbacks
  2010-09-05 22:23       ` Jose A. Ortega Ruiz
  2010-09-06 12:06         ` Andy Wingo
@ 2010-09-06 12:32         ` Ludovic Courtès
  1 sibling, 0 replies; 13+ messages in thread
From: Ludovic Courtès @ 2010-09-06 12:32 UTC (permalink / raw)
  To: guile-devel

Hi!

"Jose A. Ortega Ruiz" <jao@gnu.org> writes:

> On Sun, Sep 05 2010, Ludovic Courtès wrote:
>
>> Hi there!
>>
>> ludo@gnu.org (Ludovic Courtès) writes:
>>
>>> BTW, while we’re at it, how about make-foreign-function => pointer->procedure?
>>
>> We briefly discussed this on IRC.  One issue with the
>> ‘pointer->procedure’ name is that ‘->’ procedures are most of the time
>> one-argument procedures, whereas ‘make-foreign-function’ has 3 mandatory
>> arguments.
>>
>> However, it occurred to me that what confuses me most about
>> ‘make-foreign-function’ is that it actually makes a Scheme procedure out
>> of a foreign function.
>>
>> Conversely, ‘procedure->pointer’ really makes a foreign function out of
>> a Scheme procedure.
>>
>> In addition, I like the idea of having names that show the symmetry of
>> these two procedures.
>>
>> So, what do you think?  :-)
>>
>> (I’m also open to different names that aren’t confusing and show the
>> symmetry.)
>
> import-foreign-function
> export-foreign-function / export-to-foreign-function
>
> procedure-from-foreign-function / foreign-function-to-procedure
> procedure-to-foreign-function / foreign-function-from-procedure

OK.  (Slightly to verbose to my taste.)

> procedure-from-foreign / foreign-to-procedure
> procedure-to-foreign / foreign-from-procedure
>
> at any rate, i find "pointer" not clear enough.

Hmm but I find ‘foreign’ as a substantive hard to parse.  :-)

The object type in question is now called ‘pointer’ (it used to be
‘foreign’), hence the name.  “Pointer” is meant as a synonym for
‘void *’ ans pointer objects are untyped, which may be why it seems
“vague”.  But hey, the concept of pointing to the void *is* vague.
:-)

Thanks for the suggestions!

Ludo’.




^ permalink raw reply	[flat|nested] 13+ messages in thread

* Re: FFI supports callbacks
  2010-09-06 12:06         ` Andy Wingo
@ 2010-09-07  0:30           ` Jose A. Ortega Ruiz
  2010-09-07  7:38             ` Tristan Colgate
                               ` (2 more replies)
  0 siblings, 3 replies; 13+ messages in thread
From: Jose A. Ortega Ruiz @ 2010-09-07  0:30 UTC (permalink / raw)
  To: guile-devel

On Mon, Sep 06 2010, Andy Wingo wrote:


[...]

> Also consider that this is a low-level interface; presumably people
> should be programming with some sort of `define-c-wrapper' macro that
> presents a nicer interface.

Is anyone working on this? I happen to quite like the design presented
in the paper "The Layers of Larceny's design":

<http://www.ccs.neu.edu/home/pnkfelix/Published/klock-ffi-schemeworkshop-2008.html>

I wouldn't be surprised if actual code could be lifted from Larceny's
implementation.

jao
-- 
The most important discoveries will provide answers to questions that we do
not yet know how to ask and will concern objects we have not yet imagined.
 -John N. Bahcall, astrophysicist (1935-2005)




^ permalink raw reply	[flat|nested] 13+ messages in thread

* Re: FFI supports callbacks
  2010-09-07  0:30           ` Jose A. Ortega Ruiz
@ 2010-09-07  7:38             ` Tristan Colgate
  2010-09-07 12:56             ` Ludovic Courtès
  2010-09-07 21:01             ` Andy Wingo
  2 siblings, 0 replies; 13+ messages in thread
From: Tristan Colgate @ 2010-09-07  7:38 UTC (permalink / raw)
  To: guile-devel

A new swig flavour to support guile's ffi would be really nice too.
I've been building up patches to update the regular guile support but
might take a look at this as an alternative.

On 7 September 2010 01:30, Jose A. Ortega Ruiz <jao@gnu.org> wrote:
> On Mon, Sep 06 2010, Andy Wingo wrote:
>
>
> [...]
>
>> Also consider that this is a low-level interface; presumably people
>> should be programming with some sort of `define-c-wrapper' macro that
>> presents a nicer interface.
>
> Is anyone working on this? I happen to quite like the design presented
> in the paper "The Layers of Larceny's design":
>
> <http://www.ccs.neu.edu/home/pnkfelix/Published/klock-ffi-schemeworkshop-2008.html>
>
> I wouldn't be surprised if actual code could be lifted from Larceny's
> implementation.
>
> jao
> --
> The most important discoveries will provide answers to questions that we do
> not yet know how to ask and will concern objects we have not yet imagined.
>  -John N. Bahcall, astrophysicist (1935-2005)
>
>
>



-- 
Tristan Colgate-McFarlane
----
  "You can get all your daily vitamins from 52 pints of guiness, and a
glass of milk"



^ permalink raw reply	[flat|nested] 13+ messages in thread

* Re: FFI supports callbacks
  2010-09-07  0:30           ` Jose A. Ortega Ruiz
  2010-09-07  7:38             ` Tristan Colgate
@ 2010-09-07 12:56             ` Ludovic Courtès
  2010-09-07 21:01             ` Andy Wingo
  2 siblings, 0 replies; 13+ messages in thread
From: Ludovic Courtès @ 2010-09-07 12:56 UTC (permalink / raw)
  To: guile-devel

Hi!

"Jose A. Ortega Ruiz" <jao@gnu.org> writes:

>> Also consider that this is a low-level interface; presumably people
>> should be programming with some sort of `define-c-wrapper' macro that
>> presents a nicer interface.
>
> Is anyone working on this?

I’m not really working on this but I’m interested (I’ve been using
(system foreign) + custom macros so far.)

> I happen to quite like the design presented in the paper "The Layers
> of Larceny's design":
>
> <http://www.ccs.neu.edu/home/pnkfelix/Published/klock-ffi-schemeworkshop-2008.html>

Sounds cool.

There’s also a C parser in Bigloo (“Cigloo”), which could be reused to
extract information from C headers.

Thanks,
Ludo’.




^ permalink raw reply	[flat|nested] 13+ messages in thread

* Re: FFI supports callbacks
  2010-09-07  0:30           ` Jose A. Ortega Ruiz
  2010-09-07  7:38             ` Tristan Colgate
  2010-09-07 12:56             ` Ludovic Courtès
@ 2010-09-07 21:01             ` Andy Wingo
  2 siblings, 0 replies; 13+ messages in thread
From: Andy Wingo @ 2010-09-07 21:01 UTC (permalink / raw)
  To: Jose A. Ortega Ruiz; +Cc: guile-devel

On Tue 07 Sep 2010 02:30, "Jose A. Ortega Ruiz" <jao@gnu.org> writes:

>> Also consider that this is a low-level interface; presumably people
>> should be programming with some sort of `define-c-wrapper' macro that
>> presents a nicer interface.
>
> Is anyone working on this? I happen to quite like the design presented
> in the paper "The Layers of Larceny's design":

Not me. I was hoping someone else would get around to it before I would
:)

> <http://www.ccs.neu.edu/home/pnkfelix/Published/klock-ffi-schemeworkshop-2008.html>

Very cool trick with running the C compiler at macroexpansion time!

Andy
-- 
http://wingolog.org/



^ permalink raw reply	[flat|nested] 13+ messages in thread

* Re: FFI supports callbacks
  2010-09-06 12:04       ` Andy Wingo
@ 2010-09-08 16:21         ` Ludovic Courtès
  0 siblings, 0 replies; 13+ messages in thread
From: Ludovic Courtès @ 2010-09-08 16:21 UTC (permalink / raw)
  To: guile-devel

Hi,

Andy Wingo <wingo@pobox.com> writes:

> On Sun 05 Sep 2010 17:10, ludo@gnu.org (Ludovic Courtès) writes:
>
>> ludo@gnu.org (Ludovic Courtès) writes:
>>
>>> BTW, while we’re at it, how about make-foreign-function => pointer->procedure?
>>
>> We briefly discussed this on IRC.  One issue with the
>> ‘pointer->procedure’ name is that ‘->’ procedures are most of the time
>> one-argument procedures, whereas ‘make-foreign-function’ has 3 mandatory
>> arguments.
>>
>> However, it occurred to me that what confuses me most about
>> ‘make-foreign-function’ is that it actually makes a Scheme procedure out
>> of a foreign function.
>>
>> Conversely, ‘procedure->pointer’ really makes a foreign function out of
>> a Scheme procedure.
>>
>> In addition, I like the idea of having names that show the symmetry of
>> these two procedures.
>>
>> So, what do you think?  :-)
>
> I guess I'm OK with it. The new names do convey the types better to the
> programmer. I'm hesitant regarding "pointer" though; the name is just so
> general. I guess I prefer "machine-pointer" or something. But I would
> also be OK with the change as you propose it.

I committed the change yesterday.

Thanks,
Ludo’.




^ permalink raw reply	[flat|nested] 13+ messages in thread

end of thread, other threads:[~2010-09-08 16:21 UTC | newest]

Thread overview: 13+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2010-09-03 14:30 FFI supports callbacks Ludovic Courtès
2010-09-03 16:51 ` Andy Wingo
2010-09-03 17:27   ` Ludovic Courtès
2010-09-05 15:10     ` Ludovic Courtès
2010-09-05 22:23       ` Jose A. Ortega Ruiz
2010-09-06 12:06         ` Andy Wingo
2010-09-07  0:30           ` Jose A. Ortega Ruiz
2010-09-07  7:38             ` Tristan Colgate
2010-09-07 12:56             ` Ludovic Courtès
2010-09-07 21:01             ` Andy Wingo
2010-09-06 12:32         ` Ludovic Courtès
2010-09-06 12:04       ` Andy Wingo
2010-09-08 16:21         ` Ludovic Courtès

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