• Like
  • Save
Ruby FFI
Upcoming SlideShare
Loading in...5
×
 

Ruby FFI

on

  • 3,691 views

A small lightning talk on Ruby's FFI module for integrating system libraries.

A small lightning talk on Ruby's FFI module for integrating system libraries.

Statistics

Views

Total Views
3,691
Views on SlideShare
3,674
Embed Views
17

Actions

Likes
0
Downloads
10
Comments
0

3 Embeds 17

https://twitter.com 14
http://www.linkedin.com 2
https://www.linkedin.com 1

Accessibility

Categories

Upload Details

Uploaded via as Apple Keynote

Usage Rights

© All Rights Reserved

Report content

Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel
  • Full Name Full Name Comment goes here.
    Are you sure you want to
    Your message goes here
    Processing…
Post Comment
Edit your comment
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n

Ruby FFI Ruby FFI Presentation Transcript

  • Ruby FFIThe Foreign Function Interface for accessing system wide shared libraries in Ruby Angel Pizarro angel@upenn.edu
  • Ruby C Extension API• Ruby has a C extension mechanism • Use SWIG to wrap a C API • Non-idiomatic Ruby :( • Also IO struct changed between 1.8 and 1.9, SWIG needs new typemap • Write your own C modules using this API • Other Ruby VM’s out in the cold
  • Ruby FFI• Foreign Function Interface, based on libffiA foreign function interface [...] allows code written inone language to call code written in another language.The libffi library really only provides the lowest,machine dependent layer of a fully featured foreignfunction interface. A layer must exist above libffi thathandles type conversions for values passed between thetwo languages.• MRI, MacRuby, Rubinius and JRuby support
  • Given a C API : libcairo
  • Mapping Functions
  • Function Input Args
  • Function Input ArgsThat sucks! We lose all method signature information!
  • Types, Enums & Constants
  • Types, Enums & Constants still sucks
  • Types, Enums & Constants still sucks Alias a type: Method sig now becomes nicer:
  • Structs
  • Managed Structs DANGER WILL ROBINSON!Only use if you REALLY want Ruby GC to manage references and memory
  • Final Notes• Beware library calls that open STIN / STDOUT to buffer writes • Specifically, they may close the socket and Ruby IO becomes FUBAR• Multi-dimensional arrays in structs not supported (“unroll” the previous dimension)• Do not use ManagedStruct if you just want type casting on a pointer ref• Essentially still using C idioms to code (e.g. memory management)