Subject:
Re: [ruby-ffi] :varargs sometimes works, sometimes don't
From:
Matijs van Zuijlen
Date:
4/27/10 3:42 PM
To:
ruby-ffi@googlegroups.com

Hi Marvin,

On 04/27/2010 07:19 PM, Quintus wrote:
- the second fails with a quite strange error message:
--------------------------------------------------------------
/opt/rubies/ruby-1.9.1-p378/lib/ruby/gems/1.9.1/gems/ffi-0.6.3/lib/ffi/
types.rb:46:in `find_type': Unable to resolve type
'string' (TypeError)
    from /opt/rubies/ruby-1.9.1-p378/lib/ruby/gems/1.9.1/gems/ffi-0.6.3/
lib/ffi/variadic.rb:47:in `call'
    from (eval):3:in `g_object_set'
    from gtkbox.rb:66:in `show'
    from gtkbox.rb:76:in `<main>'
-------------------------------------------------------------

What's the matter? As far as I know, :string as a regular type in
FFI.

Looking at the ffi code, the fact that you create two new types in the second example completely overrules the default type map when resolving varargs types. Looks like a bug to me.

And here's the (non-working) second:
-------------------------------------------------------------
[...]

           enum :type, [ :gtk_message_info,
                                 :gtk_message_warning,
                                 :gtk_message_question,
                                 :gtk_message_error,
                                 :gtk_message_other
                               ]

           enum :buttons, [:gtk_buttons_none,
                                     :gtk_button_ok,
                                     :gtk_buttons_close,
                                     :gtk_buttons_cancel,
                                     :gtk_buttons_yes_no,
                                     :gtk_buttons_ok_cancel
                                     ]

At this point, @ffi_typedefs contains :type and :buttons, and only varargs of those types will be recognized.

As a workaround, moving the attaching of g_object_set to before the enums makes the example run fine.

-- 
Matijs