From: tsuraan@... Date: 2006-06-15T23:23:13+09:00 Subject: Re: Problems with Ruby and C++ > I've been using Ruby, SWIG and C++ on Linux for my development work and > am encountering some problems. The C++ consists of a built dynamic > library and I'm implementing SWIG the standard way > http://www.swig.org/Doc1.3/SWIGPlus.html > > The problem is, I seem to see memory getting corrupted when running the > Ruby program which calls the C++ library. When the Ruby program is run > on standalone, there are no problems. When the C++ dynamic library is > run with an equivalent C++ program, there are no problems. This leads > me > to believe that there are some "interactions" between Ruby and the C++ > library. Also, the Ruby program runs on a different thread than the > C++. > > Has anyone encoutered anything like this before? I don't really have much input, but maybe I can add some questions to spur discussion and prevent this post from dropping into obscurity :) You're using ruby in its own thread. Are you making calls into the ruby machine from the c++ thread? I'm not sure how thread-safe the ruby-library is, but I seem to remember that it's not terribly safe. I've had issues (with python/c++) where I failed to properly claim pointers to data recieved from python, so its garbage collector cleaned up the data that I was using. I don't know how swig handles this (I don't much like swig), but if your reference counts aren't being incremented and decremented properly, that can cause trouble. I'm hoping someone more knowledgeable than I can at least show why my questions are dumb or irrelevant. Maybe we can figure out what's going on... --jay