in reply to Re^2: Inline::C self-referential struct idioms and memory
in thread Inline::C self-referential struct idioms and memory


With the rise and rise of 'Social' network sites: 'Computers are making people easier to use everyday'
Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
"Science is about questioning the status quo. Questioning authority". I knew I was on the right track :)
In the absence of evidence, opinion is indistinguishable from prejudice.
I'm with torvalds on this Agile (and TDD) debunked I told'em LLVM was the way to go. But did they listen!

Replies are listed 'Best First'.
Re^4: Inline::C self-referential struct idioms and memory
by rutgeraldo (Novice) on Sep 04, 2015 at 16:00 UTC

    Mmmm... I'm trying out your version and I'm getting:

    perl(50784,0x7fff7dec7310) malloc: *** error for object 0x100000000000 +0000: pointer being freed was not allocated *** set a breakpoint in malloc_error_break to debug

    Presumably some kind of variation in Perl and OS? I notice you're on windows. I'm on OSX10.9, Perl version 5.16.2.

    ETA: the address 0x7fff7dec7310 is not any of the ones that show up in the Devel::Peek::Dump() outputs, by the way.

        If I only call the constructors but no getter/setters, and I put a while(1){} at the end of Node.pl it doesn't happen, the script just "waits" (loops). So one thing that triggers it is global object destruction.

        If I call set_parent($p), then an infinite loop, I notice that the destructor is triggered on the invocant $node (but not on $p). The malloc error doesn't happen. Note that the setter is not void: it returns the invocant. So there's a side effect to the conversion of the output in the typemap that makes a refcount drop to zero somewhere, triggering object destruction. However, a blessed reference to Node* is still returned.

        If I call set_parent twice, the malloc error happens.