Beefy Boxes and Bandwidth Generously Provided by pair Networks
Just another Perl shrine
 
PerlMonks  

Re^2: Inline::C callbacks to Perl

by Animator (Hermit)
on Nov 11, 2005 at 21:40 UTC ( [id://507874]=note: print w/replies, xml ) Need Help??


in reply to Re: Inline::C callbacks to Perl
in thread Inline::C callbacks to Perl

I agree with what [id://liverpole] is saying.

What is happening is that the SV that is holding the reference gets destroyed. Storing it in a variable leads to the same problem. (When the variable goes out of scope that is).

The proper way to prevent this from happening is to increase the reference counter of the code-SV. (Since that will prevent the reference counter of the (temp) variable to become 0. Meaning Perl won't destroy it.)

(You can do this by using SvREFCNT_inc(code);. You can read more about the function/macro in perlapi)

Update: changed wording

Replies are listed 'Best First'.
Re^3: Inline::C callbacks to Perl
by BrowserUk (Patriarch) on Nov 11, 2005 at 22:52 UTC

    Spot on, thanks. Incrementing the ref count in setCallback sorted me right out.


    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.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://507874]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others drinking their drinks and smoking their pipes about the Monastery: (2)
As of 2024-04-26 00:35 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found