in reply to Re^2: panic: memory wrap
in thread panic: memory wrap
Dave.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^4: panic: memory wrap
by BrowserUk (Patriarch) on Nov 14, 2005 at 16:11 UTC | |
Um, thanks, but could you give that cluebat a slightly heavier heft, and maybe go for the head-on strike rather than a glancing blow? The \ operator creates a temporary reference, which is usually freed at the end of the current statement. Obviously I cannot omit the \, as I would be calling the function rather than getting a reference to it. As far as I can tell, that means you are suggesting that I dereference the value I pass from the Perl code, once I get my hands on it inside the XS code? Part of the problem is that I am not at all sure what it is I am receiving inside the XS code? Dumping the (temporary) SV that I get from using \&sub using Devel::Peek, I see this:
Looking at perlcall there are 4 ways to invoke a sub, but only one of them, call_sv() uses a reference rather than a string that will need to be resolved every time. I'm using this, successfully, once. You're saving that tmp ref. Instead, just store the the thing pointed by the ref, ie the CV. From that, I take it that I should in some way be dereferenceing, or extracting something from the value I receive within the XS code, but looking at perlapi and perlcall, the only macro that seems to do anything related is
Which also takes an HV** and a GV**, gives no information on what I would do with those, or how I would invoke a CV* once had it? I also (previously) ran across the section of perlcall that starts with You should note that if it is necessary to store the SV (name in the example above) which corresponds to the Perl subroutine so that it can be used later in the program, it not enough just to store a copy of the pointer to the SV. Say the code above had been like this and attempted to follow the directions for saving a copy of the SV:
Update: Switched from svSetSV() to newSVsv(). This now works the first time and "panic: memory wrap"s the second and subsequent times. Full circle. Further cluebats requested. Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
Lingua non convalesco, consenesco et abolesco. -- Rule 1 has a caveat! -- Who broke the cabal?
"Science is about questioning the status quo. Questioning authority".
In the absence of evidence, opinion is indistinguishable from prejudice.
| [reply] [d/l] [select] |
by dave_the_m (Monsignor) on Nov 14, 2005 at 22:25 UTC | |
ie store a direct pointer to the CV rather than a pointer to a temporary RV that points to the CV. Note that call_sv() can take a CV as an arg. If setCallbacks() can be called more than once then you'll want to initialize the the pointers to Null, then on each call to setCallbacks(), SvREFCNT_dec() the existing g_rec and g_play if they're non-null. Dave | [reply] [d/l] |
by BrowserUk (Patriarch) on Nov 14, 2005 at 23:06 UTC | |
Thanks again, for now, setCallback() is only being called once... but it still panics on the second callback, whether to the same callback as the first successful one, or a different one being called for the first time? That it works the first time and fails the second, still makes me think I am messing up the stack somehow? As you'll see below, I've had various attempts at ensuring that the stack is cleaned up. I've tried both the Inline_* macros and the XS macros to no avail?
Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
Lingua non convalesco, consenesco et abolesco. -- Rule 1 has a caveat! -- Who broke the cabal?
"Science is about questioning the status quo. Questioning authority".
In the absence of evidence, opinion is indistinguishable from prejudice.
| [reply] [d/l] |
by dave_the_m (Monsignor) on Nov 15, 2005 at 00:52 UTC | |
by BrowserUk (Patriarch) on Nov 15, 2005 at 01:06 UTC | |
by Will_the_Chill (Pilgrim) on Dec 23, 2013 at 12:14 UTC | |
by BrowserUk (Patriarch) on Nov 15, 2005 at 23:45 UTC | |
Sorry to bug you again, but I'm trying to work out how I could have gotten to the working solution without your having to lead me by the nose. Note that call_sv() can take a CV as an arg Is this written down somewhere I should have been looking? Or is it something you picked up/worked out from experience. Also, you led me to using g_rec = SvREFCNT_inc(SvRV(rec)); to safely replicate the CV* for the callback and detailed the need to decrement the refcount before replacing the CV*, if the callback addesses are changed. In perlcall, they suggest a combination of newSVsv() and SvSetSV() to do this, which if I've unwound the macros correctly, amounts to much the same thing, except that your way sheds a level of indirection? Did I understand that right? Can you see any particular advantage of one over the other? Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
Lingua non convalesco, consenesco et abolesco. -- Rule 1 has a caveat! -- Who broke the cabal?
"Science is about questioning the status quo. Questioning authority".
In the absence of evidence, opinion is indistinguishable from prejudice.
| [reply] [d/l] [select] |
by dave_the_m (Monsignor) on Nov 16, 2005 at 00:32 UTC | |