[Haskell-cafe] Need help with very simple C++ FFI call
allbery.b at gmail.com
Tue Nov 19 16:43:09 UTC 2013
On Tue, Nov 19, 2013 at 11:31 AM, Thiago Padilha <tpadilha84 at gmail.com>wrote:
> On Tue, Nov 19, 2013 at 1:19 PM, Brandon Allbery <allbery.b at gmail.com>
> > Also note that different memory allocators have different behaviors;
> Line 14(which causes the segfault) comment says the HandleScope is
> being allocated on the stack:
> // Create a stack-allocated handle scope.
> HandleScope handle_scope(isolate);
> I dont know any C++. Is it possible that this line of code is
> allocating something on the heap? If so could ghci have overriden
> memory allocation routines in a way that would mess that allocation?
I don't think ghc/ghci overrides malloc() like that. And it is possible
that the constructor, while allocating a stack object, also allocates some
heap-based memory; but that is a detail of the C++ code of the constructor.
That said, I believe g++ uses malloc/free behind the scenes for new/delete
to avoid such conflicts (this is common because it is often necessary to
mix C and C++ code, and it's just bad to have multiple memory allocators
working in the same heap).
(That said, the fact that it uses malloc/free behind the scenes does *not*
guarantee that you can substitute malloc() for new/new or free() for
delete/delete. But in this case, no C++ allocations should be escaping
the C++ code, so that also should not be relevant.)
It might be a good idea to run the test program under valgrind and see what
it has to say about the problem.
brandon s allbery kf8nh sine nomine associates
allbery.b at gmail.com ballbery at sinenomine.net
unix, openafs, kerberos, infrastructure, xmonad http://sinenomine.net
-------------- next part --------------
An HTML attachment was scrubbed...
More information about the Haskell-Cafe