This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
Increase $B::VERSION to 1.51
[perl5.git] / mg.h
1 /*    mg.h
2  *
3  *    Copyright (C) 1991, 1992, 1993, 1994, 1995, 1996, 1997, 1999,
4  *    2000, 2002, 2005, 2006, 2007, 2008 by Larry Wall and others
5  *
6  *    You may distribute under the terms of either the GNU General Public
7  *    License or the Artistic License, as specified in the README file.
8  *
9  */
10
11 struct mgvtbl {
12     int         (*svt_get)      (pTHX_ SV *sv, MAGIC* mg);
13     int         (*svt_set)      (pTHX_ SV *sv, MAGIC* mg);
14     U32         (*svt_len)      (pTHX_ SV *sv, MAGIC* mg);
15     int         (*svt_clear)(pTHX_ SV *sv, MAGIC* mg);
16     int         (*svt_free)     (pTHX_ SV *sv, MAGIC* mg);
17     int         (*svt_copy)     (pTHX_ SV *sv, MAGIC* mg,
18                                         SV *nsv, const char *name, I32 namlen);
19     int         (*svt_dup)      (pTHX_ MAGIC *mg, CLONE_PARAMS *param);
20     int         (*svt_local)(pTHX_ SV *nsv, MAGIC *mg);
21 };
22
23 struct magic {
24     MAGIC*      mg_moremagic;
25     MGVTBL*     mg_virtual;     /* pointer to magic functions */
26     U16         mg_private;
27     char        mg_type;
28     U8          mg_flags;
29     SSize_t     mg_len;
30     SV*         mg_obj;
31     char*       mg_ptr;
32 };
33
34 #define MGf_TAINTEDDIR 1        /* PERL_MAGIC_envelem only */
35 #define MGf_MINMATCH   1        /* PERL_MAGIC_regex_global only */
36 #define MGf_REQUIRE_GV 1        /* PERL_MAGIC_checkcall only */
37 #define MGf_REFCOUNTED 2
38 #define MGf_GSKIP      4        /* skip further GETs until after next SET */
39 #define MGf_COPY       8        /* has an svt_copy  MGVTBL entry */
40 #define MGf_DUP     0x10        /* has an svt_dup   MGVTBL entry */
41 #define MGf_LOCAL   0x20        /* has an svt_local MGVTBL entry */
42 #define MGf_BYTES   0x40        /* PERL_MAGIC_regex_global only */
43
44 #define MgTAINTEDDIR(mg)        (mg->mg_flags & MGf_TAINTEDDIR)
45 #define MgTAINTEDDIR_on(mg)     (mg->mg_flags |= MGf_TAINTEDDIR)
46 #define MgTAINTEDDIR_off(mg)    (mg->mg_flags &= ~MGf_TAINTEDDIR)
47
48 #define MgPV(mg,lp)             ((((int)(lp = (mg)->mg_len)) == HEf_SVKEY) ?   \
49                                  SvPV(MUTABLE_SV((mg)->mg_ptr),lp) :    \
50                                  (mg)->mg_ptr)
51 #define MgPV_const(mg,lp)       ((((int)(lp = (mg)->mg_len)) == HEf_SVKEY) ? \
52                                  SvPV_const(MUTABLE_SV((mg)->mg_ptr),lp) :   \
53                                  (const char*)(mg)->mg_ptr)
54 #define MgPV_nolen_const(mg)    (((((int)(mg)->mg_len)) == HEf_SVKEY) ? \
55                                  SvPV_nolen_const(MUTABLE_SV((mg)->mg_ptr)) : \
56                                  (const char*)(mg)->mg_ptr)
57
58 #define SvTIED_mg(sv,how) (SvRMAGICAL(sv) ? mg_find((sv),(how)) : NULL)
59 #define SvTIED_obj(sv,mg) \
60     ((mg)->mg_obj ? (mg)->mg_obj : sv_2mortal(newRV(sv)))
61
62 #if defined(PERL_CORE) || defined(PERL_EXT)
63 # define MgBYTEPOS(mg,sv,pv,len) S_MgBYTEPOS(aTHX_ mg,sv,pv,len)
64 /* assumes get-magic and stringification have already occurred */
65 # define MgBYTEPOS_set(mg,sv,pv,off) (                   \
66     assert_((mg)->mg_type == PERL_MAGIC_regex_global)     \
67     SvPOK(sv) && !SvGMAGICAL(sv)                           \
68         ? (mg)->mg_len = (off), (mg)->mg_flags |= MGf_BYTES \
69         : ((mg)->mg_len = DO_UTF8(sv)                        \
70             ? (SSize_t)utf8_length((U8 *)(pv), (U8 *)(pv)+(off)) \
71             : (SSize_t)(off),                                     \
72            (mg)->mg_flags &= ~MGf_BYTES))
73 #endif
74
75 #define whichsig(pv) whichsig_pv(pv)
76
77 /*
78  * Local variables:
79  * c-indentation-style: bsd
80  * c-basic-offset: 4
81  * indent-tabs-mode: nil
82  * End:
83  *
84  * ex: set ts=8 sts=4 sw=4 et:
85  */