Beefy Boxes and Bandwidth Generously Provided by pair Networks
Problems? Is your data what you think it is?
 
PerlMonks  

Re: Re[4]: How's your Perl?

by BrowserUk (Patriarch)
on Oct 28, 2003 at 12:45 UTC ( [id://302674]=note: print w/replies, xml ) Need Help??


in reply to Re[4]: How's your Perl?
in thread How's your Perl?

I will finally admit :) that whilst I think I know the When and the Where, I haven't a clue as to the Why!

P:\test>perl -MO=Concise -e"sub f{}; goto +f" b <@> leave[t1] vKP/REFC ->(end) 3 <0> enter ->4 4 <;> nextstate(main 2 -e:1) v ->5 a <1> goto vKS/1 ->b 9 <1> refgen sK/1 ->a ## <<<HERE. - <1> ex-list lKRM ->9 5 <0> pushmark sRM ->6 8 <1> entersub[t2] lKRMS/NO(),TARG,INARGS,1 ->9 - <1> ex-list lK ->8 6 <0> pushmark s ->7 - <1> ex-rv2cv sK/129 ->- 7 <#> gv s ->8 -e syntax OK

Even wading through pp_goto, I couldn't quite work out why it only happens if the function is called in a list context, or indeed why it takes a reference at all. Gut feel tells me its something to do with the fact that the code tries for the goto SUB; variation prior to the goto -LABEL and goto -EXPR variations, and that something is being stacked and not cleaned up, but that's about as far as I got before my brain went into overload.

One good thing came out of it. I now have a much better appreciation of why goto \&func is so gaddamn slow. All that chundering around unwinding stack frames, validating the target isn't a prohibited one etc. I never imagined. I'd always invisioned a simple longjump().


Examine what is said, not who speaks.
"Efficiency is intelligent laziness." -David Dunham
"Think for yourself!" - Abigail
Hooray!

Replies are listed 'Best First'.
Re[6]: How's your Perl?
by xmath (Hermit) on Oct 28, 2003 at 18:27 UTC
    ok, here's why:

    initially at parse time a goto-expression is free of special cases, so goto &foo is just a goto-element with the ENTERSUB expression &foo as argument. Now, the "goto SUB" variation needs a subref ofcourse, and to accomplish this perl effectively puts a \ in front of the argument, turning goto &foo into goto \&foo. Now here comes the problem: it does this whenever the argument is an ENTERSUB, and forgets to check for the ampersand (!(o->op_flags & OPf_STACKED)), so goto +foo becomes goto \foo, which results in the strange error message (the +-prefix is already dropped at parse time, and is just to prevent the special-case handling for goto LABEL to be triggered)

    Questions? :-)

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others having a coffee break in the Monastery: (7)
As of 2024-03-29 12:51 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found