src/MMagic.xs

filter: Statementstmt 85.1% 23 / 27 Branchbran 71.4% 10 / 14 Conditioncond n/a MC/DCmcdc n/a Subroutinesub n/a Podpod n/a totaltotal 80.4% 33 / 41 CC 0 SCAR 0
CC
0
Cov
0%
CRAP 0
« src/perl-mmagic-xs.c ↑ Summary
1 #include "perl-mmagic-xs.h"
2  
3 static int
4 9 PerlFMM_mg_free(pTHX_ SV *const sv, MAGIC *const mg)
5 {
6 fmmagic *m;
7 fmmagic *md;
8 9 PerlFMM *const state = (PerlFMM *) mg->mg_ptr;
9  
10 PERL_UNUSED_VAR(sv);
11 2991 ▶ for (m = state->magic; m; ) {
Branch: 1 branch
BranchTrueFalseTotal
for (m = state->magic; m; ) { 2982 9 2991
12 2982 md = m;
13 2982 m = m->next;
14 2982 Safefree(md);
15 }
16 9 state->last = NULL;
17  
18 9 ▶ if (state->ext) {
Branch: 1 branch
BranchTrueFalseTotal
if (state->ext) { 9 0 9
19 9 st_free_table(state->ext);
20 }
21  
22 9 ▶ if (state->error != NULL) {
Branch: 1 branch
BranchTrueFalseTotal
if (state->error != NULL) { 1 8 9
23 1 SvREFCNT_dec(state->error);
24 1 state->error = NULL;
25 }
26 9 Safefree(state);
27 9 return 0;
28 }
29  
30 static int
31 0 PerlFMM_mg_dup(pTHX_ MAGIC *const mg, CLONE_PARAMS *const param)
32 {
33 #ifdef USE_ITHREADS
34 PerlFMM *const state = (PerlFMM*) mg->mg_ptr;
35 PerlFMM *newstate;
36  
37 PERL_UNUSED_VAR(param);
38  
39 newstate = PerlFMM_clone(state);
40 mg->mg_ptr = (char *) newstate;
41 #else
42 PERL_UNUSED_VAR(mg);
43 PERL_UNUSED_VAR(param);
44 #endif
45 0 return 0;
46 }
47  
48 static MAGIC*
49 81 PerlFMM_mg_find(pTHX_ SV* const sv, const MGVTBL* const vtbl){
50 MAGIC* mg;
51  
52 assert(sv != NULL);
53 assert(vtbl != NULL);
54  
55 81 ▶ for(mg = SvMAGIC(sv); mg; mg = mg->mg_moremagic){
Branch: 1 branch
BranchTrueFalseTotal
for(mg = SvMAGIC(sv); mg; mg = mg->mg_moremagic){ 81 0 81
56 81 ▶ if(mg->mg_virtual == vtbl){
Branch: 1 branch
BranchTrueFalseTotal
if(mg->mg_virtual == vtbl){ 81 0 81
57 assert(mg->mg_type == PERL_MAGIC_ext);
58 81 return mg;
59 }
60 }
61  
62 0 croak("File::MMagic::XS: Invalid File::MMagic::XS object was passed");
63 return NULL; /* not reached */
64 }
65  
66  
67 static MGVTBL PerlFMM_vtbl = { /* for identity */
68 NULL, /* get */
69 NULL, /* set */
70 NULL, /* len */
71 NULL, /* clear */
72 PerlFMM_mg_free, /* free */
73 NULL, /* copy */
74 PerlFMM_mg_dup, /* dup */
75 NULL, /* local */
76 };
77  
78 #define PerlFMM__create PerlFMM_create
79  
80 MODULE = File::MMagic::XS PACKAGE = File::MMagic::XS PREFIX = PerlFMM_
81  
82 PROTOTYPES: ENABLE
83  
84 PerlFMM *
85 PerlFMM__create(class_sv)
86 SV *class_sv;
87  
88 PerlFMM *
89 PerlFMM_clone(self)
90 PerlFMM *self;
91 PREINIT:
92 1 SV *class_sv = ST(0);
93  
94 SV *
95 PerlFMM_parse_magic_file(self, file)
96 PerlFMM *self;
97 char *file;
98  
99 SV *
100 PerlFMM_fhmagic(self, svio)
101 PerlFMM *self;
102 SV *svio;
103  
104 SV *
105 PerlFMM_fsmagic(self, filename)
106 PerlFMM *self;
107 char *filename;
108  
109 SV *
110 PerlFMM_bufmagic(self, buf)
111 PerlFMM *self;
112 SV *buf;
113  
114 SV *
115 PerlFMM_ascmagic(self, data)
116 PerlFMM *self;
117 char *data;
118  
119 SV *
120 PerlFMM_get_mime(self, filename)
121 PerlFMM *self;
122 char *filename;
123  
124 SV *
125 PerlFMM_add_magic(self, magic)
126 PerlFMM *self;
127 char *magic;
128  
129 SV *
130 PerlFMM_add_file_ext(self, ext, mime)
131 PerlFMM *self;
132 char *ext;
133 char *mime;
134  
135 SV *
136 error(self)
137 PerlFMM *self;
138 CODE:
139 2 ▶ if (! FMM_OK(self))
Branch: 1 branch
BranchTrueFalseTotal
if (! FMM_OK(self)) 0 2 2
140 0 croak("Object not initialized.");
141  
142 2 ▶ if (self->error == NULL) {
Branch: 1 branch
BranchTrueFalseTotal
if (self->error == NULL) { 1 1 2
143 1 RETVAL = newSV(0);
144 } else {
145 1 RETVAL = newSVsv(self->error);
146 }
147 OUTPUT:
148 RETVAL
149  
150  
« src/perl-mmagic-xs.c ↑ Summary