📄 zlib.xs
字号:
static di_stream *#ifdef CAN_PROTOTYPEInitStream(void)#elseInitStream()#endif{ di_stream *s ; ZMALLOC(s, di_stream) ; return s ; }static void#ifdef CAN_PROTOTYPEPostInitStream(di_stream * s, int flags, int bufsize, int windowBits)#elsePostInitStream(s, flags, bufsize, windowBits) di_stream *s ; int flags ; int bufsize ; int windowBits ;#endif{ s->bufsize = bufsize ; s->compressedBytes = s->uncompressedBytes = s->last_error = 0 ; s->flags = flags ; s->zip_mode = (windowBits < 0) ; if (flags & FLAG_CRC32) s->crc32 = crcInitial ; if (flags & FLAG_ADLER32) s->adler32 = adlerInitial ;}static SV* #ifdef CAN_PROTOTYPEdeRef(SV * sv, char * string)#elsedeRef(sv, string)SV * sv ;char * string;#endif{ dTHX; SvGETMAGIC(sv); if (SvROK(sv)) { sv = SvRV(sv) ; SvGETMAGIC(sv); switch(SvTYPE(sv)) { case SVt_PVAV: case SVt_PVHV: case SVt_PVCV: croak("%s: buffer parameter is not a SCALAR reference", string); } if (SvROK(sv)) croak("%s: buffer parameter is a reference to a reference", string) ; } if (!SvOK(sv)) { sv = newSVpv("", 0); } return sv ;}static SV*#ifdef CAN_PROTOTYPEdeRef_l(SV * sv, char * string)#elsedeRef_l(sv, string)SV * sv ;char * string ;#endif{ dTHX; bool wipe = 0 ; SvGETMAGIC(sv); wipe = ! SvOK(sv) ; if (SvROK(sv)) { sv = SvRV(sv) ; SvGETMAGIC(sv); wipe = ! SvOK(sv) ; switch(SvTYPE(sv)) { case SVt_PVAV: case SVt_PVHV: case SVt_PVCV: croak("%s: buffer parameter is not a SCALAR reference", string); } if (SvROK(sv)) croak("%s: buffer parameter is a reference to a reference", string) ; } if (SvREADONLY(sv) && PL_curcop != &PL_compiling) croak("%s: buffer parameter is read-only", string); SvUPGRADE(sv, SVt_PV); if (wipe) SvCUR_set(sv, 0); SvOOK_off(sv); SvPOK_only(sv); return sv ;}#include "constants.h"MODULE = Compress::Raw::Zlib PACKAGE = Compress::Raw::Zlib PREFIX = Zip_REQUIRE: 1.924PROTOTYPES: DISABLEINCLUDE: constants.xsBOOT: /* Check this version of zlib is == 1 */ if (zlibVersion()[0] != '1') croak("Compress::Raw::Zlib needs zlib version 1.x\n") ; { /* Create the $os_code scalar */ SV * os_code_sv = perl_get_sv("Compress::Raw::Zlib::gzip_os_code", GV_ADDMULTI) ; sv_setiv(os_code_sv, GZIP_OS_CODE) ; }#define Zip_zlib_version() (const char*)zlib_versionconst char*Zip_zlib_version()unsignedZLIB_VERNUM() CODE:#ifdef ZLIB_VERNUM RETVAL = ZLIB_VERNUM ;#else /* 1.1.4 => 0x1140 */ RETVAL = (ZLIB_VERSION[0] - '0') << 12 ; RETVAL += (ZLIB_VERSION[2] - '0') << 8 ; RETVAL += (ZLIB_VERSION[4] - '0') << 4 ;#endif OUTPUT: RETVALMODULE = Compress::Raw::Zlib PACKAGE = Compress::Raw::Zlib PREFIX = Zip_#define Zip_adler32(buf, adler) adler32(adler, buf, (uInt)len)uLongZip_adler32(buf, adler=adlerInitial) uLong adler = NO_INIT STRLEN len = NO_INIT Bytef * buf = NO_INIT SV * sv = ST(0) ; INIT: /* If the buffer is a reference, dereference it */ sv = deRef(sv, "adler32") ;#ifdef UTF8_AVAILABLE if (DO_UTF8(sv) && !sv_utf8_downgrade(sv, 1)) croak("Wide character in Compress::Raw::Zlib::adler32");#endif buf = (Byte*)SvPVbyte(sv, len) ; if (items < 2) adler = adlerInitial; else if (SvOK(ST(1))) adler = SvUV(ST(1)) ; else adler = adlerInitial; OUTPUT: RETVAL #define Zip_crc32(buf, crc) crc32(crc, buf, (uInt)len)uLongZip_crc32(buf, crc=crcInitial) uLong crc = NO_INIT STRLEN len = NO_INIT Bytef * buf = NO_INIT SV * sv = ST(0) ; INIT: /* If the buffer is a reference, dereference it */ sv = deRef(sv, "crc32") ;#ifdef UTF8_AVAILABLE if (DO_UTF8(sv) && !sv_utf8_downgrade(sv, 1)) croak("Wide character in Compress::Raw::Zlib::crc32");#endif buf = (Byte*)SvPVbyte(sv, len) ; if (items < 2) crc = crcInitial; else if (SvOK(ST(1))) crc = SvUV(ST(1)) ; else crc = crcInitial;uLongcrc32_combine(crc1, crc2, len2) uLong crc1 uLong crc2 z_off_t len2 CODE:#ifndef AT_LEAST_ZLIB_1_2_2_1 crc1 = crc1; crc2 = crc2 ; len2 = len2; /* Silence -Wall */ croak("crc32_combine needs zlib 1.2.3 or better");#else RETVAL = crc32_combine(crc1, crc2, len2);#endif OUTPUT: RETVALuLongadler32_combine(adler1, adler2, len2) uLong adler1 uLong adler2 z_off_t len2 CODE:#ifndef AT_LEAST_ZLIB_1_2_2_1 adler1 = adler1; adler2 = adler2 ; len2 = len2; /* Silence -Wall */ croak("adler32_combine needs zlib 1.2.3 or better");#else RETVAL = adler32_combine(adler1, adler2, len2);#endif OUTPUT: RETVALMODULE = Compress::Raw::Zlib PACKAGE = Compress::Raw::Zlibvoid_deflateInit(flags,level, method, windowBits, memLevel, strategy, bufsize, dictionary) int flags int level int method int windowBits int memLevel int strategy uLong bufsize SV* dictionary PPCODE: int err ; deflateStream s ; if (trace) warn("in _deflateInit(level=%d, method=%d, windowBits=%d, memLevel=%d, strategy=%d, bufsize=%ld dictionary=%p)\n", level, method, windowBits, memLevel, strategy, bufsize, dictionary) ; if ((s = InitStream() )) { s->Level = level; s->Method = method; s->WindowBits = windowBits; s->MemLevel = memLevel; s->Strategy = strategy; err = deflateInit2(&(s->stream), level, method, windowBits, memLevel, strategy); /* Check if a dictionary has been specified */ if (err == Z_OK && SvCUR(dictionary)) {#ifdef UTF8_AVAILABLE if (DO_UTF8(dictionary) && !sv_utf8_downgrade(dictionary, 1)) croak("Wide character in Compress::Raw::Zlib::Deflate::new dicrionary parameter");#endif err = deflateSetDictionary(&(s->stream), (const Bytef*) SvPVbyte_nolen(dictionary), SvCUR(dictionary)) ; s->dict_adler = s->stream.adler ; } if (err != Z_OK) { Safefree(s) ; s = NULL ; } else PostInitStream(s, flags, bufsize, windowBits) ; } else err = Z_MEM_ERROR ; { SV* obj = sv_setref_pv(sv_newmortal(), "Compress::Raw::Zlib::deflateStream", (void*)s); XPUSHs(obj); } if (GIMME == G_ARRAY) { SV * sv = sv_2mortal(newSViv(err)) ; setDUALstatus(sv, err); XPUSHs(sv) ; }void_inflateInit(flags, windowBits, bufsize, dictionary) int flags int windowBits uLong bufsize SV * dictionary ALIAS: _inflateScanInit = 1 PPCODE: int err = Z_OK ; inflateStream s ;#ifndef MAGIC_APPEND if (ix == 1) croak("inflateScanInit needs zlib 1.2.1 or better");#endif if (trace) warn("in _inflateInit(windowBits=%d, bufsize=%lu, dictionary=%lu\n", windowBits, bufsize, (unsigned long)SvCUR(dictionary)) ; if ((s = InitStream() )) { s->WindowBits = windowBits; err = inflateInit2(&(s->stream), windowBits); if (err != Z_OK) { Safefree(s) ; s = NULL ; } else if (SvCUR(dictionary)) { /* Dictionary specified - take a copy for use in inflate */ s->dictionary = newSVsv(dictionary) ; } if (s) { PostInitStream(s, flags, bufsize, windowBits) ;#ifdef MAGIC_APPEND if (ix == 1) { s->window = (unsigned char *)safemalloc(WINDOW_SIZE); }#endif } } else err = Z_MEM_ERROR ; { SV* obj = sv_setref_pv(sv_newmortal(), ix == 1 ? "Compress::Raw::Zlib::inflateScanStream" : "Compress::Raw::Zlib::inflateStream", (void*)s); XPUSHs(obj); } if (GIMME == G_ARRAY) { SV * sv = sv_2mortal(newSViv(err)) ; setDUALstatus(sv, err); XPUSHs(sv) ; } MODULE = Compress::Raw::Zlib PACKAGE = Compress::Raw::Zlib::deflateStreamvoidDispStream(s, message=NULL) Compress::Raw::Zlib::deflateStream s char * messageDualTypedeflateReset(s) Compress::Raw::Zlib::deflateStream s CODE: RETVAL = deflateReset(&(s->stream)) ; if (RETVAL == Z_OK) { PostInitStream(s, s->flags, s->bufsize, s->WindowBits) ; } OUTPUT: RETVALDualType deflate (s, buf, output) Compress::Raw::Zlib::deflateStream s SV * buf SV * output uInt cur_length = NO_INIT uInt increment = NO_INIT uInt prefix = NO_INIT int RETVAL = 0; uLong bufinc = NO_INIT CODE: bufinc = s->bufsize; /* If the input buffer is a reference, dereference it */ buf = deRef(buf, "deflate") ; /* initialise the input buffer */#ifdef UTF8_AVAILABLE if (DO_UTF8(buf) && !sv_utf8_downgrade(buf, 1)) croak("Wide character in Compress::Raw::Zlib::Deflate::deflate input parameter");#endif s->stream.next_in = (Bytef*)SvPVbyte_nolen(buf) ; s->stream.avail_in = SvCUR(buf) ; if (s->flags & FLAG_CRC32) s->crc32 = crc32(s->crc32, s->stream.next_in, s->stream.avail_in) ; if (s->flags & FLAG_ADLER32) s->adler32 = adler32(s->adler32, s->stream.next_in, s->stream.avail_in) ; /* and retrieve the output buffer */ output = deRef_l(output, "deflate") ;#ifdef UTF8_AVAILABLE if (DO_UTF8(output) && !sv_utf8_downgrade(output, 1)) croak("Wide character in Compress::Raw::Zlib::Deflate::deflate output parameter");#endif if((s->flags & FLAG_APPEND) != FLAG_APPEND) { SvCUR_set(output, 0); /* sv_setpvn(output, "", 0); */ } prefix = cur_length = SvCUR(output) ; s->stream.next_out = (Bytef*) SvPVbyte_nolen(output) + cur_length; increment = SvLEN(output) - cur_length; s->stream.avail_out = increment;#ifdef SETP_BYTE /* Check for saved output from deflateParams */ if (s->deflateParams_out_valid) { *(s->stream.next_out) = s->deflateParams_out_byte; ++ s->stream.next_out; -- s->stream.avail_out ; s->deflateParams_out_valid = FALSE; }#else /* Check for saved output from deflateParams */ if (s->deflateParams_out_length) { uLong plen = s->deflateParams_out_length ; /* printf("Copy %d bytes saved data\n", plen);*/ if (s->stream.avail_out < plen) { /*printf("GROW from %d to %d\n", s->stream.avail_out, SvLEN(output) + plen - s->stream.avail_out); */ Sv_Grow(output, SvLEN(output) + plen - s->stream.avail_out) ; } Copy(s->stream.next_out, s->deflateParams_out_buffer, plen, Bytef) ; cur_length = cur_length + plen; SvCUR_set(output, cur_length); s->stream.next_out += plen ; s->stream.avail_out = SvLEN(output) - cur_length ; increment = s->stream.avail_out; s->deflateParams_out_length = 0; }#endif while (s->stream.avail_in != 0) { if (s->stream.avail_out == 0) { /* out of space in the output buffer so make it bigger */ Sv_Grow(output, SvLEN(output) + bufinc) ; cur_length += increment ; s->stream.next_out = (Bytef*) SvPVbyte_nolen(output) + cur_length ; increment = bufinc ; s->stream.avail_out = increment; bufinc *= 2 ; } RETVAL = deflate(&(s->stream), Z_NO_FLUSH);
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -