Branch: Tag:

2001-07-05

2001-07-05 01:47:20 by Fredrik Hübinette (Hubbe) <hubbe@hubbe.net>

handle repeated deflate() calls

Rev: src/modules/Gz/zlibmod.c:1.41

5:   \*/   /**/   #include "global.h" - RCSID("$Id: zlibmod.c,v 1.40 2001/06/13 12:48:03 grubba Exp $"); + RCSID("$Id: zlibmod.c,v 1.41 2001/07/05 01:47:20 hubbe Exp $");      #include "zlib_machine.h"   
34:      struct zipper   { +  char level; +  char state;    struct z_stream_s gz;   #ifdef _REENTRANT    DEFINE_MUTEX(lock);
83:    */   static void gz_deflate_create(INT32 args)   { -  int level=Z_DEFAULT_COMPRESSION; +  int tmp; +  THIS->level=Z_DEFAULT_COMPRESSION;       if(THIS->gz.state)    {
96:    {    if(sp[-args].type != T_INT)    Pike_error("Bad argument 1 to gz->create()\n"); -  level=sp[-args].u.integer; -  if(level < Z_NO_COMPRESSION || -  level > Z_BEST_COMPRESSION) +  THIS->level=sp[-args].u.integer; +  if(THIS->level < Z_NO_COMPRESSION || +  THIS->level > Z_BEST_COMPRESSION)    {    Pike_error("Compression level out of range for gz_deflate->create()\n");    }
110:       pop_n_elems(args);   /* mt_lock(& THIS->lock); */ -  level=deflateInit(&THIS->gz, level); +  tmp=deflateInit(&THIS->gz, THIS->level);   /* mt_unlock(& THIS->lock); */ -  switch(level) +  switch(tmp)    {    case Z_OK:    return;
195:    dynamic_buffer buf;    ONERROR err;    +  if(THIS->state == 1) +  { +  deflateEnd(& THIS->gz); +  deflateInit(& THIS->gz, THIS->level); +  THIS->state=0; +  } +     if(!THIS->gz.state)    Pike_error("gz_deflate not initialized or destructed\n");   
245:    else    Pike_error("Error in gz_deflate->deflate(): %d\n",fail);    } +  +  if(fail == Z_STREAM_END) +  THIS->state=1; +     pop_n_elems(args);       push_string(low_free_buf(&buf));
258:    THIS->gz.zalloc=Z_NULL;    THIS->gz.zfree=Z_NULL;    THIS->gz.opaque=(void *)THIS; -  deflateInit(& THIS->gz, Z_DEFAULT_COMPRESSION); +  THIS->state=0; +  deflateInit(& THIS->gz, THIS->level = Z_DEFAULT_COMPRESSION);   }      static void exit_gz_deflate(struct object *o)
419:    else    Pike_error("Error in gz_inflate->inflate(): %d\n",fail);    } +     pop_n_elems(args);       push_string(low_free_buf(&buf));
435:    MEMSET(& THIS->gz, 0, sizeof(THIS->gz));    THIS->gz.zalloc=Z_NULL;    THIS->gz.zfree=Z_NULL; -  THIS->gz.opaque=0; +  THIS->gz.opaque=(void *)THIS;    inflateInit(&THIS->gz);    inflateEnd(&THIS->gz);   }