Beefy Boxes and Bandwidth Generously Provided by pair Networks
There's more than one way to do things
 
PerlMonks  

Perl_API get_sv and SvIV_set

by BUU (Prior)
on Apr 16, 2006 at 23:30 UTC ( #543725=perlquestion: print w/ replies, xml ) Need Help??
BUU has asked for the wisdom of the Perl Monks concerning the following question:

I'm playing with patching the perl source and am attempting to create a new super global variable for nefarious purposes. I've added the following code to one of the opcodes in pp_ctl.c:
SV* super_i; super_i = get_sv("main::buu_test_i", TRUE); SvIV_set(super_i, 42);
Which *seems* to work properly. Unfortunately once I compile I can't seem to access my new variable from perl code. That is, when I try to print out what I think is the variable I just set I get undef. Do I need some special magic to make it accessible from perl, or do I need a specific perl command to invoke it? (I've tried $buu_test_i, $main::buu_test_i, and so on).

Comment on Perl_API get_sv and SvIV_set
Download Code
Re: Perl_API get_sv and SvIV_set
by salva (Abbot) on Apr 16, 2006 at 23:34 UTC
    you also have to tell perl that the integer on the IV slot is good with SvIOK_on():
    SV* super_i; super_i = get_sv("main::buu_test_i", TRUE); SvIV_set(super_i, 42); SvIOK_on(super_i);
      Ah, you are completely correct and it works happily. However I wonder if you could answer another question. I am trying to find an op that gets called at the 'end' of every loop, just before the next iteration begins. Is there any such beast? The B module seems to imply that pp_redo is called, but in my tests it doesn't seem to be. Any ideas?

        It sounds like you are looking for the opcode equivalent of the 'continue' statement. From a casual look at the differences in the output of these two commands:

        perl -MO=Concise -e 'while ($z == 1) { $x=2;} continue {$y=3;}' perl -MO=Concise -e 'while ($z == 1) { $x=2;}'
        I would guess that the opcode is 'pp_next'.

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: perlquestion [id://543725]
Approved by ikegami
Front-paged by Courage
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others imbibing at the Monastery: (6)
As of 2014-12-20 10:41 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    Is guessing a good strategy for surviving in the IT business?





    Results (95 votes), past polls