in reply to Re^16: Perl crash during perl_clone
in thread Perl crash during perl_clone

Hi BrowserUk,

Thanks again for the response. I will try tomorrow, but I'm also fairly positive, these versions will work for me too..Fundamentally, there seems no issue with callbacks perse, as long as I comply with your comment that.

If I try to pass the callback addresses by code-reference instead of name, I too get traps. I don't know why, so don't do that.

Although, it is strange why the code-ref way works, reliably, for one of my callbacks registered this way.

I had tried, but the SWIG typemaps I have currently did not allow the 'modulename:subname' format to register the callbacks. I'll have to dig into that more. Will hopefully have good news to share tomorrow!

Replies are listed 'Best First'.
Re^18: Perl crash during perl_clone
by BrowserUk (Patriarch) on Nov 08, 2010 at 15:42 UTC
    I had tried, but the SWIG typemaps I have currently did not allow the 'modulename:subname' format to register the callbacks.

    I don't understand this. The SWIG stuff wraps the registering of the CCB, not the PCB.

    So you "register" the PCB--by storing the SV* you pass into your code. You then call that stored SV* (using call_sv()) when the SWIG stuff calls back you CCB.

    I agree that call_sv() should handle coderefs (according to the documentation; I even think I've done it in the past on 5.8x era perls), but every time I've tried it recently, it falls in a heap with coderefs (with or without threads involved), and works as advertised with a function name. So I stick with the latter. It does mean you have to name the callbacks rather than use anonymous subs or blocks, but that is an acceptable limitation (for me).

    I having trouble understanding why you cannot do the same?


    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".
    In the absence of evidence, opinion is indistinguishable from prejudice.

      I may have made some other mistake when I tried the SWIG wrapper experiment.

      Its quite late in the night here and I hope I'm not celebrating too early: I think I figured out the cause for the seg-faults in the sample code (myModule version) and my real project.

      The problem seems to be that the \&module:sub syntax is somehow a temporary reference and was out of scope by the time my callback was invoked. The reason it worked in one of my callbacks was sheer coincidence: a scalar that was holding a reference to the sub was still in scope when the callback is called.

      In the RegisterCB function, by doing a newSVsv() and then using that new SV as the PCB always seem to keep the reference in scope/valid when the PCB is called. This newSVsv() was in the first version of my code that did the perl_clone, but I had removed it along with a bunch of other code, thinking it was not necessary.

      I'll try to reconfirm tomorrow when I'm more awake :-) Let me know if it works for you and if it makes sense.

        Let me know if it works for you and if it makes sense.

        Sorry, you lost me there ) I can't see where you could put newSVsv() in RegisterCB(); much less need to...

        'fraid you'll have to draw me a picture of that one :)