Hole.xs

filter: Statementstmt 93.9% 31 / 33 Branchbran 68.7% 11 / 16 Conditioncond n/a MC/DCmcdc n/a Subroutinesub n/a Podpod n/a totaltotal 85.7% 42 / 49 CC 0 SCAR 0
CC
0
Cov
0%
CRAP 0
« blib/lib/Safe/Hole.pm ↑ Summary
1 /*
2 * Safe::Hole - make a hole to the original main compartment in the Safe compartment
3 * Copyright 1999-2001, Sey Nakajima, All rights reserved.
4 * This program is free software under the GPL.
5 */
6 #ifdef __cplusplus
7 extern "C" {
8 #endif
9 #include "EXTERN.h"
10 #include "perl.h"
11 #include "XSUB.h"
12 #include "ppport.h"
13 #ifdef __cplusplus
14 }
15 #endif
16  
17 #define OP_MASK_BUF_SIZE (MAXO + 100)
18  
19 /* A reference to a dummy string with the real opmask, if any, attached as magic */
20  
21 7 static SV* _get_current_opmask() {
22 SV *opmask;
23 7 SV *saved_PL_op_mask = NULL;
24 7 opmask = newSVpvn("Opcode Mask",11);
25 7 ▶ if ( PL_op_mask ) {
Branch: 1 branch
BranchTrueFalseTotal
if ( PL_op_mask ) { 3 4 7
26 3 saved_PL_op_mask = sv_2mortal(newSVpvn(PL_op_mask,OP_MASK_BUF_SIZE));
27 }
28 7 sv_magic(opmask,saved_PL_op_mask,'~',"Safe::Hole opmask",17);
29 7 return newRV_noinc(opmask);
30 }
31  
32 MODULE = Safe::Hole PACKAGE = Safe::Hole
33  
34 void
35 _hole_call_sv(stashref, opmask, codesv)
36 SV * stashref
37 SV * opmask
38 SV * codesv
39 PPCODE:
40 /*** This code is copied from Opcode::_safe_call_sv and modified ***/
41 GV *gv;
42 AV *av;
43 SV *saved_PL_op_mask;
44 MAGIC *magic;
45 I32 j,ac;
46  
47 59 ENTER;
48  
49 59 ▶ if ( SvTRUE(opmask)) {
Branch: 1 branch
BranchTrueFalseTotal
if ( SvTRUE(opmask)) { 55 4 59
50 55 SAVEVPTR(PL_op_mask);
51 110 if ( SvMAGICAL(opmask) &&
52 55 (magic = mg_find(opmask, '~')) &&
53 55 ▶ magic->mg_ptr &&
Branch: 1 branch
BranchTrueFalseTotal
magic->mg_ptr && 55 0 55
54 55 ▶ !strncmp(magic->mg_ptr,"Safe::Hole opmask",17) ) {
Branch: 1 branch
BranchTrueFalseTotal
!strncmp(magic->mg_ptr,"Safe::Hole opmask",17) ) { 55 0 55
55 55 ▶ if ( (saved_PL_op_mask = magic->mg_obj) ) {
Branch: 1 branch
BranchTrueFalseTotal
if ( (saved_PL_op_mask = magic->mg_obj) ) { 16 39 55
56 16 PL_op_mask = SvPVX(saved_PL_op_mask);
57 } else {
58 39 PL_op_mask = NULL;
59 }
60 } else {
61 0 croak("Opmask argument lacks suitable 'Safe::Hole opmask' magic");
62 }
63 }
64  
65 59 save_aptr(&PL_endav);
66 59 PL_endav = (AV*)sv_2mortal((SV*)newAV()); /* ignore END blocks for now */
67  
68 59 save_hptr(&PL_defstash); /* save current default stack */
69 59 save_hptr(&PL_globalstash); /* save current global stash */
70 /* the assignment to global defstash changes our sense of 'main' */
71 59 ▶ if( !SvROK(stashref) || SvTYPE(SvRV(stashref)) != SVt_PVHV )
Branch: 2 branches
BranchTrueFalseTotal
if( !SvROK(stashref) || SvTYPE(SvRV(stashref)) != SVt_PVHV ) 59 0 59
if( !SvROK(stashref) || SvTYPE(SvRV(stashref)) != SVt_PVHV ) 0 59 59
72 0 croak("stash reference required");
73 59 PL_defstash = (HV*)SvRV(stashref);
74 59 PL_globalstash = GvHV(gv_fetchpv("CORE::GLOBAL::", GV_ADDWARN, SVt_PVHV));
75  
76 /* defstash must itself contain a main:: so we'll add that now */
77 /* take care with the ref counts (was cause of long standing bug) */
78 /* XXX I'm still not sure if this is right, GV_ADDWARN should warn! */
79 59 gv = gv_fetchpv("main::", GV_ADDWARN, SVt_PVHV);
80 59 sv_free((SV*)GvHV(gv));
81 59 GvHV(gv) = (HV*)SvREFCNT_inc(PL_defstash);
82 59 ▶ PUSHMARK(SP);
Branch: 1 branch
BranchTrueFalseTotal
PUSHMARK(SP); 0 59 59
83  
84 59 call_sv(codesv, GIMME_V);
85 59 SPAGAIN; /* for the PUTBACK added by xsubpp */
86 59 LEAVE;
87  
88 SV*
89 _get_current_opmask()
« blib/lib/Safe/Hole.pm ↑ Summary