jettero has asked for the wisdom of the Perl Monks concerning the following question:

I can't seem to find SvMAGICAL in any of the perl docs. I tried man perlapi, perlguts, perlxs, perlclib, perlinteral, and finally (cd /usr/share/man/man1; zgrep SvMAG perl*.gz), google, super search (here), etc.

Many people seem to use this function in their XS modules. I would appreciate hints on where to find documentation (if any) for this function.

I can get some things from context; but, I would prefer to know precisely what it does.

Replies are listed 'Best First'.
Re: SvMAGICAL() question
by idsfa (Vicar) on Jul 13, 2005 at 17:37 UTC

    Look for "Magic Variables" in the guts. Specifically, it is a C language macro in lib/CORE/sv.h:

    #define SvMAGICAL(sv) (SvFLAGS(sv) & (SVs_GMG|SVs_SMG|SVs_RMG))

    for examining an sv for the existance of these variables.


    The intelligent reader will judge for himself. Without examining the facts fully and fairly, there is no way of knowing whether vox populi is really vox dei, or merely vox asinorum. -- Cyrus H. Gordon
Re: SvMAGICAL() question
by Fletch (Bishop) on Jul 13, 2005 at 18:07 UTC

    You want to look at the section Magic Virtual Tables in perldoc perlguts where it talks about magic on SVs and how to set and retrieve it.

    --
    We're looking for people in ATL

      Well, that page proves it. Magic virtuals are way over my head. Is it possible to copy the magic virtuals from one SV to another SV from pure perl? (I suspect the answer is no.)
        Can you tell us what you want to accomplish? There may be a better way.
Re: SvMAGICAL() question
by samtregar (Abbot) on Jul 13, 2005 at 17:33 UTC
    Given the case I'd guess it tests a flag in the SV structure. And given the name I'd guess that flag indicated that there is magic set on the SV. Maybe it's a quick check to avoid calling the various mg_* functions when they're not needed?

    Of course, if you really want to know the best thing to do is to read the source. I'd start with sv.h since it's probably defined there. If you're lucky it'll come with a nice big comment.

    -sam

      Oh, right you are. It's clearly:
      #define SvMAGICAL(sv) (SvFLAGS(sv) & (SVs_GMG|SVs_SMG|SVs_RMG))
      Now, if only I knew what those flags were. Oh, I see. What a wonderful file, thanks.
      #define SVs_GMG 0x00002000 /* has magical get method */ #define SVs_SMG 0x00004000 /* has magical set method */ #define SVs_RMG 0x00008000 /* has random magical methods */
      I'm still not clear on what they are, but I have some idea where to start.
Re: SvMAGICAL() question
by Anonymous Monk on Jul 13, 2005 at 17:36 UTC
    It casts Magic Missile at the dark.