RandomAccess.xs

filter: Statementstmt 81.2% 26 / 32 Branchbran 65.0% 13 / 20 Conditioncond n/a MC/DCmcdc n/a Subroutinesub n/a Podpod n/a totaltotal 75.0% 39 / 52 CC 0 SCAR 0
CC
0
Cov
0%
CRAP 0
« blib/lib/Gzip/RandomAccess.pm ↑ Summary
1 #ifdef __cplusplus
2 extern "C" {
3 #endif
4 #include "EXTERN.h"
5 #include "perl.h"
6 #include "XSUB.h"
7 #ifdef __cplusplus
8 }
9 #endif
10  
11 #define Z_ERRSTR(n) ((n) == Z_MEM_ERROR ? "out of memory" : "input corrupted")
12  
13 #include "libzran/libzran.h"
14  
15 typedef struct {
16 struct zran *zran;
17 Off_t index_span;
18 bool cleanup;
19 } *Gzip__RandomAccess;
20  
21 MODULE = Gzip::RandomAccess PACKAGE = Gzip::RandomAccess
22  
23 PROTOTYPES: DISABLE
24  
25 Gzip::RandomAccess
26 _new(file, index_file, index_span, cleanup)
27 SV * file
28 SV * index_file
29 Off_t index_span
30 bool cleanup
31 INIT:
32 Gzip__RandomAccess self;
33 struct zran *zran;
34 char *index_str;
35 CODE:
36 7 ▶ if (!SvOK(file)) {
Branch: 1 branch
BranchTrueFalseTotal
if (!SvOK(file)) { 0 7 7
37 0 croak("undefined file");
38 XSRETURN_UNDEF;
39 }
40 7 ▶ index_str = SvOK(index_file) ? SvPVX(index_file) : NULL;
Branch: 1 branch
BranchTrueFalseTotal
index_str = SvOK(index_file) ? SvPVX(index_file) : NULL; 6 1 7
41 7 zran = zran_init(SvPVX(file), index_str);
42 7 ▶ if (!zran) {
Branch: 1 branch
BranchTrueFalseTotal
if (!zran) { 0 7 7
43 0 croak("could not open %s for reading", SvPVX(file));
44 XSRETURN_UNDEF;
45 }
46 7 self = malloc(sizeof(*self));
47 7 ▶ if (self == NULL) {
Branch: 1 branch
BranchTrueFalseTotal
if (self == NULL) { 0 7 7
48 0 free(zran);
49 0 croak("out of memory");
50 XSRETURN_UNDEF;
51 }
52 7 self->zran = zran;
53 7 self->index_span = index_span;
54 7 self->cleanup = cleanup;
55 7 RETVAL = self;
56 OUTPUT:
57 RETVAL
58  
59 char *
60 file(self)
61 Gzip::RandomAccess self
62 CODE:
63 4 RETVAL = self->zran->data.filename;
64 OUTPUT:
65 RETVAL
66  
67 char *
68 index_file(self)
69 Gzip::RandomAccess self
70 CODE:
71 11 RETVAL = self->zran->index.filename;
72 OUTPUT:
73 RETVAL
74  
75 Off_t
76 index_span(self)
77 Gzip::RandomAccess self
78 CODE:
79 0 ▶ RETVAL = self->index_span;
Branch: 1 branch
BranchTrueFalseTotal
RETVAL = self->index_span; 0 0 0
80 OUTPUT:
81 RETVAL
82  
83 bool
84 cleanup(self)
85 Gzip::RandomAccess self
86 CODE:
87 11 ▶ RETVAL = self->cleanup;
Branch: 1 branch
BranchTrueFalseTotal
RETVAL = self->cleanup; 4 7 11
88 OUTPUT:
89 RETVAL
90  
91 bool
92 index_available(self)
93 Gzip::RandomAccess self
94 CODE:
95 11 ▶ RETVAL = zran_index_available(self->zran);
Branch: 1 branch
BranchTrueFalseTotal
RETVAL = zran_index_available(self->zran); 6 5 11
96 OUTPUT:
97 RETVAL
98  
99 void
100 build_index(self)
101 Gzip::RandomAccess self
102 PPCODE:
103 5 zran_build_index(self->zran, self->index_span, NULL);
104  
105 SV *
106 extract(self, offset, length)
107 Gzip::RandomAccess self
108 Off_t offset
109 int length
110 CODE:
111 13 char *buffer = (char *)malloc(length);
112 13 int extracted = zran_extract(self->zran, offset, buffer, length);
113 13 ▶ if (extracted < 0) {
Branch: 1 branch
BranchTrueFalseTotal
if (extracted < 0) { 1 12 13
114 1 int err = extracted;
115 1 ▶ croak("extract: failed (%s)", Z_ERRSTR(err));
Branch: 1 branch
BranchTrueFalseTotal
croak("extract: failed (%s)", Z_ERRSTR(err)); 0 1 1
116 }
117 else {
118 12 RETVAL = newSVpvn(buffer, extracted);
119 12 free(buffer);
120 }
121 OUTPUT:
122 RETVAL
123  
124 Off_t
125 uncompressed_size(self)
126 Gzip::RandomAccess self
127 CODE:
128 1 RETVAL = zran_uncompressed_size(self->zran);
129 1 ▶ if (RETVAL == -1) {
Branch: 1 branch
BranchTrueFalseTotal
if (RETVAL == -1) { 0 1 1
130 0 croak("uncompressed_size: unable to read index file");
131 XSRETURN_UNDEF;
132 }
133  
134 OUTPUT:
135 RETVAL
136  
137 void
138 _free(self)
139 Gzip::RandomAccess self
140 PPCODE:
141 7 zran_cleanup(self->zran);
142 7 free(self);
143  
« blib/lib/Gzip/RandomAccess.pm ↑ Summary