Subject:
Re: [ruby-ffi] using C macros
From:
Shawn Anderson
Date:
5/20/10 8:33 PM
To:
ruby-ffi@googlegroups.com

You could also ask the library maintainer to "publish" those static inline methods. Chipmunk did that and chipmunk-ffi attaches the function as data:

http://code.google.com/p/chipmunk-physics/source/browse/trunk/include/chipmunk/chipmunk_ffi.h
http://github.com/shawn42/chipmunk-ffi/blob/master/lib/chipmunk-ffi.rb#L27-L40

Of course this only works if you have a library maintainer that's willing to play nicely.

/Shawn

On Thu, May 20, 2010 at 8:02 PM, Jeremy Voorhis <jvoorhis@gmail.com> wrote:
The same explanation also holds for static inline functions, which are more frustrating since they are often less trivial than macros. For non-trivial code, creating a support library in C and linking it with FFI has been a good approach for me.

Best,

Jeremy


On Thu, May 20, 2010 at 4:57 PM, Wayne Meissner <wmeissner@gmail.com> wrote:
No, C macros are not present in the library as code, since they are
handled by the  C pre-processor.

You could just implement ruby versions of those macros (they should be
pretty simple).

On 21 May 2010 01:22, mixtli <ronmcclain75@gmail.com> wrote:
> Is it possible to access macros such as FD_SET and FD_ZERO?  I'm
> trying to wrap net-snmp, specifically the snmp_select_info function
> which is called in C like so:
>
>  int fds = 0, block = 1;
>  fd_set fdset;
>  struct timeval timeout;
>  FD_ZERO(&fdset);
>  snmp_select_info(&fds, &fdset, &timeout, &block);
>  fds = select(fds, &fdset, 0,0, block ? 0 : &timeout);
>  if(fds) { snmp_read(&fdset); } else { snmp_timeout(); }
>
>
> I've been trying to do it with ffi-inliner, but haven't had much
> luck.  Any pointers would be appreciated.
>
>