rbzip2 icon indicating copy to clipboard operation
rbzip2 copied to clipboard

FFI backend doesn't work on Windows

Open mbudnek opened this issue 7 years ago • 2 comments

BZip2's public API functions use the stdcall calling convention on Windows, but rbzip2 tries to load them using the default cdecl convention. This leads to the functions not being found by FFI:

C:/Ruby225/lib/ruby/gems/2.2.0/gems/ffi-1.9.18-x86-mingw32/lib/ffi/library.rb:275:in `attach_function': Function 'BZ2_bzRead' not found in [bz2] (FFI::NotFoundError)
        from C:/Ruby225/lib/ruby/gems/2.2.0/gems/rbzip2-0.3.0/lib/rbzip2/ffi/decompressor.rb:20:in `<class:Decompressor>'
        from C:/Ruby225/lib/ruby/gems/2.2.0/gems/rbzip2-0.3.0/lib/rbzip2/ffi/decompressor.rb:7:in `<top (required)>'
        from C:/my_script.rb:45:in `<main>'

mbudnek avatar Sep 13 '17 23:09 mbudnek

Looks like I’m unable to reproduce this. Can you give some detail about your setup (Windows, Ruby, bzip2 versions)?

koraktor avatar Sep 17 '17 20:09 koraktor

I'm using Ruby 2.2.5 32-bit from rubyinstaller.org, bzip2 1.0.6 built with Visual Studio 2010, FFI 1.9.18, and rbzip2 0.3.0.

I expect any version of Visual Studio will have this problem. You can see where bzip2 defines BZ_API(func) to WINAPI func (WINAPI being a macro that expands to __stdcall) on line 85 of bzlib.h. If you're building bzip2 with MinGW or similar then _WIN32 may not be defined, in which case the API will use the cdecl convention.

mbudnek avatar Sep 18 '17 14:09 mbudnek