Beefy Boxes and Bandwidth Generously Provided by pair Networks
Keep It Simple, Stupid
 
PerlMonks  

Re^2: Sharing XS object?

by menth0l (Monk)
on Mar 09, 2011 at 14:14 UTC ( #892196=note: print w/ replies, xml ) Need Help??


in reply to Re: Sharing XS object?
in thread Sharing XS object?

I don't know if i understand this correctly:

# this produces error: "invalid value for shared scalar" my $o :shared = new Tree::BK_XS; # and this causes perl to crash my $o :shared = shared_clone(new Tree::BK_XS);
I always thought that that link that you've posted refers to hash-based, pure-perl objects?


Comment on Re^2: Sharing XS object?
Download Code
Re^3: Sharing XS object?
by BrowserUk (Pope) on Mar 09, 2011 at 14:39 UTC
    # this produces error: "invalid value for shared scalar" my $o :shared = new Tree::BK_XS;

    Which versions of perl/threads/threads::shared are you using?

    Show us the new() method of your module.


    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.
      Versions:
      Perl: ActiveState 5.10
      Threads: 1.82
      Threads-shared: 1.36
      My new() function from BK_XS.xs file:
      #include "EXTERN.h" #include "perl.h" #include "XSUB.h" #include "ppport.h" #include "BKTree.h" MODULE = Tree::BK_XS PACKAGE = Tree::BK_XS PREFIX= BK_ SV * BK_new(package) char * package PROTOTYPE: $ CODE: OBJECT t; SV *tp; t = new_object(); tp = newSVpv((char *)&t, sizeof(OBJECT)); RETVAL = newRV(tp); SvREFCNT_dec(tp); sv_bless(RETVAL, gv_stashpv(package, 0)); SvREADONLY_on(tp); OUTPUT: RETVAL

        If this is possible--I've never done it, mostly because I've never seen a need for it--then success will resolve around using the bless() function exported from threads::shared rather than the built-in version.

        Whilst it is possible to gain access to threads::shared::bless() from within your XS code, the simplest method to test whether it will actually work for you, would be to export the RV (RETVAL) from your XS new() (perhaps renamed _new()) un-blessed; and then add a wrapper method in the .pm file that calls the XS _new() and then applies the modified bless() (imported from threads::shared) at the Perl level before returning it.

        That should get you past the "Invalid value for shared scalar" problem. I do not expect it to be a complete solution. You will almost certainly have to add a CLONE() method to the package. And you will need to deal with the problem of multiple DESTROY()s. But one step at a time.

        If you module isn't proprietary, and doesn't have a raft of dependancies, and you were prepared to let me have an installable copy, it might make solving the knock on problems quicker.


        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.

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others avoiding work at the Monastery: (4)
As of 2015-07-06 03:23 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    The top three priorities of my open tasks are (in descending order of likelihood to be worked on) ...









    Results (70 votes), past polls