pike.git / src / modules / Gz / zlibmod.c

version» Context lines:

pike.git/src/modules/Gz/zlibmod.c:1:   /*   || This file is part of Pike. For copyright information see COPYRIGHT.   || Pike is distributed under GPL, LGPL and MPL. See the file COPYING   || for more information. - || $Id: zlibmod.c,v 1.79 2007/05/19 20:30:14 per Exp $ + || $Id: zlibmod.c,v 1.80 2007/06/02 00:30:03 nilsson Exp $   */      #include "global.h"   #include "zlib_machine.h"   #include "module.h"   #include "program.h"   #include "module_support.h"      #if !defined(HAVE_LIBZ) && !defined(HAVE_LIBGZ)   #undef HAVE_ZLIB_H
pike.git/src/modules/Gz/zlibmod.c:77:    *! packing routines in the libz library.    *!    *! @note    *! This program is only available if libz was available and found when    *! Pike was compiled.    *!    *! @seealso    *! @[Gz.inflate()]    */    - /*! @decl void create(int(0..9)|void level, int|void strategy) + /*! @decl void create(int(0..9)|void level, int|void strategy,@ +  *! int(8..15) window_size)    *!    *! If given, @[level] should be a number from 0 to 9 indicating the    *! packing / CPU ratio. Zero means no packing, 2-3 is considered 'fast',    *! 6 is default and higher is considered 'slow' but gives better packing.    *!    *! This function can also be used to re-initialize a Gz.deflate object    *! so it can be re-used.    *!    *! If the argument is negative, no headers will be emitted. This is    *! needed to produce ZIP-files, as an example. The negative value is    *! then negated, and handled as a positive value.    *!    *! @[strategy], if given, should be one of DEFAULT_STRATEGY, FILTERED or    *! HUFFMAN_ONLY. -  +  *! +  *! @[window_size] defines the size of the LZ77 window from 256 bytes +  *! to 32768 bytes, expressed as 2^x.    */   static void gz_deflate_create(INT32 args)   {    int tmp, wbits = 15;    int strategy = Z_DEFAULT_STRATEGY;    THIS->level=Z_DEFAULT_COMPRESSION;       if(THIS->gz.state)    {   /* mt_lock(& THIS->lock); */    deflateEnd(&THIS->gz);   /* mt_unlock(& THIS->lock); */    }    -  +  if(args>2) +  { +  if(sp[2-args].type != T_INT) +  Pike_error("Bad argument 2 to gz->create()\n"); +  wbits = sp[1-args].u.integer; +  if( wbits == 0 ) wbits = 15; +  if( wbits < 8 || wbits > 15 ) +  Pike_error("Invalid window size for gz_deflate->create().\n"); +  } +     if(args)    {    if(sp[-args].type != T_INT)    Pike_error("Bad argument 1 to gz->create()\n");    THIS->level=sp[-args].u.integer;    if( THIS->level < 0 )    {    wbits = -wbits;    THIS->level = -THIS->level;    }
pike.git/src/modules/Gz/zlibmod.c:227: Inside #if defined(Z_RLE)
   strategy != Z_FILTERED &&   #ifdef Z_RLE    strategy != Z_RLE &&   #endif   #ifdef Z_FIXED    strategy != Z_FIXED &&   #endif    strategy != Z_HUFFMAN_ONLY)    Pike_error("Invalid compression strategy %d for pack.\n", strategy);    -  if( wbits!=15 && wbits!=-15 ) -  Pike_error("Invalid wbits value %d for pack.\n", wbits); +  if( wbits<0 ? (wbits<-15 || wbits>-8) : (wbits<8 || wbits>15 ) ) +  Pike_error("Invalid window size value %d for pack.\n", wbits);       MEMSET(&z, 0, sizeof(z));    z.gz.zalloc = Z_NULL;    z.gz.zfree = Z_NULL;       z.gz.next_in = (Bytef *)data->str;    z.gz.avail_in = (unsigned INT32)(data->len);       ret = deflateInit2(&z.gz, level, Z_DEFLATED, wbits, 9, strategy);   
pike.git/src/modules/Gz/zlibmod.c:268:    ret = do_deflate(buf, &z, Z_FINISH);       deflateEnd(&z.gz);    mt_destroy(&z.lock);       if(ret != Z_STREAM_END)    Pike_error("Error while deflating data (%d).\n",ret);   }      /*! @decl string compress(string data, void|int(0..1) raw, @ -  *! void|int(0..9) level, void|int strategy) +  *! void|int(0..9) level, void|int strategy @ +  *! void|int(8..15) window_size)    *!    */   static void gz_compress(INT32 args)   {    struct pike_string *data;    dynamic_buffer buf;    ONERROR err;       int wbits = 15;    int raw = 0;    int level = 8;    int strategy = Z_DEFAULT_STRATEGY;    -  get_all_args("compress", args, "%n.%d%d%d", &data, &raw, &level, &strategy); +  get_all_args("compress", args, "%n.%d%d%d%d", &data, &raw, &level, &strategy, +  &wbits);    -  +  if( !wbits ) +  wbits = 15; +     if( raw )    wbits = -wbits;       initialize_buf(&buf);    SET_ONERROR(err, toss_buffer, &buf);    zlibmod_pack(data, &buf, level, strategy, wbits);    UNSET_ONERROR(err);       pop_n_elems(args);    push_string(low_free_buf(&buf));
pike.git/src/modules/Gz/zlibmod.c:857: Inside #if defined(HAVE_ZLIB_H)
   add_integer_constant("RLE", Z_RLE,0);   #endif   #ifdef Z_FIXED    add_integer_constant("FIXED", Z_FIXED,0);   #endif       /* function(string,void|int:int) */    ADD_FUNCTION("crc32",gz_crc32,tFunc(tStr tOr(tVoid,tInt),tInt),0);       /* function(string,void|int(0..1),void|int,void|int:string) */ -  ADD_FUNCTION("compress",gz_compress,tFunc(tStr tOr(tVoid,tInt01) tOr(tVoid,tInt09) tOr(tVoid,tInt),tStr),0); +  ADD_FUNCTION("compress",gz_compress,tFunc(tStr tOr(tVoid,tInt01) tOr(tVoid,tInt09) tOr(tVoid,tInt) tOr(tVoid,tInt),tStr),0);       /* function(string,void|int(0..1):string) */    ADD_FUNCTION("uncompress",gz_uncompress,tFunc(tStr tOr(tVoid,tInt01),tStr),0);       PIKE_MODULE_EXPORT(Gz, crc32);    PIKE_MODULE_EXPORT(Gz, zlibmod_pack);    PIKE_MODULE_EXPORT(Gz, zlibmod_unpack);   #else    if(!TEST_COMPAT(7,6))    HIDE_MODULE();