File Coverage

const-xs.inc
Criterion Covered Total %
statement 17 33 51.5
branch 7 24 29.1
condition n/a
subroutine n/a
pod n/a
total 24 57 42.1


line stmt bran cond sub pod time code
1             BOOT:
2             {
3             #if defined(dTHX) && !defined(PERL_NO_GET_CONTEXT)
4             dTHX;
5             #endif
6 2           HV *symbol_table = get_hv("Dir::TempChdir::", GV_ADD);
7              
8             static const struct iv_s values_for_iv[] =
9             {
10             #ifdef O_PATH
11             { "O_PATH", 6, O_PATH },
12             #endif
13             #ifdef O_SEARCH
14             { "O_SEARCH", 8, O_SEARCH },
15             #endif
16             { NULL, 0, 0 } };
17 2           const struct iv_s *value_for_iv = values_for_iv;
18 4 100         while (value_for_iv->name) {
19 4           constant_add_symbol(aTHX_ symbol_table, value_for_iv->name,
20 2           value_for_iv->namelen, newSViv(value_for_iv->value));
21 2           ++value_for_iv;
22             }
23             if (C_ARRAY_LENGTH(values_for_notfound) > 1) {
24             #ifndef SYMBIAN
25 2           HV *const constant_missing = get_missing_hash(aTHX);
26             #endif
27 2           const struct notfound_s *value_for_notfound = values_for_notfound;
28             do {
29              
30             /* Need to add prototypes, else parsing will vary by platform. */
31 2           HE *he = (HE*) hv_common_key_len(symbol_table,
32             value_for_notfound->name,
33             value_for_notfound->namelen,
34             HV_FETCH_LVALUE, NULL, 0);
35             SV *sv;
36             #ifndef SYMBIAN
37             HEK *hek;
38             #endif
39 2 50         if (!he) {
40 0           croak("Couldn't add key '%s' to %%Dir::TempChdir::",
41             value_for_notfound->name);
42             }
43 2           sv = HeVAL(he);
44 2 50         if (!SvOK(sv) && SvTYPE(sv) != SVt_PVGV) {
    50          
45             /* Nothing was here before, so mark a prototype of "" */
46 2           sv_setpvn(sv, "", 0);
47 0 0         } else if (SvPOK(sv) && SvCUR(sv) == 0) {
    0          
48             /* There is already a prototype of "" - do nothing */
49             } else {
50             /* Someone has been here before us - have to make a real
51             typeglob. */
52             /* It turns out to be incredibly hard to deal with all the
53             corner cases of sub foo (); and reporting errors correctly,
54             so lets cheat a bit. Start with a constant subroutine */
55 0           CV *cv = newCONSTSUB(symbol_table,
56             value_for_notfound->name,
57             &PL_sv_yes);
58             /* and then turn it into a non constant declaration only. */
59 0           SvREFCNT_dec(CvXSUBANY(cv).any_ptr);
60 0           CvCONST_off(cv);
61 0           CvXSUB(cv) = NULL;
62 0           CvXSUBANY(cv).any_ptr = NULL;
63             }
64             #ifndef SYMBIAN
65 2           hek = HeKEY_hek(he);
66 2 50         if (!hv_common(constant_missing, NULL, HEK_KEY(hek),
67             HEK_LEN(hek), HEK_FLAGS(hek), HV_FETCH_ISSTORE,
68             &PL_sv_yes, HEK_HASH(hek)))
69 0           croak("Couldn't add key '%s' to missing_hash",
70             value_for_notfound->name);
71             #endif
72 2 50         } while ((++value_for_notfound)->name);
73             }
74             /* As we've been creating subroutines, we better invalidate any cached
75             methods */
76 2           mro_method_changed_in(symbol_table);
77             }
78              
79             void
80             constant(sv)
81             INPUT:
82             SV * sv;
83             PREINIT:
84 0           const PERL_CONTEXT *cx = caller_cx(0, NULL);
85             /* cx is NULL if we've been called from the top level. PL_curcop isn't
86             ideal, but it's much cheaper than other ways of not going SEGV. */
87 0 0         const COP *cop = cx ? cx->blk_oldcop : PL_curcop;
88             PPCODE:
89             #ifndef SYMBIAN
90             /* It's not obvious how to calculate this at C pre-processor time.
91             However, any compiler optimiser worth its salt should be able to
92             remove the dead code, and hopefully the now-obviously-unused static
93             function too. */
94             HV *constant_missing = (C_ARRAY_LENGTH(values_for_notfound) > 1)
95 0           ? get_missing_hash(aTHX) : NULL;
96 0 0         if ((C_ARRAY_LENGTH(values_for_notfound) > 1)
97 0           ? hv_exists_ent(constant_missing, sv, 0) : 0) {
98 0 0         sv = newSVpvf("Your vendor has not defined Dir::TempChdir macro %" SVf
99             ", used at %" COP_FILE_F " line %" UVuf "\n",
100             sv, COP_FILE(cop), (UV)CopLINE(cop));
101             } else
102             #endif
103             {
104 0 0         sv = newSVpvf("%" SVf
105             " is not a valid Dir::TempChdir macro at %"
106             COP_FILE_F " line %" UVuf "\n",
107             sv, COP_FILE(cop), (UV)CopLINE(cop));
108             }
109 0           croak_sv(sv_2mortal(sv));