Subject:
[ruby-ffi] Re: Unsure how to proceed using type defined in header
From:
Wayne Meissner
Date:
2/21/12 6:24 PM
To:
ruby-ffi@googlegroups.com

The typedef should work fine.  You may find though, that for some functions, you will need to pass the address of a pointer.
e.g. pam_start()

that would be attached as:
    attach_function :pam_start, [ :string, :string, :pointer, :pointer ], :int

and called like so:

  ppamh = FFI::MemoryPointer.new(:pointer)
  LibPam.pam_start("my_service", "my_user", conv, ppamh)
  pamh = ppamh.read_pointer

  # Now use pamh as the pam_handle_t arg to any other pam function.


On Wednesday, February 22, 2012 9:59:19 AM UTC+10, jason wrote:
Hi all,

I'm in the process of porting the rpam gem over to FFI (I ported the gem from 1.8 to 1.9 a while back, this seemed like the logical next step). One thing I'm having trouble finding documentation on is handling user-defined types from the header when the type being aliased is private to the library. 

So for instance, in security/pam_appl.h, we have:


/*
 * This is a blind structure; users aren't allowed to see inside a
 * pam_handle_t, so we don't define struct _pam_handle here.  This is
 * defined in a file private to the PAM library.  (i.e., it's private
 * to PAM service modules, too!)
 */
typedef struct _pam_handle pam_handle_t;

My first guess is to define a class inheriting from FFI::Struct, but since I don't know its layout, I'm not sure how to proceed.

In the C version, it gets initialized as a null pointer, so I then thought I could do `typdef :pointer, :pam_handle_t`, but this also seems wrong.

Grateful for any suggestions.

Thanks,

Jason Lewis

Email          jasonlewis.x@gmail.com     

Twitter        @canweriotnow

Blog            http://duckpunching.github.com/