unofficial mirror of guile-devel@gnu.org 
 help / color / mirror / Atom feed
From: Matt Wette <matt.wette@gmail.com>
To: guile-devel <guile-devel@gnu.org>
Subject: Re: ffi-help: status to date
Date: Tue, 24 Oct 2017 17:18:29 -0700	[thread overview]
Message-ID: <91AF422B-BC34-4F99-BEE1-87B946A9FBD4@gmail.com> (raw)
In-Reply-To: <47398F30-BD71-43ED-B9A0-DA86CCCA4D40@gmail.com>


> On Oct 22, 2017, at 11:31 AM, Matt Wette <matt.wette@gmail.com> wrote:
> 
> Hi All,
> 
> I am working on a ffi-helper (FH): a program that will read in a C dot-h file and generate a Guile dot-scm file 
> which defines a module to provide hooks into the associated C library.  
> 

> I was able to generate scm code for glib, gobject, gio, pango, and gtk2+.  The following demo code actually works.
> I get a GUI and click the button and it closes, though with an error message:
>    gtkdemo.scm:16:0: Wrong number of arguments to #<procedure hello (widget data)>
> 

> (define (hello widget data)
>  (display "Hello World!\n"))

>  (g_signal_connect button "clicked" hello NULL)

The reason I got error messages was that g_signal_connect uses signature `void (*f)(void)' for the 
callback but the semantics of GTK say use `void (*f)(void*, void*)', basically.  GTK handles this 
by providing casts for arguments.  I got the code working by hand generating casts:

  (define ~hello (ffi:procedure->pointer ffi:void hello (list '* '*)))

  (g_signal_connect button "clicked" ~hello NULL)

Doing this by hand is a bit of a mess, but ... there it is.  I am not confident that there is a way
to automate or make this easier.  I had to generate a couple other hand-casts but the result is that
the demo is now working w/o error messages.  

In case you are interested here are line counts for the text files and sizes for the object files.
(oops, didn't include pango; that is bigish)

mwette$ wc gobject.* glib.* gtk2+.* gdk2.*
      26      77     885 gobject.ffi
   12543   28465  426476 gobject.scm
      31      82    1006 glib.ffi
   31326   75035 1013504 glib.scm
      17      47     470 gtk2+.ffi
   92827  210107 3259549 gtk2+.scm
      18      52     534 gdk2.ffi
   18986   45046  639630 gdk2.scm

mwette$ ls -l gobject.* glib.* gtk2+.* gdk2.*
-rw-r--r--  1 mwette  staff   3619461 Oct 22 10:57 gdk2.scm.go
-rw-r--r--  1 mwette  staff   5546829 Oct 22 10:48 glib.scm.go
-rw-r--r--  1 mwette  staff   2554501 Oct 24 16:36 gobject.scm.go
-rw-r--r--  1 mwette  staff  18521997 Oct 22 11:06 gtk2+.scm.go




  reply	other threads:[~2017-10-25  0:18 UTC|newest]

Thread overview: 13+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-07-03 17:25 ffi-help: documentation Matt Wette
2017-08-19 15:30 ` ffi-help: status to 19 Aug 2017 Matt Wette
2017-09-08  3:32   ` ffi-help: #:use-ffi-module Matt Wette
2017-09-08  3:40     ` Matt Wette
2017-10-22 18:31     ` ffi-help: status to date Matt Wette
2017-10-25  0:18       ` Matt Wette [this message]
2017-11-09 19:10   ` ffi-help: status to 19 Aug 2017 Roel Janssen
2017-11-10  1:00     ` Matt Wette
2017-11-10  2:34       ` Matt Wette
2017-11-10  2:39     ` Matt Wette
2017-11-10 23:04       ` Stefan Israelsson Tampe
2017-11-11  4:38         ` Matt Wette
2017-11-14 18:06     ` Ricardo Wurmus

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=91AF422B-BC34-4F99-BEE1-87B946A9FBD4@gmail.com \
    --to=matt.wette@gmail.com \
    --cc=guile-devel@gnu.org \
    /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).