unofficial mirror of guile-user@gnu.org 
 help / color / mirror / Atom feed
From: Jan Synacek <jsynacek@redhat.com>
To: guile-user@gnu.org
Subject: FFI questions
Date: Fri, 15 May 2020 15:47:34 +0200	[thread overview]
Message-ID: <CAPsXM8WZ7ORLOgoJMNqxfy7ZZKbptv+T2kpTsh=mc7e1V-K09w@mail.gmail.com> (raw)

Hello,

Currently I have something like this:

(define libxcb (dynamic-link "libxcb"))

...

(define c-change-window-attributes
  (pointer->procedure void
     (dynamic-func "xcb_change_window_attributes" libxcb)
     (list '* uint32 uint32 '*)))

(define (change-window-attributes conn win mask vals)
   (c-change-window-attributes conn win mask (bytevector->pointer vals)))

The last argument to xcb_change_window_attributes is 'const void *' and I
need to pass a u32 vector to it. As it is right now, it segfaults when I
try passing #u32(something) to 'change-window-attributes'. Is it possible
to make it accept a u32 vector using just Scheme or do I have to work
around it on the C level?


My second question is about FFI and structs. Is it possible to access C
struct members from Scheme by name? If not, how do I generally approach the
problem? I've checked how guile-xcb does it and it seems to be building
hash tables with field names as keys. But that basically requires me to
"redefine" all the C structs that I would be interested in at the Scheme
level.

Regards,
-- 
Jan Synacek
Software Engineer, Red Hat


             reply	other threads:[~2020-05-15 13:47 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-05-15 13:47 Jan Synacek [this message]
2020-05-15 20:09 ` FFI questions Taylan Kammer
2020-05-15 23:52   ` Matt Wette
2020-05-15 23:59     ` Matt Wette
2020-05-17 10:06   ` Jan Synacek

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='CAPsXM8WZ7ORLOgoJMNqxfy7ZZKbptv+T2kpTsh=mc7e1V-K09w@mail.gmail.com' \
    --to=jsynacek@redhat.com \
    --cc=guile-user@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).