On Thu, Jul 31, 2014 at 6:09 PM, Jeffrey 'jf' Lim <jfs.world / gmail.com>
wrote:

> On Thu, Jul 31, 2014 at 6:03 PM, Jeffrey 'jf' Lim <jfs.world / gmail.com>
> wrote:
>
>> As per subject.
>>
>> If you have the latest libffi version (3.1) installed, fiddle wont be
>> configured.
>>
>> The offending section in extconf.rb:
>> ========
>>   7 pkg_config("libffi")
>>   8 if ver = pkg_config("libffi", "modversion")
>>   9   ver = ver.gsub(/-rc\d+/, '') # If ver contains rc version, just
>> ignored.
>>  10   $defs.push(%{-DRUBY_LIBFFI_MODVERSION=#{ '%d%03d' % ver.split('.')
>> }})
>>  11 end
>> ========
>>
>> I'm not too sure what the idiomatic approach would be; how about the
>> following?
>>
>> ===============
>> --- ext/fiddle/extconf.rb.orig    2013-05-19 10:42:16.000000000 +0800
>> +++ ext/fiddle/extconf.rb    2014-07-31 18:00:47.000000000 +0800
>> @@ -7,7 +7,8 @@
>>  pkg_config("libffi")
>>  if ver = pkg_config("libffi", "modversion")
>>    ver = ver.gsub(/-rc\d+/, '') # If ver contains rc version, just
>> ignored.
>> -  $defs.push(%{-DRUBY_LIBFFI_MODVERSION=#{ '%d%03d%03d' % ver.split('.')
>> }})
>> +  ver_split = ver.split('.')
>> +  $defs.push(%{-DRUBY_LIBFFI_MODVERSION=#{ ('%d' +
>> '%03d'*(versplit.length-1)) % versplit }})
>>  end
>>
>>  unless have_header('ffi.h')
>> =================
>>
>>
>
> or indeed the "correct" way? Do we use/assume "3.1.0" for "3.1" instead,
> for example?
>
>
ok, sorry my bad. Indeed it does (ext/fiddle/closure.c to be precise!)
depends on RUBY_LIBFFI_MODVERSION being generated off of a 3-digit 'ver').
So the correct patch should this instead:

==========
--- ext/fiddle/extconf.rb.orig    2013-05-19 10:42:16.000000000 +0800
+++ ext/fiddle/extconf.rb    2014-07-31 23:39:34.000000000 +0800
@@ -7,7 +7,9 @@
 pkg_config("libffi")
 if ver = pkg_config("libffi", "modversion")
   ver = ver.gsub(/-rc\d+/, '') # If ver contains rc version, just ignored.
-  $defs.push(%{-DRUBY_LIBFFI_MODVERSION=#{ '%d%03d%03d' % ver.split('.')
}})
+  ver_split = ver.split('.')
+  ver_split.push '0' if ver_split.length == 2
+  $defs.push(%{-DRUBY_LIBFFI_MODVERSION=#{ '%d%03d%03d' % ver_split }})
 end

 unless have_header('ffi.h')
===========

thanks,
-jf