Monday, November 7, 2011

TypeError: can't convert Module into Integer (error in Ruby native extension)

For about 1/2 an hour today I was stuck on a single error:

TypeError: can't convert Module into Integer

The code in question was:

static VALUE qpid_receive(VALUE arg_timeout)
  int timeout =  FIX2INT(arg_timeout);

  // do some work with the timeout value

  return Qnil;

If I commented out the line that called FIX2INT() then the error went away. But for the life of me I couldn't figure out the problem.

Then I realized my error.

After googling the error message and finding no solutions, I realized I was missing an argument. Every native extension method must have, as the first argument, a VALUE argument that is a reference to the current execution context in Ruby.

So after changing the method signature to be:

static VALUE qpid_recieve(VALUE self, VALUE arg_timeout) { ... }

the error went away.

No comments:

Post a Comment