develooper Front page | perl.perl5.porters | Postings from September 2012

Swapping SV bodies between two SV heads

Thread Next
September 5, 2012 05:28
Swapping SV bodies between two SV heads
Message ID:
I am wondering if anybody can give me some feedback on the following C/CS code.

Basically I need to be able to compile a regex INTO a specific empty
SV but the api does not support passing in the SV the regexp will be
compiled into.

So I came up with the following code which swaps the bodies of the SV
that CALLREGCOMP returns with the body of the SV (which will be
SVt_NULL) which I want the regexp to be compiled into.

Can anyone see anything wrong with this? So far the C/XS hackers I've
asked do not see a problem with it.

            /* compile the regex */
            SV *referent= (SV*)CALLREGCOMP(sv_pat, flags);
            SV tmp;

            /* make sure the SV came from us (it should) and
             * is bodyless */

            /* Swap the contents of the two heads. */
            Copy(into, &tmp, 1, SV);
            Copy((SV*)referent, into, 1, SV);
            Copy(&tmp, (SV*)referent, 1, SV);

Thanks a lot,

perl -Mre=debug -e "/just|another|perl|hacker/"

Thread Next Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at | Group listing | About