Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

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 */

   }
  • Loading branch information...
commit 557fbd17eba6e0db6dab333c82d35234963af435 1 parent 5e0b449
Father Chrysostomos authored

Showing 2 changed files with 14 additions and 1 deletion. Show diff stats Hide diff stats

  1. +13 0 pp.h
  2. +1 1  sv.h
13 pp.h
@@ -496,12 +496,25 @@ True if this op will be the return value of an lvalue subroutine
496 496 )
497 497
498 498 #ifdef PERL_CORE
  499 +
499 500 /* These are just for Perl_tied_method(), which is not part of the public API.
500 501 Use 0x04 rather than the next available bit, to help the compiler if the
501 502 architecture can generate more efficient instructions. */
502 503 # define TIED_METHOD_MORTALIZE_NOT_NEEDED 0x04
503 504 # define TIED_METHOD_ARGUMENTS_ON_STACK 0x08
504 505 # define TIED_METHOD_SAY 0x10
  506 +
  507 +/* Used in various places that need to dereference a glob or globref */
  508 +# define MAYBE_DEREF_GV(sv) \
  509 + ( \
  510 + SvGETMAGIC(sv), \
  511 + isGV_with_GP(sv) \
  512 + ? (GV *)sv \
  513 + : SvROK(sv) && (SvGETMAGIC(SvRV(sv)), isGV_with_GP(SvRV(sv))) \
  514 + ? (GV *)SvRV(sv) \
  515 + : NULL \
  516 + )
  517 +
505 518 #endif
506 519
507 520 /*
2  sv.h
@@ -1919,7 +1919,7 @@ Returns a pointer to the character buffer.
1919 1919 #define SvUNLOCK(sv) PL_unlockhook(aTHX_ sv)
1920 1920 #define SvDESTROYABLE(sv) PL_destroyhook(aTHX_ sv)
1921 1921
1922   -#define SvGETMAGIC(x) STMT_START { if (SvGMAGICAL(x)) mg_get(x); } STMT_END
  1922 +#define SvGETMAGIC(x) ((void)(SvGMAGICAL(x) && mg_get(x)))
1923 1923 #define SvSETMAGIC(x) STMT_START { if (SvSMAGICAL(x)) mg_set(x); } STMT_END
1924 1924
1925 1925 #define SvSetSV_and(dst,src,finally) \

0 comments on commit 557fbd1

Please sign in to comment.
Something went wrong with that request. Please try again.