| 1 |
|
| /* Filename: Bzip2.xs |
| 2 |
|
| * Author : Paul Marquess, <pmqs@outlook.com> |
| 3 |
|
| * Created : 5th October 2005 |
| 4 |
|
| * Version : 2.000 |
| 5 |
|
| * |
| 6 |
|
| * Copyright (c) 2005-2010 Paul Marquess. All rights reserved. |
| 7 |
|
| * This program is free software; you can redistribute it and/or |
| 8 |
|
| * modify it under the same terms as Perl itself. |
| 9 |
|
| * |
| 10 |
|
| */ |
| 11 |
|
| |
| 12 |
|
| #define PERL_NO_GET_CONTEXT |
| 13 |
|
| #include "EXTERN.h" |
| 14 |
|
| #include "perl.h" |
| 15 |
|
| #include "XSUB.h" |
| 16 |
|
| |
| 17 |
|
| #include "bzlib.h" |
| 18 |
|
| |
| 19 |
|
| #ifdef USE_PPPORT_H |
| 20 |
|
| # define NEED_sv_2pv_nolen |
| 21 |
|
| # include "ppport.h" |
| 22 |
|
| #endif |
| 23 |
|
| |
| 24 |
|
| #if PERL_REVISION == 5 && (PERL_VERSION < 8 || (PERL_VERSION == 8 && PERL_SUBVERSION < 4 )) |
| 25 |
|
| |
| 26 |
|
| # ifdef SvPVbyte_force |
| 27 |
|
| # undef SvPVbyte_force |
| 28 |
|
| # endif |
| 29 |
|
| |
| 30 |
|
| # define SvPVbyte_force(sv,lp) SvPV_force(sv,lp) |
| 31 |
|
| |
| 32 |
|
| #endif |
| 33 |
|
| |
| 34 |
|
| #ifndef SvPVbyte_nolen |
| 35 |
|
| # define SvPVbyte_nolen SvPV_nolen |
| 36 |
|
| #endif |
| 37 |
|
| |
| 38 |
|
| |
| 39 |
|
| #if PERL_REVISION == 5 && (PERL_VERSION >= 8 || (PERL_VERSION == 8 && PERL_SUBVERSION < 4 )) |
| 40 |
|
| # define UTF8_AVAILABLE |
| 41 |
|
| #endif |
| 42 |
|
| |
| 43 |
|
| typedef int DualType ; |
| 44 |
|
| typedef int int_undef ; |
| 45 |
|
| |
| 46 |
|
| typedef unsigned long uLong; |
| 47 |
|
| typedef unsigned int uInt; |
| 48 |
|
| |
| 49 |
|
| typedef struct di_stream { |
| 50 |
|
| int flags ; |
| 51 |
|
| #define FLAG_APPEND_OUTPUT 1 |
| 52 |
|
| #define FLAG_CONSUME_INPUT 8 |
| 53 |
|
| #define FLAG_LIMIT_OUTPUT 16 |
| 54 |
|
| bz_stream stream; |
| 55 |
|
| uInt bufsize; |
| 56 |
|
| int last_error ; |
| 57 |
|
| uLong bytesInflated ; |
| 58 |
|
| uLong compressedBytes ; |
| 59 |
|
| uLong uncompressedBytes ; |
| 60 |
|
| |
| 61 |
|
| } di_stream; |
| 62 |
|
| |
| 63 |
|
| typedef di_stream * deflateStream ; |
| 64 |
|
| typedef di_stream * Compress__Raw__Bzip2 ; |
| 65 |
|
| |
| 66 |
|
| typedef di_stream * inflateStream ; |
| 67 |
|
| typedef di_stream * Compress__Raw__Bunzip2 ; |
| 68 |
|
| |
| 69 |
|
| #define COMPRESS_CLASS "Compress::Raw::Bzip2" |
| 70 |
|
| #define UNCOMPRESS_CLASS "Compress::Raw::Bunzip2" |
| 71 |
|
| |
| 72 |
|
| #define ZMALLOC(to, typ) ((to = (typ *)safemalloc(sizeof(typ))), \ |
| 73 |
|
| Zero(to,1,typ)) |
| 74 |
|
| |
| 75 |
|
| |
| 76 |
|
| /* static const char * const my_z_errmsg[] = { */ |
| 77 |
|
| static const char my_z_errmsg[][32] = { |
| 78 |
|
| "End of Stream", /* BZ_STREAM_END 4 */ |
| 79 |
|
| "Finish OK", /* BZ_FINISH_OK 3 */ |
| 80 |
|
| "Flush OK", /* BZ_FLUSH_OK 2 */ |
| 81 |
|
| "Run OK", /* BZ_RUN_OK 1 */ |
| 82 |
|
| "", /* BZ_OK 0 */ |
| 83 |
|
| "Sequence Error", /* BZ_SEQUENCE_ERROR (-1) */ |
| 84 |
|
| "Param Error", /* BZ_PARAM_ERROR (-2) */ |
| 85 |
|
| "Memory Error", /* BZ_MEM_ERROR (-3) */ |
| 86 |
|
| "Data Error", /* BZ_DATA_ERROR (-4) */ |
| 87 |
|
| "Magic Error", /* BZ_DATA_ERROR_MAGIC (-5) */ |
| 88 |
|
| "IO Error", /* BZ_IO_ERROR (-6) */ |
| 89 |
|
| "Unexpected EOF", /* BZ_UNEXPECTED_EOF (-7) */ |
| 90 |
|
| "Output Buffer Full", /* BZ_OUTBUFF_FULL (-8) */ |
| 91 |
|
| "Config Error", /* BZ_CONFIG_ERROR (-9) */ |
| 92 |
|
| ""}; |
| 93 |
|
| |
| 94 |
|
| #define setDUALstatus(var, err) \ |
| 95 |
|
| sv_setnv(var, (double)err) ; \ |
| 96 |
|
| sv_setpv(var, ((err) ? GetErrorString(err) : "")) ; \ |
| 97 |
|
| SvNOK_on(var); |
| 98 |
|
| |
| 99 |
|
| |
| 100 |
|
| #if defined(__SYMBIAN32__) |
| 101 |
|
| # define NO_WRITEABLE_DATA |
| 102 |
|
| #endif |
| 103 |
|
| |
| 104 |
|
| /* Set TRACE_DEFAULT to a non-zero value to enable tracing */ |
| 105 |
|
| #define TRACE_DEFAULT 0 |
| 106 |
|
| |
| 107 |
|
| #if defined(NO_WRITEABLE_DATA) || TRACE_DEFAULT == 0 |
| 108 |
|
| # define trace TRACE_DEFAULT |
| 109 |
|
| #else |
| 110 |
|
| static int trace = TRACE_DEFAULT ; |
| 111 |
|
| #endif |
| 112 |
|
| |
| 113 |
|
| /* Dodge PerlIO hiding of these functions. */ |
| 114 |
|
| #undef printf |
| 115 |
|
| |
| 116 |
|
| #if 1 |
| 117 |
|
| #define getInnerObject(x) (*av_fetch((AV*)SvRV(x), 0, FALSE)) |
| 118 |
|
| #else |
| 119 |
|
| #define getInnerObject(x) ((SV*)SvRV(sv)) |
| 120 |
|
| #endif |
| 121 |
|
| |
| 122 |
|
| #ifdef BZ_NO_STDIO |
| 123 |
0 |
| void bz_internal_error(int errorcode) |
| 124 |
|
| { |
| 125 |
0 |
| croak("bz_internal_error %d\n", errorcode); |
| 126 |
|
| } |
| 127 |
|
| #endif |
| 128 |
|
| |
| 129 |
|
| static char * |
| 130 |
|
| #ifdef CAN_PROTOTYPE |
| 131 |
257 |
| GetErrorString(int error_no) |
| 132 |
|
| #else |
| 133 |
|
| GetErrorString(error_no) |
| 134 |
|
| int error_no ; |
| 135 |
|
| #endif |
| 136 |
|
| { |
| 137 |
257 |
| return(char*) my_z_errmsg[4 - error_no]; |
| 138 |
|
| } |
| 139 |
|
| |
| 140 |
|
| static void |
| 141 |
|
| #ifdef CAN_PROTOTYPE |
| 142 |
0 |
| DispHex(void * ptr, int length) |
| 143 |
|
| #else |
| 144 |
|
| DispHex(ptr, length) |
| 145 |
|
| void * ptr; |
| 146 |
|
| int length; |
| 147 |
|
| #endif |
| 148 |
|
| { |
| 149 |
0 |
| char * p = (char*)ptr; |
| 150 |
|
| int i; |
| 151 |
0 |
▶ | for (i = 0; i < length; ++i) { |
Branch: 1 branch
| Branch | True | False | Total |
| for (i = 0; i < length; ++i) { |
0 |
0 |
0 |
|
| 152 |
0 |
| printf(" %02x", 0xFF & *(p+i)); |
| 153 |
|
| } |
| 154 |
0 |
| } |
| 155 |
|
| |
| 156 |
|
| |
| 157 |
|
| static void |
| 158 |
|
| #ifdef CAN_PROTOTYPE |
| 159 |
0 |
| DispStream(di_stream * s, const char * message) |
| 160 |
|
| #else |
| 161 |
|
| DispStream(s, message) |
| 162 |
|
| di_stream * s; |
| 163 |
|
| const char * message; |
| 164 |
|
| #endif |
| 165 |
|
| { |
| 166 |
|
| |
| 167 |
|
| #if 0 |
| 168 |
|
| if (! trace) |
| 169 |
|
| return ; |
| 170 |
|
| #endif |
| 171 |
|
| |
| 172 |
|
| #define EnDis(f) (s->flags & f ? "Enabled" : "Disabled") |
| 173 |
|
| |
| 174 |
0 |
| printf("DispStream 0x%p", s) ; |
| 175 |
0 |
▶ | if (message) |
Branch: 1 branch
| Branch | True | False | Total |
| if (message) |
0 |
0 |
0 |
|
| 176 |
0 |
| printf(" - %s \n", message) ; |
| 177 |
0 |
| printf("\n") ; |
| 178 |
|
| |
| 179 |
0 |
▶ | if (!s) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (!s) { |
0 |
0 |
0 |
|
| 180 |
0 |
| printf(" stream pointer is NULL\n"); |
| 181 |
|
| } |
| 182 |
|
| else { |
| 183 |
0 |
| printf(" stream 0x%p\n", &(s->stream)); |
| 184 |
0 |
| printf(" opaque 0x%p\n", s->stream.opaque); |
| 185 |
0 |
| printf(" state 0x%p\n", s->stream.state ); |
| 186 |
0 |
| printf(" next_in 0x%p", s->stream.next_in); |
| 187 |
0 |
▶ | if (s->stream.next_in){ |
Branch: 1 branch
| Branch | True | False | Total |
| if (s->stream.next_in){ |
0 |
0 |
0 |
|
| 188 |
0 |
| printf(" =>"); |
| 189 |
0 |
| DispHex(s->stream.next_in, 4); |
| 190 |
|
| } |
| 191 |
0 |
| printf("\n"); |
| 192 |
|
| |
| 193 |
0 |
| printf(" next_out 0x%p", s->stream.next_out); |
| 194 |
0 |
▶ | if (s->stream.next_out){ |
Branch: 1 branch
| Branch | True | False | Total |
| if (s->stream.next_out){ |
0 |
0 |
0 |
|
| 195 |
0 |
| printf(" =>"); |
| 196 |
0 |
| DispHex(s->stream.next_out, 4); |
| 197 |
|
| } |
| 198 |
0 |
| printf("\n"); |
| 199 |
|
| |
| 200 |
0 |
| printf(" avail_in %lu\n", (unsigned long)s->stream.avail_in); |
| 201 |
0 |
| printf(" avail_out %lu\n", (unsigned long)s->stream.avail_out); |
| 202 |
0 |
| printf(" bufsize %lu\n", (unsigned long)s->bufsize); |
| 203 |
0 |
| printf(" total_in_lo32 %u\n", s->stream.total_in_lo32); |
| 204 |
0 |
| printf(" total_in_hi32 %u\n", s->stream.total_in_hi32); |
| 205 |
0 |
| printf(" total_out_lo32 %u\n", s->stream.total_out_lo32); |
| 206 |
0 |
| printf(" total_out_hi32 %u\n", s->stream.total_out_hi32); |
| 207 |
0 |
| printf(" flags 0x%x\n", s->flags); |
| 208 |
0 |
▶ | printf(" APPEND %s\n", EnDis(FLAG_APPEND_OUTPUT)); |
Branch: 1 branch
| Branch | True | False | Total |
| printf(" APPEND %s\n", EnDis(FLAG_APPEND_OUTPUT)); |
0 |
0 |
0 |
|
| 209 |
0 |
▶ | printf(" CONSUME %s\n", EnDis(FLAG_CONSUME_INPUT)); |
Branch: 1 branch
| Branch | True | False | Total |
| printf(" CONSUME %s\n", EnDis(FLAG_CONSUME_INPUT)); |
0 |
0 |
0 |
|
| 210 |
0 |
▶ | printf(" LIMIT %s\n", EnDis(FLAG_LIMIT_OUTPUT)); |
Branch: 1 branch
| Branch | True | False | Total |
| printf(" LIMIT %s\n", EnDis(FLAG_LIMIT_OUTPUT)); |
0 |
0 |
0 |
|
| 211 |
|
| |
| 212 |
0 |
| printf("\n"); |
| 213 |
|
| |
| 214 |
|
| } |
| 215 |
0 |
| } |
| 216 |
|
| |
| 217 |
|
| static di_stream * |
| 218 |
|
| #ifdef CAN_PROTOTYPE |
| 219 |
51 |
| InitStream(void) |
| 220 |
|
| #else |
| 221 |
|
| InitStream() |
| 222 |
|
| #endif |
| 223 |
|
| { |
| 224 |
|
| di_stream *s ; |
| 225 |
|
| |
| 226 |
51 |
| ZMALLOC(s, di_stream) ; |
| 227 |
|
| |
| 228 |
51 |
| return s ; |
| 229 |
|
| |
| 230 |
|
| } |
| 231 |
|
| |
| 232 |
|
| static void |
| 233 |
|
| #ifdef CAN_PROTOTYPE |
| 234 |
51 |
| PostInitStream(di_stream * s, int flags) |
| 235 |
|
| #else |
| 236 |
|
| PostInitStream(s, flags) |
| 237 |
|
| di_stream *s ; |
| 238 |
|
| int flags ; |
| 239 |
|
| #endif |
| 240 |
|
| { |
| 241 |
51 |
| s->bufsize = 1024 * 16 ; |
| 242 |
51 |
| s->last_error = 0 ; |
| 243 |
51 |
| s->flags = flags ; |
| 244 |
51 |
| } |
| 245 |
|
| |
| 246 |
|
| |
| 247 |
|
| static SV* |
| 248 |
|
| #ifdef CAN_PROTOTYPE |
| 249 |
51325 |
| deRef(SV * sv, const char * string) |
| 250 |
|
| #else |
| 251 |
|
| deRef(sv, string) |
| 252 |
|
| SV * sv ; |
| 253 |
|
| char * string; |
| 254 |
|
| #endif |
| 255 |
|
| { |
| 256 |
|
| dTHX; |
| 257 |
51325 |
▶ | SvGETMAGIC(sv); |
Branch: 2 branches
| Branch | True | False | Total |
| SvGETMAGIC(sv); |
6 |
51319 |
51325 |
| SvGETMAGIC(sv); |
0 |
6 |
6 |
|
| 258 |
|
| |
| 259 |
51325 |
▶ | if (SvROK(sv)) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (SvROK(sv)) { |
0 |
51325 |
51325 |
|
| 260 |
0 |
| sv = SvRV(sv) ; |
| 261 |
0 |
▶ | SvGETMAGIC(sv); |
Branch: 2 branches
| Branch | True | False | Total |
| SvGETMAGIC(sv); |
0 |
0 |
0 |
| SvGETMAGIC(sv); |
0 |
0 |
0 |
|
| 262 |
0 |
▶ | switch(SvTYPE(sv)) { |
Branch: 1 branch
| Branch | True | False | Total |
| switch(SvTYPE(sv)) { |
0 |
0 |
0 |
|
| 263 |
0 |
| case SVt_PVAV: |
| 264 |
|
| case SVt_PVHV: |
| 265 |
|
| case SVt_PVCV: |
| 266 |
0 |
| croak("%s: buffer parameter is not a SCALAR reference", string); |
| 267 |
0 |
| default: |
| 268 |
0 |
| break; |
| 269 |
|
| } |
| 270 |
0 |
▶ | if (SvROK(sv)) |
Branch: 1 branch
| Branch | True | False | Total |
| if (SvROK(sv)) |
0 |
0 |
0 |
|
| 271 |
0 |
| croak("%s: buffer parameter is a reference to a reference", string) ; |
| 272 |
|
| } |
| 273 |
|
| |
| 274 |
51325 |
▶ | if (!SvOK(sv)) |
Branch: 1 branch
| Branch | True | False | Total |
| if (!SvOK(sv)) |
0 |
51325 |
51325 |
|
| 275 |
0 |
| sv = sv_2mortal(newSVpv("", 0)); |
| 276 |
|
| |
| 277 |
51325 |
| return sv ; |
| 278 |
|
| } |
| 279 |
|
| |
| 280 |
|
| static SV* |
| 281 |
|
| #ifdef CAN_PROTOTYPE |
| 282 |
51347 |
| deRef_l(SV * sv, const char * string) |
| 283 |
|
| #else |
| 284 |
|
| deRef_l(sv, string) |
| 285 |
|
| SV * sv ; |
| 286 |
|
| char * string ; |
| 287 |
|
| #endif |
| 288 |
|
| { |
| 289 |
|
| dTHX; |
| 290 |
51347 |
| bool wipe = 0 ; |
| 291 |
|
| STRLEN na; |
| 292 |
|
| |
| 293 |
51347 |
▶ | SvGETMAGIC(sv); |
Branch: 2 branches
| Branch | True | False | Total |
| SvGETMAGIC(sv); |
356 |
50991 |
51347 |
| SvGETMAGIC(sv); |
0 |
356 |
356 |
|
| 294 |
51347 |
| wipe = ! SvOK(sv) ; |
| 295 |
|
| |
| 296 |
51347 |
▶ | if (SvROK(sv)) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (SvROK(sv)) { |
18 |
51329 |
51347 |
|
| 297 |
18 |
| sv = SvRV(sv) ; |
| 298 |
18 |
▶ | SvGETMAGIC(sv); |
Branch: 2 branches
| Branch | True | False | Total |
| SvGETMAGIC(sv); |
0 |
18 |
18 |
| SvGETMAGIC(sv); |
0 |
0 |
0 |
|
| 299 |
18 |
| wipe = ! SvOK(sv) ; |
| 300 |
|
| |
| 301 |
18 |
▶ | switch(SvTYPE(sv)) { |
Branch: 1 branch
| Branch | True | False | Total |
| switch(SvTYPE(sv)) { |
0 |
18 |
18 |
|
| 302 |
0 |
| case SVt_PVAV: |
| 303 |
|
| case SVt_PVHV: |
| 304 |
|
| case SVt_PVCV: |
| 305 |
0 |
| croak("%s: buffer parameter is not a SCALAR reference", string); |
| 306 |
18 |
| default: |
| 307 |
18 |
| break; |
| 308 |
|
| } |
| 309 |
18 |
▶ | if (SvROK(sv)) |
Branch: 1 branch
| Branch | True | False | Total |
| if (SvROK(sv)) |
0 |
18 |
18 |
|
| 310 |
0 |
| croak("%s: buffer parameter is a reference to a reference", string) ; |
| 311 |
|
| } |
| 312 |
|
| |
| 313 |
51347 |
▶ | if (SvREADONLY(sv) && PL_curcop != &PL_compiling) |
Branch: 2 branches
| Branch | True | False | Total |
| if (SvREADONLY(sv) && PL_curcop != &PL_compiling) |
0 |
51347 |
51347 |
| if (SvREADONLY(sv) && PL_curcop != &PL_compiling) |
0 |
0 |
0 |
|
| 314 |
0 |
| croak("%s: buffer parameter is read-only", string); |
| 315 |
|
| |
| 316 |
51347 |
▶ | SvUPGRADE(sv, SVt_PV); |
Branch: 1 branch
| Branch | True | False | Total |
| SvUPGRADE(sv, SVt_PV); |
24 |
51323 |
51347 |
|
| 317 |
|
| |
| 318 |
51347 |
▶ | if (wipe) |
Branch: 1 branch
| Branch | True | False | Total |
| if (wipe) |
30 |
51317 |
51347 |
|
| 319 |
30 |
| sv_setpv(sv, "") ; |
| 320 |
|
| else |
| 321 |
|
| (void)SvPVbyte_force(sv, na) ; |
| 322 |
|
| |
| 323 |
51347 |
| return sv ; |
| 324 |
|
| } |
| 325 |
|
| |
| 326 |
|
| |
| 327 |
|
| #include "constants.h" |
| 328 |
|
| |
| 329 |
|
| MODULE = Compress::Raw::Bzip2 PACKAGE = Compress::Raw::Bzip2 PREFIX = Zip_ |
| 330 |
|
| |
| 331 |
|
| REQUIRE: 1.924 |
| 332 |
|
| PROTOTYPES: DISABLE |
| 333 |
|
| |
| 334 |
|
| INCLUDE: constants.xs |
| 335 |
|
| |
| 336 |
|
| BOOT: |
| 337 |
|
| /* Check this version of bzip2 is == 1 */ |
| 338 |
3 |
▶ | if (BZ2_bzlibVersion()[0] != '1') |
Branch: 1 branch
| Branch | True | False | Total |
| if (BZ2_bzlibVersion()[0] != '1') |
0 |
3 |
3 |
|
| 339 |
0 |
| croak(COMPRESS_CLASS " needs bzip2 version 1.x, you have %s\n", BZ2_bzlibVersion()) ; |
| 340 |
|
| |
| 341 |
|
| |
| 342 |
|
| MODULE = Compress::Raw::Bzip2 PACKAGE = Compress::Raw::Bzip2 |
| 343 |
|
| |
| 344 |
|
| #define bzlibversion() BZ2_bzlibVersion() |
| 345 |
|
| const char * |
| 346 |
|
| bzlibversion() |
| 347 |
|
| |
| 348 |
|
| void |
| 349 |
|
| new(className, appendOut=1, blockSize100k=1, workfactor=0, verbosity=0) |
| 350 |
|
| const char * className |
| 351 |
|
| int appendOut |
| 352 |
|
| int blockSize100k |
| 353 |
|
| int workfactor |
| 354 |
|
| int verbosity |
| 355 |
|
| PPCODE: |
| 356 |
|
| { |
| 357 |
|
| int err ; |
| 358 |
|
| deflateStream s ; |
| 359 |
|
| #if 0 |
| 360 |
|
| /* if (trace) */ |
| 361 |
|
| warn("in Compress::Raw::Bzip2::_new(items=%d,appendOut=%d, blockSize100k=%d, workfactor=%d, verbosity=%d\n", |
| 362 |
|
| items, appendOut, blockSize100k, workfactor, verbosity); |
| 363 |
|
| #endif |
| 364 |
21 |
▶ | if ((s = InitStream() )) { |
Branch: 1 branch
| Branch | True | False | Total |
| if ((s = InitStream() )) { |
21 |
0 |
21 |
|
| 365 |
|
| |
| 366 |
21 |
| err = BZ2_bzCompressInit ( &(s->stream), |
| 367 |
|
| blockSize100k, |
| 368 |
|
| verbosity, |
| 369 |
|
| workfactor ); |
| 370 |
|
| |
| 371 |
21 |
▶ | if (err != BZ_OK) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (err != BZ_OK) { |
0 |
21 |
21 |
|
| 372 |
0 |
| Safefree(s) ; |
| 373 |
0 |
| s = NULL ; |
| 374 |
|
| } |
| 375 |
|
| else { |
| 376 |
21 |
| PostInitStream(s, appendOut ? FLAG_APPEND_OUTPUT :0) ; |
| 377 |
|
| } |
| 378 |
|
| } |
| 379 |
|
| else |
| 380 |
0 |
| err = BZ_MEM_ERROR ; |
| 381 |
|
| |
| 382 |
|
| { |
| 383 |
21 |
| SV* obj = sv_setref_pv(sv_newmortal(), className, (void*)s); |
| 384 |
21 |
▶ | XPUSHs(obj); |
Branch: 1 branch
| Branch | True | False | Total |
| XPUSHs(obj); |
0 |
21 |
21 |
|
| 385 |
|
| } |
| 386 |
|
| if(0) |
| 387 |
|
| { |
| 388 |
|
| SV* obj = sv_2mortal(newSViv(PTR2IV(s))) ; |
| 389 |
|
| XPUSHs(obj); |
| 390 |
|
| } |
| 391 |
21 |
▶ | if (GIMME_V == G_ARRAY) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (GIMME_V == G_ARRAY) { |
13 |
8 |
21 |
|
| 392 |
13 |
| SV * sv = sv_2mortal(newSViv(err)) ; |
| 393 |
13 |
▶ | setDUALstatus(sv, err); |
Branch: 1 branch
| Branch | True | False | Total |
| setDUALstatus(sv, err); |
0 |
13 |
13 |
|
| 394 |
13 |
▶ | XPUSHs(sv) ; |
Branch: 1 branch
| Branch | True | False | Total |
| XPUSHs(sv) ; |
0 |
13 |
13 |
|
| 395 |
|
| } |
| 396 |
|
| } |
| 397 |
|
| |
| 398 |
|
| MODULE = Compress::Raw::Bunzip2 PACKAGE = Compress::Raw::Bunzip2 |
| 399 |
|
| |
| 400 |
|
| void |
| 401 |
|
| new(className, appendOut=1 , consume=1, small=0, verbosity=0, limitOutput=0) |
| 402 |
|
| const char* className |
| 403 |
|
| int appendOut |
| 404 |
|
| int consume |
| 405 |
|
| int small |
| 406 |
|
| int verbosity |
| 407 |
|
| int limitOutput |
| 408 |
|
| PPCODE: |
| 409 |
|
| { |
| 410 |
30 |
| int err = BZ_OK ; |
| 411 |
|
| inflateStream s ; |
| 412 |
|
| #if 0 |
| 413 |
|
| if (trace) |
| 414 |
|
| warn("in _inflateInit(windowBits=%d, bufsize=%lu, dictionary=%lu\n", |
| 415 |
|
| windowBits, bufsize, (unsigned long)SvCUR(dictionary)) ; |
| 416 |
|
| #endif |
| 417 |
30 |
▶ | if ((s = InitStream() )) { |
Branch: 1 branch
| Branch | True | False | Total |
| if ((s = InitStream() )) { |
30 |
0 |
30 |
|
| 418 |
|
| |
| 419 |
30 |
| err = BZ2_bzDecompressInit (&(s->stream), verbosity, small); |
| 420 |
30 |
▶ | if (err != BZ_OK) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (err != BZ_OK) { |
0 |
30 |
30 |
|
| 421 |
0 |
| Safefree(s) ; |
| 422 |
0 |
| s = NULL ; |
| 423 |
|
| } |
| 424 |
30 |
▶ | if (s) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (s) { |
30 |
0 |
30 |
|
| 425 |
30 |
| int flags = 0; |
| 426 |
30 |
▶ | if (appendOut) |
Branch: 1 branch
| Branch | True | False | Total |
| if (appendOut) |
23 |
7 |
30 |
|
| 427 |
23 |
| flags |= FLAG_APPEND_OUTPUT; |
| 428 |
30 |
▶ | if (consume) |
Branch: 1 branch
| Branch | True | False | Total |
| if (consume) |
16 |
14 |
30 |
|
| 429 |
16 |
| flags |= FLAG_CONSUME_INPUT; |
| 430 |
30 |
▶ | if (limitOutput) |
Branch: 1 branch
| Branch | True | False | Total |
| if (limitOutput) |
7 |
23 |
30 |
|
| 431 |
7 |
| flags |= (FLAG_LIMIT_OUTPUT|FLAG_CONSUME_INPUT); |
| 432 |
30 |
| PostInitStream(s, flags) ; |
| 433 |
|
| } |
| 434 |
|
| } |
| 435 |
|
| else |
| 436 |
0 |
| err = BZ_MEM_ERROR ; |
| 437 |
|
| |
| 438 |
|
| { |
| 439 |
30 |
| SV* obj = sv_setref_pv(sv_newmortal(), className, (void*)s); |
| 440 |
30 |
▶ | XPUSHs(obj); |
Branch: 1 branch
| Branch | True | False | Total |
| XPUSHs(obj); |
0 |
30 |
30 |
|
| 441 |
|
| } |
| 442 |
|
| if (0) |
| 443 |
|
| { |
| 444 |
|
| SV* obj = sv_2mortal(newSViv(PTR2IV(s))) ; |
| 445 |
|
| XPUSHs(obj); |
| 446 |
|
| } |
| 447 |
30 |
▶ | if (GIMME_V == G_ARRAY) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (GIMME_V == G_ARRAY) { |
19 |
11 |
30 |
|
| 448 |
19 |
| SV * sv = sv_2mortal(newSViv(err)) ; |
| 449 |
19 |
▶ | setDUALstatus(sv, err); |
Branch: 1 branch
| Branch | True | False | Total |
| setDUALstatus(sv, err); |
0 |
19 |
19 |
|
| 450 |
19 |
▶ | XPUSHs(sv) ; |
Branch: 1 branch
| Branch | True | False | Total |
| XPUSHs(sv) ; |
0 |
19 |
19 |
|
| 451 |
|
| } |
| 452 |
|
| } |
| 453 |
|
| |
| 454 |
|
| |
| 455 |
|
| |
| 456 |
|
| MODULE = Compress::Raw::Bzip2 PACKAGE = Compress::Raw::Bzip2 |
| 457 |
|
| |
| 458 |
|
| void |
| 459 |
|
| DispStream(s, message=NULL) |
| 460 |
|
| Compress::Raw::Bzip2 s |
| 461 |
|
| const char * message |
| 462 |
|
| |
| 463 |
|
| DualType |
| 464 |
|
| bzdeflate (s, buf, output) |
| 465 |
|
| Compress::Raw::Bzip2 s |
| 466 |
|
| SV * buf |
| 467 |
|
| SV * output |
| 468 |
|
| uInt cur_length = NO_INIT |
| 469 |
|
| uInt increment = NO_INIT |
| 470 |
|
| int RETVAL = 0; |
| 471 |
|
| uInt bufinc = NO_INIT |
| 472 |
|
| STRLEN origlen = NO_INIT |
| 473 |
|
| CODE: |
| 474 |
205 |
| bufinc = s->bufsize; |
| 475 |
|
| |
| 476 |
|
| /* If the input buffer is a reference, dereference it */ |
| 477 |
205 |
| buf = deRef(buf, "deflate") ; |
| 478 |
|
| |
| 479 |
|
| /* initialise the input buffer */ |
| 480 |
|
| #ifdef UTF8_AVAILABLE |
| 481 |
205 |
▶ | if (DO_UTF8(buf) && !sv_utf8_downgrade(buf, 1)) |
Branch: 3 branches
| Branch | True | False | Total |
| if (DO_UTF8(buf) && !sv_utf8_downgrade(buf, 1)) |
0 |
205 |
205 |
| if (DO_UTF8(buf) && !sv_utf8_downgrade(buf, 1)) |
0 |
0 |
0 |
| if (DO_UTF8(buf) && !sv_utf8_downgrade(buf, 1)) |
0 |
0 |
0 |
|
| 482 |
0 |
| croak("Wide character in " COMPRESS_CLASS "::bzdeflate input parameter"); |
| 483 |
|
| #endif |
| 484 |
205 |
| s->stream.next_in = (char*)SvPV_nomg(buf, origlen) ; |
| 485 |
205 |
| s->stream.avail_in = (unsigned int) origlen; |
| 486 |
|
| |
| 487 |
|
| /* and retrieve the output buffer */ |
| 488 |
205 |
| output = deRef_l(output, "deflate") ; |
| 489 |
|
| #ifdef UTF8_AVAILABLE |
| 490 |
205 |
▶ | if (DO_UTF8(output) && !sv_utf8_downgrade(output, 1)) |
Branch: 3 branches
| Branch | True | False | Total |
| if (DO_UTF8(output) && !sv_utf8_downgrade(output, 1)) |
0 |
205 |
205 |
| if (DO_UTF8(output) && !sv_utf8_downgrade(output, 1)) |
0 |
0 |
0 |
| if (DO_UTF8(output) && !sv_utf8_downgrade(output, 1)) |
0 |
0 |
0 |
|
| 491 |
0 |
| croak("Wide character in " COMPRESS_CLASS "::bzdeflate output parameter"); |
| 492 |
|
| #endif |
| 493 |
|
| |
| 494 |
205 |
▶ | if((s->flags & FLAG_APPEND_OUTPUT) == FLAG_APPEND_OUTPUT) { |
Branch: 1 branch
| Branch | True | False | Total |
| if((s->flags & FLAG_APPEND_OUTPUT) == FLAG_APPEND_OUTPUT) { |
129 |
76 |
205 |
|
| 495 |
129 |
▶ | SvOOK_off(output); |
Branch: 4 branches
| Branch | True | False | Total |
| SvOOK_off(output); |
96 |
33 |
129 |
| SvOOK_off(output); |
96 |
0 |
96 |
| SvOOK_off(output); |
0 |
96 |
96 |
| SvOOK_off(output); |
1 |
32 |
33 |
|
| 496 |
|
| } else { |
| 497 |
76 |
| SvCUR_set(output, 0); |
| 498 |
|
| } |
| 499 |
205 |
| cur_length = SvCUR(output) ; |
| 500 |
205 |
| s->stream.next_out = (char*) SvPVX(output) + cur_length; |
| 501 |
205 |
| increment = SvLEN(output) - cur_length; |
| 502 |
205 |
| s->stream.avail_out = increment; |
| 503 |
410 |
▶ | while (s->stream.avail_in != 0) { |
Branch: 1 branch
| Branch | True | False | Total |
| while (s->stream.avail_in != 0) { |
205 |
205 |
410 |
|
| 504 |
|
| |
| 505 |
205 |
▶ | if (s->stream.avail_out == 0) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (s->stream.avail_out == 0) { |
0 |
205 |
205 |
|
| 506 |
|
| /* out of space in the output buffer so make it bigger */ |
| 507 |
0 |
| s->stream.next_out = Sv_Grow(output, SvLEN(output) + bufinc) ; |
| 508 |
0 |
| cur_length += increment ; |
| 509 |
0 |
| s->stream.next_out += cur_length ; |
| 510 |
0 |
| increment = bufinc ; |
| 511 |
0 |
| s->stream.avail_out = increment; |
| 512 |
0 |
| bufinc *= 2 ; |
| 513 |
|
| } |
| 514 |
|
| |
| 515 |
205 |
| RETVAL = BZ2_bzCompress(&(s->stream), BZ_RUN); |
| 516 |
205 |
▶ | if (RETVAL != BZ_RUN_OK) |
Branch: 1 branch
| Branch | True | False | Total |
| if (RETVAL != BZ_RUN_OK) |
0 |
205 |
205 |
|
| 517 |
0 |
| break; |
| 518 |
|
| } |
| 519 |
|
| |
| 520 |
205 |
| s->compressedBytes += cur_length + increment - s->stream.avail_out ; |
| 521 |
205 |
| s->uncompressedBytes += origlen - s->stream.avail_in ; |
| 522 |
|
| |
| 523 |
205 |
| s->last_error = RETVAL ; |
| 524 |
205 |
▶ | if (RETVAL == BZ_RUN_OK) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (RETVAL == BZ_RUN_OK) { |
205 |
0 |
205 |
|
| 525 |
205 |
| SvPOK_only(output); |
| 526 |
205 |
| SvCUR_set(output, cur_length + increment - s->stream.avail_out) ; |
| 527 |
205 |
▶ | SvSETMAGIC(output); |
Branch: 1 branch
| Branch | True | False | Total |
| SvSETMAGIC(output); |
96 |
109 |
205 |
|
| 528 |
|
| } |
| 529 |
|
| OUTPUT: |
| 530 |
|
| RETVAL |
| 531 |
|
| |
| 532 |
|
| |
| 533 |
|
| void |
| 534 |
|
| DESTROY(s) |
| 535 |
|
| Compress::Raw::Bzip2 s |
| 536 |
|
| CODE: |
| 537 |
21 |
| BZ2_bzCompressEnd(&s->stream) ; |
| 538 |
21 |
| Safefree(s) ; |
| 539 |
|
| |
| 540 |
|
| |
| 541 |
|
| DualType |
| 542 |
|
| bzclose(s, output) |
| 543 |
|
| Compress::Raw::Bzip2 s |
| 544 |
|
| SV * output |
| 545 |
|
| uInt cur_length = NO_INIT |
| 546 |
|
| uInt increment = NO_INIT |
| 547 |
|
| uInt bufinc = NO_INIT |
| 548 |
|
| CODE: |
| 549 |
21 |
| bufinc = s->bufsize; |
| 550 |
|
| |
| 551 |
21 |
| s->stream.avail_in = 0; /* should be zero already anyway */ |
| 552 |
|
| |
| 553 |
|
| /* retrieve the output buffer */ |
| 554 |
21 |
| output = deRef_l(output, "close") ; |
| 555 |
|
| #ifdef UTF8_AVAILABLE |
| 556 |
21 |
▶ | if (DO_UTF8(output) && !sv_utf8_downgrade(output, 1)) |
Branch: 3 branches
| Branch | True | False | Total |
| if (DO_UTF8(output) && !sv_utf8_downgrade(output, 1)) |
0 |
21 |
21 |
| if (DO_UTF8(output) && !sv_utf8_downgrade(output, 1)) |
0 |
0 |
0 |
| if (DO_UTF8(output) && !sv_utf8_downgrade(output, 1)) |
0 |
0 |
0 |
|
| 557 |
0 |
| croak("Wide character in " COMPRESS_CLASS "::bzclose input parameter"); |
| 558 |
|
| #endif |
| 559 |
21 |
▶ | if((s->flags & FLAG_APPEND_OUTPUT) == FLAG_APPEND_OUTPUT) { |
Branch: 1 branch
| Branch | True | False | Total |
| if((s->flags & FLAG_APPEND_OUTPUT) == FLAG_APPEND_OUTPUT) { |
14 |
7 |
21 |
|
| 560 |
14 |
▶ | SvOOK_off(output); |
Branch: 4 branches
| Branch | True | False | Total |
| SvOOK_off(output); |
4 |
10 |
14 |
| SvOOK_off(output); |
4 |
0 |
4 |
| SvOOK_off(output); |
0 |
4 |
4 |
| SvOOK_off(output); |
1 |
9 |
10 |
|
| 561 |
|
| } else { |
| 562 |
7 |
| SvCUR_set(output, 0); |
| 563 |
|
| } |
| 564 |
21 |
| cur_length = SvCUR(output) ; |
| 565 |
21 |
| s->stream.next_out = (char*) SvPVX(output) + cur_length; |
| 566 |
21 |
| increment = SvLEN(output) - cur_length; |
| 567 |
21 |
| s->stream.avail_out = increment; |
| 568 |
|
| |
| 569 |
|
| for (;;) { |
| 570 |
39 |
▶ | if (s->stream.avail_out == 0) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (s->stream.avail_out == 0) { |
18 |
21 |
39 |
|
| 571 |
|
| /* consumed all the available output, so extend it */ |
| 572 |
18 |
| s->stream.next_out = Sv_Grow(output, SvLEN(output) + bufinc) ; |
| 573 |
18 |
| cur_length += increment ; |
| 574 |
18 |
| s->stream.next_out += cur_length ; |
| 575 |
18 |
| increment = bufinc ; |
| 576 |
18 |
| s->stream.avail_out = increment; |
| 577 |
18 |
| bufinc *= 2 ; |
| 578 |
|
| } |
| 579 |
39 |
| RETVAL = BZ2_bzCompress(&(s->stream), BZ_FINISH); |
| 580 |
|
| |
| 581 |
|
| /* deflate has finished flushing only when it hasn't used up |
| 582 |
|
| * all the available space in the output buffer: |
| 583 |
|
| */ |
| 584 |
|
| /* if (s->stream.avail_out != 0 || RETVAL < 0 ) */ |
| 585 |
39 |
▶ | if (RETVAL == BZ_STREAM_END || RETVAL < 0 ) |
Branch: 2 branches
| Branch | True | False | Total |
| if (RETVAL == BZ_STREAM_END || RETVAL < 0 ) |
18 |
21 |
39 |
| if (RETVAL == BZ_STREAM_END || RETVAL < 0 ) |
18 |
0 |
18 |
|
| 586 |
|
| break; |
| 587 |
|
| } |
| 588 |
|
| |
| 589 |
|
| /* RETVAL = (RETVAL == BZ_STREAM_END ? BZ_OK : RETVAL) ; */ |
| 590 |
21 |
| s->last_error = RETVAL ; |
| 591 |
|
| |
| 592 |
21 |
| s->compressedBytes += cur_length + increment - s->stream.avail_out ; |
| 593 |
|
| |
| 594 |
21 |
▶ | if (RETVAL == BZ_STREAM_END) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (RETVAL == BZ_STREAM_END) { |
21 |
0 |
21 |
|
| 595 |
21 |
| SvPOK_only(output); |
| 596 |
21 |
| SvCUR_set(output, cur_length + increment - s->stream.avail_out) ; |
| 597 |
21 |
▶ | SvSETMAGIC(output); |
Branch: 1 branch
| Branch | True | False | Total |
| SvSETMAGIC(output); |
4 |
17 |
21 |
|
| 598 |
|
| } |
| 599 |
|
| OUTPUT: |
| 600 |
|
| RETVAL |
| 601 |
|
| |
| 602 |
|
| |
| 603 |
|
| DualType |
| 604 |
|
| bzflush(s, output) |
| 605 |
|
| Compress::Raw::Bzip2 s |
| 606 |
|
| SV * output |
| 607 |
|
| uInt cur_length = NO_INIT |
| 608 |
|
| uInt increment = NO_INIT |
| 609 |
|
| uInt bufinc = NO_INIT |
| 610 |
|
| CODE: |
| 611 |
2 |
| bufinc = s->bufsize; |
| 612 |
|
| |
| 613 |
2 |
| s->stream.avail_in = 0; /* should be zero already anyway */ |
| 614 |
|
| |
| 615 |
|
| /* retrieve the output buffer */ |
| 616 |
2 |
| output = deRef_l(output, "close") ; |
| 617 |
|
| #ifdef UTF8_AVAILABLE |
| 618 |
2 |
▶ | if (DO_UTF8(output) && !sv_utf8_downgrade(output, 1)) |
Branch: 3 branches
| Branch | True | False | Total |
| if (DO_UTF8(output) && !sv_utf8_downgrade(output, 1)) |
0 |
2 |
2 |
| if (DO_UTF8(output) && !sv_utf8_downgrade(output, 1)) |
0 |
0 |
0 |
| if (DO_UTF8(output) && !sv_utf8_downgrade(output, 1)) |
0 |
0 |
0 |
|
| 619 |
0 |
| croak("Wide character in " COMPRESS_CLASS "::bzflush input parameter"); |
| 620 |
|
| #endif |
| 621 |
2 |
▶ | if((s->flags & FLAG_APPEND_OUTPUT) == FLAG_APPEND_OUTPUT) { |
Branch: 1 branch
| Branch | True | False | Total |
| if((s->flags & FLAG_APPEND_OUTPUT) == FLAG_APPEND_OUTPUT) { |
0 |
2 |
2 |
|
| 622 |
0 |
▶ | SvOOK_off(output); |
Branch: 4 branches
| Branch | True | False | Total |
| SvOOK_off(output); |
0 |
0 |
0 |
| SvOOK_off(output); |
0 |
0 |
0 |
| SvOOK_off(output); |
0 |
0 |
0 |
| SvOOK_off(output); |
0 |
0 |
0 |
|
| 623 |
|
| } else { |
| 624 |
2 |
| SvCUR_set(output, 0); |
| 625 |
|
| } |
| 626 |
2 |
| cur_length = SvCUR(output) ; |
| 627 |
2 |
| s->stream.next_out = (char*) SvPVX(output) + cur_length; |
| 628 |
2 |
| increment = SvLEN(output) - cur_length; |
| 629 |
2 |
| s->stream.avail_out = increment; |
| 630 |
|
| |
| 631 |
|
| for (;;) { |
| 632 |
4 |
▶ | if (s->stream.avail_out == 0) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (s->stream.avail_out == 0) { |
2 |
2 |
4 |
|
| 633 |
|
| /* consumed all the available output, so extend it */ |
| 634 |
2 |
| s->stream.next_out = Sv_Grow(output, SvLEN(output) + bufinc) ; |
| 635 |
2 |
| cur_length += increment ; |
| 636 |
2 |
| s->stream.next_out += cur_length ; |
| 637 |
2 |
| increment = bufinc ; |
| 638 |
2 |
| s->stream.avail_out = increment; |
| 639 |
2 |
| bufinc *= 2 ; |
| 640 |
|
| } |
| 641 |
4 |
| RETVAL = BZ2_bzCompress(&(s->stream), BZ_FLUSH); |
| 642 |
|
| |
| 643 |
4 |
▶ | if (RETVAL == BZ_RUN_OK || RETVAL < 0) |
Branch: 2 branches
| Branch | True | False | Total |
| if (RETVAL == BZ_RUN_OK || RETVAL < 0) |
2 |
2 |
4 |
| if (RETVAL == BZ_RUN_OK || RETVAL < 0) |
2 |
0 |
2 |
|
| 644 |
|
| break; |
| 645 |
|
| |
| 646 |
|
| /* deflate has finished flushing only when it hasn't used up |
| 647 |
|
| * all the available space in the output buffer: |
| 648 |
|
| */ |
| 649 |
|
| /* RETVAL == if (s->stream.avail_out != 0 || RETVAL < 0 ) |
| 650 |
|
| break; */ |
| 651 |
|
| } |
| 652 |
|
| |
| 653 |
|
| /* RETVAL = (RETVAL == BZ_STREAM_END ? BZ_OK : RETVAL) ; */ |
| 654 |
2 |
| s->last_error = RETVAL ; |
| 655 |
|
| |
| 656 |
2 |
| s->compressedBytes += cur_length + increment - s->stream.avail_out ; |
| 657 |
|
| |
| 658 |
2 |
▶ | if (RETVAL == BZ_RUN_OK) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (RETVAL == BZ_RUN_OK) { |
2 |
0 |
2 |
|
| 659 |
2 |
| SvPOK_only(output); |
| 660 |
2 |
| SvCUR_set(output, cur_length + increment - s->stream.avail_out) ; |
| 661 |
2 |
▶ | SvSETMAGIC(output); |
Branch: 1 branch
| Branch | True | False | Total |
| SvSETMAGIC(output); |
0 |
2 |
2 |
|
| 662 |
|
| } |
| 663 |
|
| OUTPUT: |
| 664 |
|
| RETVAL |
| 665 |
|
| |
| 666 |
|
| uLong |
| 667 |
|
| total_in_lo32(s) |
| 668 |
|
| Compress::Raw::Bzip2 s |
| 669 |
|
| CODE: |
| 670 |
0 |
▶ | RETVAL = s->stream.total_in_lo32 ; |
Branch: 1 branch
| Branch | True | False | Total |
| RETVAL = s->stream.total_in_lo32 ; |
0 |
0 |
0 |
|
| 671 |
|
| OUTPUT: |
| 672 |
|
| RETVAL |
| 673 |
|
| |
| 674 |
|
| uLong |
| 675 |
|
| total_out_lo32(s) |
| 676 |
|
| Compress::Raw::Bzip2 s |
| 677 |
|
| CODE: |
| 678 |
0 |
▶ | RETVAL = s->stream.total_out_lo32 ; |
Branch: 1 branch
| Branch | True | False | Total |
| RETVAL = s->stream.total_out_lo32 ; |
0 |
0 |
0 |
|
| 679 |
|
| OUTPUT: |
| 680 |
|
| RETVAL |
| 681 |
|
| |
| 682 |
|
| uLong |
| 683 |
|
| compressedBytes(s) |
| 684 |
|
| Compress::Raw::Bzip2 s |
| 685 |
|
| CODE: |
| 686 |
4 |
▶ | RETVAL = s->compressedBytes; |
Branch: 1 branch
| Branch | True | False | Total |
| RETVAL = s->compressedBytes; |
0 |
4 |
4 |
|
| 687 |
|
| OUTPUT: |
| 688 |
|
| RETVAL |
| 689 |
|
| |
| 690 |
|
| uLong |
| 691 |
|
| uncompressedBytes(s) |
| 692 |
|
| Compress::Raw::Bzip2 s |
| 693 |
|
| CODE: |
| 694 |
4 |
▶ | RETVAL = s->uncompressedBytes; |
Branch: 1 branch
| Branch | True | False | Total |
| RETVAL = s->uncompressedBytes; |
0 |
4 |
4 |
|
| 695 |
|
| OUTPUT: |
| 696 |
|
| RETVAL |
| 697 |
|
| |
| 698 |
|
| |
| 699 |
|
| MODULE = Compress::Raw::Bunzip2 PACKAGE = Compress::Raw::Bunzip2 |
| 700 |
|
| |
| 701 |
|
| void |
| 702 |
|
| DispStream(s, message=NULL) |
| 703 |
|
| Compress::Raw::Bunzip2 s |
| 704 |
|
| const char * message |
| 705 |
|
| |
| 706 |
|
| DualType |
| 707 |
|
| bzinflate (s, buf, output) |
| 708 |
|
| Compress::Raw::Bunzip2 s |
| 709 |
|
| SV * buf |
| 710 |
|
| SV * output |
| 711 |
|
| uInt cur_length = 0; |
| 712 |
|
| uInt prefix_length = 0; |
| 713 |
|
| uInt increment = 0; |
| 714 |
|
| uInt bufinc = NO_INIT |
| 715 |
|
| STRLEN na = NO_INIT ; |
| 716 |
|
| STRLEN origlen = NO_INIT |
| 717 |
|
| PREINIT: |
| 718 |
|
| #ifdef UTF8_AVAILABLE |
| 719 |
51120 |
▶ | bool out_utf8 = FALSE; |
Branch: 1 branch
| Branch | True | False | Total |
| bool out_utf8 = FALSE; |
51120 |
0 |
51120 |
|
| 720 |
|
| #endif |
| 721 |
|
| CODE: |
| 722 |
51120 |
| bufinc = s->bufsize; |
| 723 |
|
| /* If the buffer is a reference, dereference it */ |
| 724 |
51120 |
| buf = deRef(buf, "bzinflate") ; |
| 725 |
|
| |
| 726 |
51120 |
▶ | if (s->flags & FLAG_CONSUME_INPUT) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (s->flags & FLAG_CONSUME_INPUT) { |
93 |
51027 |
51120 |
|
| 727 |
93 |
▶ | if (SvREADONLY(buf)) |
Branch: 1 branch
| Branch | True | False | Total |
| if (SvREADONLY(buf)) |
1 |
92 |
93 |
|
| 728 |
1 |
| croak(UNCOMPRESS_CLASS "::bzinflate input parameter cannot be read-only when ConsumeInput is specified"); |
| 729 |
|
| SvPV_force(buf, na); |
| 730 |
|
| } |
| 731 |
|
| #ifdef UTF8_AVAILABLE |
| 732 |
51119 |
▶ | if (DO_UTF8(buf) && !sv_utf8_downgrade(buf, 1)) |
Branch: 3 branches
| Branch | True | False | Total |
| if (DO_UTF8(buf) && !sv_utf8_downgrade(buf, 1)) |
0 |
51119 |
51119 |
| if (DO_UTF8(buf) && !sv_utf8_downgrade(buf, 1)) |
0 |
0 |
0 |
| if (DO_UTF8(buf) && !sv_utf8_downgrade(buf, 1)) |
0 |
0 |
0 |
|
| 733 |
0 |
| croak("Wide character in " UNCOMPRESS_CLASS "::bzinflate input parameter"); |
| 734 |
|
| #endif |
| 735 |
|
| |
| 736 |
|
| /* initialise the input buffer */ |
| 737 |
51119 |
| s->stream.next_in = (char*)SvPV_nomg(buf, origlen) ; |
| 738 |
51119 |
| s->stream.avail_in = (unsigned int) origlen; |
| 739 |
|
| |
| 740 |
|
| /* and retrieve the output buffer */ |
| 741 |
51119 |
| output = deRef_l(output, "bzinflate") ; |
| 742 |
|
| #ifdef UTF8_AVAILABLE |
| 743 |
51119 |
▶ | if (DO_UTF8(output)) |
Branch: 2 branches
| Branch | True | False | Total |
| if (DO_UTF8(output)) |
0 |
51119 |
51119 |
| if (DO_UTF8(output)) |
0 |
0 |
0 |
|
| 744 |
0 |
| out_utf8 = TRUE ; |
| 745 |
51119 |
▶ | if (DO_UTF8(output) && !sv_utf8_downgrade(output, 1)) |
Branch: 3 branches
| Branch | True | False | Total |
| if (DO_UTF8(output) && !sv_utf8_downgrade(output, 1)) |
0 |
51119 |
51119 |
| if (DO_UTF8(output) && !sv_utf8_downgrade(output, 1)) |
0 |
0 |
0 |
| if (DO_UTF8(output) && !sv_utf8_downgrade(output, 1)) |
0 |
0 |
0 |
|
| 746 |
0 |
| croak("Wide character in " UNCOMPRESS_CLASS "::bzinflate output parameter"); |
| 747 |
|
| #endif |
| 748 |
51119 |
▶ | if((s->flags & FLAG_APPEND_OUTPUT) == FLAG_APPEND_OUTPUT) { |
Branch: 1 branch
| Branch | True | False | Total |
| if((s->flags & FLAG_APPEND_OUTPUT) == FLAG_APPEND_OUTPUT) { |
51048 |
71 |
51119 |
|
| 749 |
51048 |
▶ | SvOOK_off(output); |
Branch: 4 branches
| Branch | True | False | Total |
| SvOOK_off(output); |
256 |
50792 |
51048 |
| SvOOK_off(output); |
256 |
0 |
256 |
| SvOOK_off(output); |
0 |
256 |
256 |
| SvOOK_off(output); |
1 |
50791 |
50792 |
|
| 750 |
|
| } else { |
| 751 |
71 |
| SvCUR_set(output, 0); |
| 752 |
|
| } |
| 753 |
|
| |
| 754 |
|
| /* Assume no output buffer - the code below will update if there is any available */ |
| 755 |
51119 |
| s->stream.avail_out = 0; |
| 756 |
|
| |
| 757 |
51119 |
▶ | if (SvLEN(output)) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (SvLEN(output)) { |
51119 |
0 |
51119 |
|
| 758 |
51119 |
| prefix_length = cur_length = SvCUR(output) ; |
| 759 |
|
| |
| 760 |
51119 |
▶ | if (s->flags & FLAG_LIMIT_OUTPUT && SvLEN(output) - cur_length - 1 < bufinc) |
Branch: 2 branches
| Branch | True | False | Total |
| if (s->flags & FLAG_LIMIT_OUTPUT && SvLEN(output) - cur_length - 1 < bufinc) |
20 |
51099 |
51119 |
| if (s->flags & FLAG_LIMIT_OUTPUT && SvLEN(output) - cur_length - 1 < bufinc) |
20 |
0 |
20 |
|
| 761 |
|
| { |
| 762 |
20 |
| Sv_Grow(output, bufinc + cur_length + 1) ; |
| 763 |
|
| } |
| 764 |
|
| |
| 765 |
|
| /* Only setup the stream output pointers if there is spare |
| 766 |
|
| capacity in the outout SV |
| 767 |
|
| */ |
| 768 |
51119 |
▶ | if (SvLEN(output) > cur_length + 1) |
Branch: 1 branch
| Branch | True | False | Total |
| if (SvLEN(output) > cur_length + 1) |
51119 |
0 |
51119 |
|
| 769 |
|
| { |
| 770 |
51119 |
| s->stream.next_out = (char*) SvPVX(output) + cur_length; |
| 771 |
51119 |
| increment = SvLEN(output) - cur_length - 1; |
| 772 |
51119 |
| s->stream.avail_out = increment; |
| 773 |
|
| } |
| 774 |
|
| } |
| 775 |
|
| |
| 776 |
51119 |
| s->bytesInflated = 0; |
| 777 |
|
| |
| 778 |
51119 |
| RETVAL = BZ_OK; |
| 779 |
|
| |
| 780 |
|
| while (1) { |
| 781 |
|
| |
| 782 |
51140 |
▶ | if (s->stream.avail_out == 0) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (s->stream.avail_out == 0) { |
21 |
51119 |
51140 |
|
| 783 |
|
| /* out of space in the output buffer so make it bigger */ |
| 784 |
21 |
| s->stream.next_out = Sv_Grow(output, SvLEN(output) + bufinc + 1) ; |
| 785 |
21 |
| cur_length += increment ; |
| 786 |
21 |
| s->stream.next_out += cur_length ; |
| 787 |
21 |
| increment = bufinc ; |
| 788 |
21 |
| s->stream.avail_out = increment; |
| 789 |
21 |
| bufinc *= 2 ; |
| 790 |
|
| } |
| 791 |
|
| |
| 792 |
|
| /* DispStream(s, "pre"); */ |
| 793 |
51140 |
| RETVAL = BZ2_bzDecompress (&(s->stream)); |
| 794 |
|
| |
| 795 |
|
| /* |
| 796 |
|
| printf("Status %d\n", RETVAL); |
| 797 |
|
| DispStream(s, "apres"); |
| 798 |
|
| */ |
| 799 |
51140 |
▶ | if (RETVAL != BZ_OK || s->flags & FLAG_LIMIT_OUTPUT) |
Branch: 2 branches
| Branch | True | False | Total |
| if (RETVAL != BZ_OK || s->flags & FLAG_LIMIT_OUTPUT) |
51111 |
29 |
51140 |
| if (RETVAL != BZ_OK || s->flags & FLAG_LIMIT_OUTPUT) |
51098 |
13 |
51111 |
|
| 800 |
|
| break ; |
| 801 |
|
| |
| 802 |
51098 |
▶ | if (s->stream.avail_out == 0) |
Branch: 1 branch
| Branch | True | False | Total |
| if (s->stream.avail_out == 0) |
21 |
51077 |
51098 |
|
| 803 |
21 |
| continue ; |
| 804 |
|
| |
| 805 |
51077 |
▶ | if (s->stream.avail_in == 0) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (s->stream.avail_in == 0) { |
51077 |
0 |
51077 |
|
| 806 |
51077 |
| RETVAL = BZ_OK ; |
| 807 |
51077 |
| break ; |
| 808 |
|
| } |
| 809 |
|
| |
| 810 |
|
| } |
| 811 |
|
| |
| 812 |
51119 |
| s->last_error = RETVAL ; |
| 813 |
51119 |
▶ | if (RETVAL == BZ_OK || RETVAL == BZ_STREAM_END) { |
Branch: 2 branches
| Branch | True | False | Total |
| if (RETVAL == BZ_OK || RETVAL == BZ_STREAM_END) { |
29 |
51090 |
51119 |
| if (RETVAL == BZ_OK || RETVAL == BZ_STREAM_END) { |
29 |
0 |
29 |
|
| 814 |
|
| unsigned in ; |
| 815 |
|
| |
| 816 |
51119 |
| s->bytesInflated = cur_length + increment - s->stream.avail_out - prefix_length; |
| 817 |
51119 |
| s->uncompressedBytes += s->bytesInflated ; |
| 818 |
51119 |
| s->compressedBytes += origlen - s->stream.avail_in ; |
| 819 |
|
| |
| 820 |
51119 |
| SvPOK_only(output); |
| 821 |
51119 |
| SvCUR_set(output, prefix_length + s->bytesInflated) ; |
| 822 |
51119 |
| *SvEND(output) = '\0'; |
| 823 |
|
| #ifdef UTF8_AVAILABLE |
| 824 |
51119 |
▶ | if (out_utf8) |
Branch: 1 branch
| Branch | True | False | Total |
| if (out_utf8) |
0 |
51119 |
51119 |
|
| 825 |
0 |
| sv_utf8_upgrade(output); |
| 826 |
|
| #endif |
| 827 |
51119 |
▶ | SvSETMAGIC(output); |
Branch: 1 branch
| Branch | True | False | Total |
| SvSETMAGIC(output); |
256 |
50863 |
51119 |
|
| 828 |
|
| |
| 829 |
|
| /* fix the input buffer */ |
| 830 |
51119 |
▶ | if (s->flags & FLAG_CONSUME_INPUT) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (s->flags & FLAG_CONSUME_INPUT) { |
92 |
51027 |
51119 |
|
| 831 |
92 |
| in = s->stream.avail_in ; |
| 832 |
92 |
| SvCUR_set(buf, in) ; |
| 833 |
92 |
▶ | if (in) |
Branch: 1 branch
| Branch | True | False | Total |
| if (in) |
17 |
75 |
92 |
|
| 834 |
17 |
| Move(s->stream.next_in, SvPVX(buf), in, char) ; |
| 835 |
92 |
| *SvEND(buf) = '\0'; |
| 836 |
92 |
▶ | SvSETMAGIC(buf); |
Branch: 1 branch
| Branch | True | False | Total |
| SvSETMAGIC(buf); |
3 |
89 |
92 |
|
| 837 |
|
| } |
| 838 |
|
| } |
| 839 |
|
| OUTPUT: |
| 840 |
|
| RETVAL |
| 841 |
|
| |
| 842 |
|
| uLong |
| 843 |
|
| inflateCount(s) |
| 844 |
|
| Compress::Raw::Bunzip2 s |
| 845 |
|
| CODE: |
| 846 |
0 |
▶ | RETVAL = s->bytesInflated; |
Branch: 1 branch
| Branch | True | False | Total |
| RETVAL = s->bytesInflated; |
0 |
0 |
0 |
|
| 847 |
|
| OUTPUT: |
| 848 |
|
| RETVAL |
| 849 |
|
| |
| 850 |
|
| |
| 851 |
|
| void |
| 852 |
|
| DESTROY(s) |
| 853 |
|
| Compress::Raw::Bunzip2 s |
| 854 |
|
| CODE: |
| 855 |
30 |
| BZ2_bzDecompressEnd(&s->stream) ; |
| 856 |
30 |
| Safefree(s) ; |
| 857 |
|
| |
| 858 |
|
| |
| 859 |
|
| uLong |
| 860 |
|
| status(s) |
| 861 |
|
| Compress::Raw::Bunzip2 s |
| 862 |
|
| CODE: |
| 863 |
0 |
▶ | RETVAL = s->last_error ; |
Branch: 1 branch
| Branch | True | False | Total |
| RETVAL = s->last_error ; |
0 |
0 |
0 |
|
| 864 |
|
| OUTPUT: |
| 865 |
|
| RETVAL |
| 866 |
|
| |
| 867 |
|
| uLong |
| 868 |
|
| total_in_lo32(s) |
| 869 |
|
| Compress::Raw::Bunzip2 s |
| 870 |
|
| CODE: |
| 871 |
12 |
▶ | RETVAL = s->stream.total_in_lo32 ; |
Branch: 1 branch
| Branch | True | False | Total |
| RETVAL = s->stream.total_in_lo32 ; |
10 |
2 |
12 |
|
| 872 |
|
| OUTPUT: |
| 873 |
|
| RETVAL |
| 874 |
|
| |
| 875 |
|
| uLong |
| 876 |
|
| total_out_lo32(s) |
| 877 |
|
| Compress::Raw::Bunzip2 s |
| 878 |
|
| CODE: |
| 879 |
18 |
▶ | RETVAL = s->stream.total_out_lo32 ; |
Branch: 1 branch
| Branch | True | False | Total |
| RETVAL = s->stream.total_out_lo32 ; |
10 |
8 |
18 |
|
| 880 |
|
| OUTPUT: |
| 881 |
|
| RETVAL |
| 882 |
|
| |
| 883 |
|
| uLong |
| 884 |
|
| compressedBytes(s) |
| 885 |
|
| Compress::Raw::Bunzip2 s |
| 886 |
|
| CODE: |
| 887 |
4 |
▶ | RETVAL = s->compressedBytes; |
Branch: 1 branch
| Branch | True | False | Total |
| RETVAL = s->compressedBytes; |
0 |
4 |
4 |
|
| 888 |
|
| OUTPUT: |
| 889 |
|
| RETVAL |
| 890 |
|
| |
| 891 |
|
| uLong |
| 892 |
|
| uncompressedBytes(s) |
| 893 |
|
| Compress::Raw::Bunzip2 s |
| 894 |
|
| CODE: |
| 895 |
4 |
▶ | RETVAL = s->uncompressedBytes; |
Branch: 1 branch
| Branch | True | False | Total |
| RETVAL = s->uncompressedBytes; |
0 |
4 |
4 |
|
| 896 |
|
| OUTPUT: |
| 897 |
|
| RETVAL |
| 898 |
|
| |
| 899 |
|
| MODULE = Compress::Raw::Bzip2 PACKAGE = Compress::Raw::Bzip2 PREFIX = Zip_ |