ruby - Error in irb free() invalid size error when calling library from FFI -
description
i trying call omnipage ocr library ruby using ffi on linux. in particular, there recprocesspagesex
method following signature:
recerr recapipls recprocesspagesex ( int sid, lpctstr pdocfile, lpctstr * pimagefiles, lponetouch_cb pcallback, void * pcontext )
i've defined methods in ruby (note :rec_err
enum type definition defined elsewhere):
module omnipage extend ffi::library nuance_directory = '/usr/local/lib/nuance-omnipage-csdk-lib64-19.2/'.freeze lib_paths = %w(librecapiplus.so libkernelapi.so libtxtconv.so librtfconv.so).map |file| file.join(nuance_directory, file) end ffi_lib lib_paths attach_function :init, :recinitplusa, [:pointer, :pointer], :rec_err attach_function :set_license, :krecsetlicensea, [:pointer, :pointer], :rec_err attach_function :set_output_format, :recsetoutputformata, [:int, :pointer], :rec_err attach_function :set_output_level, :recsetoutputlevel, [:int, :output_level], :rec_err attach_function :recprocesspagesexa, [:int, :string, :pointer, :pointer, :pointer], :rec_err def self.process_pages(id, output_file, *images) ffi::memorypointer.new(:pointer, images.length + 1) |p_images_array| p_images = images.map(&ffi::memorypointer.method(:from_string)) << nil p_images_array.write_array_of_pointer p_images return recprocesspagesexa(id, output_file, p_images_array, nil, nil) end end end
the various calls set license , initialize license works fine...however when call omnipage.process_pages
method i've written, looks it's calling it, when returns irb
blows following:
*** error in `irb': free(): invalid size: 0x00007f65fcefc360 *** aborted shell returned 134
at point, i'm unsure how proceed. i've tried recprocessspagesexu8
variant of method call see if might case, no avail. is 64-bit library, though ffi
seems aware it's 64-bit process didn't think issue.
any appreciated.
update #1
so here's odd thing...i wrote omnipage.cpp
wrapper eliminate me being dumb ffi. here looked like:
#include <recapiplus.h> extern "c" { int processpages() { const char* pimagefiles[2] = {"<path file>", null}; return recprocesspagesex(0, "<output file>", pimagefiles, null, null); } }
i compiled with:
gcc -shared -o omnipage.so -fpic omnipage.cpp -l $ocrlibpath -lrecapiplus -lkernelapi -lrecpdf -wl,-rpath-link,$ocrlibpath,-rpath,$ocrlibpath
and updated ffi definition this:
module omnipage extend ffi::library ffi_lib 'omnipage.so' attach_function :process_pages, :processpages, [], :int end
this yields exact same error:
*** error in `irb': free(): invalid size: 0x00007fb858a99360 *** aborted shell returned 134
so doesn't seem have @ passing in memory pointers via ffi. has else seen before?
Comments
Post a Comment