This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
A new try at getting -fstack-protector working, by adding it to the
[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, 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 #ifdef STRUCT_MGVTBL_DEFINITION
12 STRUCT_MGVTBL_DEFINITION;
13 #else
14 struct mgvtbl {
15     int         (CPERLscope(*svt_get))  (pTHX_ SV *sv, MAGIC* mg);
16     int         (CPERLscope(*svt_set))  (pTHX_ SV *sv, MAGIC* mg);
17     U32         (CPERLscope(*svt_len))  (pTHX_ SV *sv, MAGIC* mg);
18     int         (CPERLscope(*svt_clear))(pTHX_ SV *sv, MAGIC* mg);
19     int         (CPERLscope(*svt_free)) (pTHX_ SV *sv, MAGIC* mg);
20     int         (CPERLscope(*svt_copy)) (pTHX_ SV *sv, MAGIC* mg,
21                                         SV *nsv, const char *name, int namlen);
22     int         (CPERLscope(*svt_dup))  (pTHX_ MAGIC *mg, CLONE_PARAMS *param);
23     int         (CPERLscope(*svt_local))(pTHX_ SV *nsv, MAGIC *mg);
24 };
25 #endif
26
27 struct magic {
28     MAGIC*      mg_moremagic;
29     MGVTBL*     mg_virtual;     /* pointer to magic functions */
30     U16         mg_private;
31     char        mg_type;
32     U8          mg_flags;
33     I32         mg_len;
34     SV*         mg_obj;
35     char*       mg_ptr;
36 };
37
38 #define MGf_TAINTEDDIR 1        /* PERL_MAGIC_envelem only */
39 #define MGf_MINMATCH   1        /* PERL_MAGIC_regex_global only */
40 #define MGf_REFCOUNTED 2
41 #define MGf_GSKIP      4
42 #define MGf_COPY       8        /* has an svt_copy  MGVTBL entry */
43 #define MGf_DUP     0x10        /* has an svt_dup   MGVTBL entry */
44 #define MGf_LOCAL   0x20        /* has an svt_local MGVTBL entry */
45
46 #define MgTAINTEDDIR(mg)        (mg->mg_flags & MGf_TAINTEDDIR)
47 #define MgTAINTEDDIR_on(mg)     (mg->mg_flags |= MGf_TAINTEDDIR)
48 #define MgTAINTEDDIR_off(mg)    (mg->mg_flags &= ~MGf_TAINTEDDIR)
49
50 #define MgPV(mg,lp)             ((((int)(lp = (mg)->mg_len)) == HEf_SVKEY) ?   \
51                                  SvPV((SV*)((mg)->mg_ptr),lp) :         \
52                                  (mg)->mg_ptr)
53 #define MgPV_const(mg,lp)       ((((int)(lp = (mg)->mg_len)) == HEf_SVKEY) ? \
54                                  SvPV_const((SV*)((mg)->mg_ptr),lp) :        \
55                                  (const char*)(mg)->mg_ptr)
56 #define MgPV_nolen_const(mg)    (((((int)(mg)->mg_len)) == HEf_SVKEY) ?   \
57                                  SvPV_nolen_const((SV*)((mg)->mg_ptr)) :  \
58                                  (const char*)(mg)->mg_ptr)
59
60 #define SvTIED_mg(sv,how) (SvRMAGICAL(sv) ? mg_find((sv),(how)) : NULL)
61 #define SvTIED_obj(sv,mg) \
62     ((mg)->mg_obj ? (mg)->mg_obj : sv_2mortal(newRV(sv)))