Forum: Ruby on Rails Stack level too deep error

F27ec882c17760270f028a61f4ab1b9e?d=identicon&s=25 Liz Huang (Guest)
on 2014-08-27 20:21
(Received via mailing list)
I tried to call an external library which worked in older version of
Ruby
On Rails with DL, but I couldn't get it working in newer version of Ruby
On
Rails using fiddle, the error message is "stack level too deep". I tried
several new versions of Ruby without success. After some digging, it
seems
that it works in Ruby script, but not if I use thread, see codes posted
below, I suspect that it might be an issue with stack size (when use
thread) ? I actually tried to comment out codes to generate newer
external
library to find out where the crash is, and find that the program
crashes
at a loop with 20000 loops when computing entries for a 4X20000 matrix.
Any
advice to fix this? Thanks!

Working ruby script:

require 'fiddle/import'

module Libm
extend Fiddle::Importer
dlload '/Library/WebServer/smart/lib/libsamplesize.dylib'
extern 'long Calculate(long, double, double, char*)'
end

errmsg = " "

puts Libm.Calculate( 1000, 0.2, 0.9, errmsg)

Not working in thread:

require 'fiddle/import'

module Libm
extend Fiddle::Importer
dlload '/Library/WebServer/smart/lib/libsamplesize.dylib'
extern 'long Calculate(long, double, double, char*)'
end

puts "Started At #{Time.now}"
errmsg = " "
thr1=Thread.new{ puts Libm.Calculate( 1000, 0.2, 0.9, errmsg)}
thr1.join
puts "End at #{Time.now}"
Please log in before posting. Registration is free and takes only a minute.
Existing account

NEW: Do you have a Google/GoogleMail, Yahoo or Facebook account? No registration required!
Log in with Google account | Log in with Yahoo account | Log in with Facebook account
No account? Register here.