conferences | speakers | series

Ruby-red onions: Peeling back Ruby's layers in C extensions

home

Ruby-red onions: Peeling back Ruby's layers in C extensions
FOSDEM 2015

The fact that Ruby has different implementations is strange but also powerful as it allows us to write extensions. Although writing an extension can be a daunting task, there's no better way to get to the heart of what exactly Ruby objects are and the reason for some of the language's quirks.

In this talk, we'll use an example of writing a C extension for Ruby to use a third-party C security library. We'll peel back the layers of Ruby objects to deepen our knowledge of MRI and to understand in a little more detail what it really means to write object-oriented code.

Ruby is a very high-level language and I've found that Rubyists often lack more lower-level knowledge concerning operating systems, memory management, differences with other languages, and typing. Writing a C or Java extension exposes some of these concepts to the Rubyist and highlights the uniqueness of the language. I would like to share some of what I've learned from writing C and Java extensions with the RubyConf audience.

In this presentation I'll use an example of writing a C extension so that Ruby code can make use of a third-party C security library. The topics I'll touch on are:

How to write a rake task so that your extension compiles when your gem installs How Ruby objects are represented in C code The appropriate C functions to use when going back and forth between Ruby objects and C code

Here is the c code: https://github.com/mongodb/mongo-ruby-driver/blob/1.x-stable/ext/csasl/csasl.c

Why I'm qualified as a speaker on this topic:

I had to write both a Java and C extension for the MongoDB Ruby driver using a sasl library for GSSAPI authentication against MongoDB. There was minimal documentation available for how to write extensions in Java or C and I learned a ton from having to figure it out on my own. Having written the extensions gives me a much deeper understanding of MRI in particular and general knowledge about programming languages.

I've given numerous talks at conferences, including RubyConf '13, invited to BaRuCo '14, RailsConf '13, RailsIsrael, RuLu, GoGaRuCo '13, GoRuCo '13, ScottishRuby, etc. I love giving talks and put a lot of heart and soul into the preparation. I've heard people usually think they're high quality = )

Speakers: Emily Stolfo