diff options
author | Father Chrysostomos <sprout@cpan.org> | 2011-09-10 06:09:26 -0700 |
---|---|---|
committer | Father Chrysostomos <sprout@cpan.org> | 2011-09-10 06:43:49 -0700 |
commit | 557fbd17eba6e0db6dab333c82d35234963af435 (patch) | |
tree | 6358eda4d27dec8b83abf5d7a698818c312433ee /pp.h | |
parent | 5e0b4493cc341303b7c3c0606ba927b605e53a62 (diff) | |
download | perl-557fbd17eba6e0db6dab333c82d35234963af435.tar.gz |
Add MAYBE_DEREF_GV macro
There are so many parts of the core (mostly pp functions or functions
they call) that need a glob or a globref, including many that call
get-magic at the wrong time (or not at all in some cases, that it
makes sense to add a macro to do it.
It can be used like this:
if (gv = MAYBE_DEREF_GV(sv)) /* calls get-magic */
{
}
else { /* avoid magic here */
}
Diffstat (limited to 'pp.h')
-rw-r--r-- | pp.h | 13 |
1 files changed, 13 insertions, 0 deletions
@@ -496,12 +496,25 @@ True if this op will be the return value of an lvalue subroutine ) #ifdef PERL_CORE + /* These are just for Perl_tied_method(), which is not part of the public API. Use 0x04 rather than the next available bit, to help the compiler if the architecture can generate more efficient instructions. */ # define TIED_METHOD_MORTALIZE_NOT_NEEDED 0x04 # define TIED_METHOD_ARGUMENTS_ON_STACK 0x08 # define TIED_METHOD_SAY 0x10 + +/* Used in various places that need to dereference a glob or globref */ +# define MAYBE_DEREF_GV(sv) \ + ( \ + SvGETMAGIC(sv), \ + isGV_with_GP(sv) \ + ? (GV *)sv \ + : SvROK(sv) && (SvGETMAGIC(SvRV(sv)), isGV_with_GP(SvRV(sv))) \ + ? (GV *)SvRV(sv) \ + : NULL \ + ) + #endif /* |