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.82 2007/07/03 07:01:32 mast Exp $ + || $Id: zlibmod.c,v 1.83 2007/07/05 12:41:58 grubba 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:162:    Pike_error("Invalid compression strategy for gz_deflate->create()\n");    }    }       THIS->gz.zalloc=Z_NULL;    THIS->gz.zfree=Z_NULL;    THIS->gz.opaque=(void *)THIS;       pop_n_elems(args);   /* mt_lock(& THIS->lock); */ +  do {    tmp=deflateInit2(&THIS->gz, THIS->level, Z_DEFLATED, wbits, 9, strategy ); -  +  if (tmp == Z_STREAM_ERROR) { +  /* zlib 1.1.4's deflateInit2() only supports wbits 9..15 (not 8). */ +  if (wbits == -8) wbits = -9; +  else if (wbits == 8) wbits = 9; +  else break; +  continue; +  } +  break; +  } while(1);   /* mt_unlock(& THIS->lock); */    switch(tmp)    {    case Z_OK:    return;       case Z_VERSION_ERROR:    Pike_error("libz not compatible with zlib.h!!!\n");    break;   
pike.git/src/modules/Gz/zlibmod.c:255:    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);    +  do {    ret = deflateInit2(&z.gz, level, Z_DEFLATED, wbits, 9, strategy); -  +  if (ret == Z_STREAM_ERROR) { +  /* zlib 1.1.4's deflateInit2() only supports wbits 9..15 (not 8). */ +  if (wbits == -8) wbits = -9; +  else if (wbits == 8) wbits = 9; +  else break; +  continue; +  } +  break; +  } while(1);       switch(ret)    {    case Z_OK:    break;       case Z_VERSION_ERROR:    Pike_error("libz not compatible with zlib.h!!!\n");    break;   
pike.git/src/modules/Gz/zlibmod.c:828:      /*! @endmodule    */   #endif      PIKE_MODULE_EXIT {}      PIKE_MODULE_INIT   {   #ifdef HAVE_ZLIB_H +  struct z_stream_s z; /* Used to detect support for extensions. */ +  int have_rle = 0; +  int have_fixed = 0; +     start_new_program();    ADD_STORAGE(struct zipper);       /* function(int|void,int|void:void) */    ADD_FUNCTION("create",gz_deflate_create,tFunc(tOr(tInt,tVoid) tOr(tInt,tVoid),tVoid),0);    /* function(string,int|void:string) */    ADD_FUNCTION("deflate",gz_deflate,tFunc(tStr tOr(tInt,tVoid),tStr),0);       add_integer_constant("NO_FLUSH",Z_NO_FLUSH,0);    add_integer_constant("PARTIAL_FLUSH",Z_PARTIAL_FLUSH,0);    add_integer_constant("SYNC_FLUSH",Z_SYNC_FLUSH,0);    add_integer_constant("FINISH",Z_FINISH,0);    add_integer_constant("DEFAULT_STRATEGY", Z_DEFAULT_STRATEGY,0);    add_integer_constant("FILTERED", Z_FILTERED,0);    add_integer_constant("HUFFMAN_ONLY", Z_HUFFMAN_ONLY,0); -  +  +  MEMSET(&z, 0, sizeof(z));   #ifdef Z_RLE -  +  if (deflateInit2(&z, 8, Z_DEFLATED, 9, 9, Z_RLE) == Z_OK) { +  have_rle = 1; +  deflateEnd(&z);    add_integer_constant("RLE", Z_RLE,0); -  +  }   #endif   #ifdef Z_FIXED -  +  if (deflateInit2(&z, 8, Z_DEFLATED, 9, 9, Z_FIXED) == Z_OK) { +  have_fixed = 1; +  deflateEnd(&z);    add_integer_constant("FIXED", Z_FIXED,0); -  +  }   #endif       set_init_callback(init_gz_deflate);    set_exit_callback(exit_gz_deflate);       end_class("deflate",0);       start_new_program();    ADD_STORAGE(struct zipper);   
pike.git/src/modules/Gz/zlibmod.c:883: Inside #if defined(HAVE_ZLIB_H)
   end_class("inflate",0);       add_integer_constant("NO_FLUSH",Z_NO_FLUSH,0);    add_integer_constant("PARTIAL_FLUSH",Z_PARTIAL_FLUSH,0);    add_integer_constant("SYNC_FLUSH",Z_SYNC_FLUSH,0);    add_integer_constant("FINISH",Z_FINISH,0);    add_integer_constant("DEFAULT_STRATEGY", Z_DEFAULT_STRATEGY,0);    add_integer_constant("FILTERED", Z_FILTERED,0);    add_integer_constant("HUFFMAN_ONLY", Z_HUFFMAN_ONLY,0);   #ifdef Z_RLE +  if (have_rle) {    add_integer_constant("RLE", Z_RLE,0); -  +  }   #endif   #ifdef Z_FIXED -  +  if (have_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) tOr(tVoid,tInt),tStr),0);       /* function(string,void|int(0..1):string) */    ADD_FUNCTION("uncompress",gz_uncompress,tFunc(tStr tOr(tVoid,tInt01),tStr),0);