Debugging embedded ruby interpreter

Hello, I am trying to embed a ruby interpreter into my Haskell library. It didn't seem complicated, and went flawlessly until I tried using it a lot. Then I got segfaults. Here is a test program that corrupts the Array object that is being created : https://github.com/bartavelle/hruby/blob/271d99e26a5df075b1011e4b30adf6adddd... Changing line 46 to this makes it work: v <- pick (listOf arbitrary :: Gen [Double]) And this version makes it fail again : v <- pick (listOf subvalue :: Gen [Value]) As you can see, the "frequencies" of "subvalue" are set so that only JSON Values representing Doubles are generated. As the toRuby and fromRuby instances for Value are just pure wrappers over the instances for Double, the non-pure code that is executed should be the same. Am I wrong here ? Given that there is almost no documentation for doing this Ruby embedding, I am unsure that I am doing it right. I looked at the Hubris code and several other sources on the Internet, but can't find what is wrong with my implementation. I have no clue on how to debug this. Valgrind gives me a few "Conditional jump or move depends on uninitialised value(s)" during Ruby's gc, but I get more or less the same when just running the native interpreter. Also running this with the multithreaded runtime makes it fail immediately. Anyone has an idea on how I should approach this problem ?

On 05/22/2013 11:36 PM, Simon Marechal wrote:
Anyone has an idea on how I should approach this problem ?
For future reference : I believe I have found the problem, and it was quite obvious ... When generating Ruby objects from Haskell, they are not referenced by anything in the interpreter. This means they will be collected everytime there is a GC run. I now manually enable / disable / start GC, and things seem to work.
participants (1)
-
Simon Marechal