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

version» Context lines:

pike.git/src/modules/Gz/zlibmod.c:19:      #include "interpret.h"   #include "svalue.h"   #include "stralloc.h"   #include "array.h"   #include "pike_macros.h"   #include "stralloc.h"   #include "object.h"   #include "pike_types.h"   #include "threads.h" - #include "dynamic_buffer.h" + #include "buffer.h"   #include "operators.h"   #include "bignum.h"      #include <zlib.h>         #define sp Pike_sp      struct zipper   {
pike.git/src/modules/Gz/zlibmod.c:324:    }   }      #ifdef _REENTRANT   static void do_mt_unlock (PIKE_MUTEX_T *lock)   {    mt_unlock (lock);   }   #endif    - static int do_deflate(dynamic_buffer *buf, + static int do_deflate(struct byte_buffer *buf,    struct zipper *this,    int flush)   {    int ret=0;      #ifdef _REENTRANT    ONERROR uwp;    THREADS_ALLOW();    mt_lock(& this->lock);    THREADS_DISALLOW();    SET_ONERROR (uwp, do_mt_unlock, &this->lock);   #endif       if(!this->gz.state)    ret=Z_STREAM_ERROR;    else    do    { -  this->gz.next_out=(Bytef *)low_make_buf_space( +  this->gz.next_out=(Bytef *)buffer_alloc(buf,    /* recommended by the zlib people */    (this->gz.avail_out =    this->gz.avail_in ?    this->gz.avail_in+this->gz.avail_in/1000+42 : -  4096), -  buf); +  4096));       THREADS_ALLOW();    ret=deflate(& this->gz, flush);    THREADS_DISALLOW();       /* Absorb any unused space /Hubbe */ -  low_make_buf_space(-((ptrdiff_t)this->gz.avail_out), buf); +  buffer_remove(buf, this->gz.avail_out);       if(ret == Z_BUF_ERROR) ret=Z_OK;    }    while (ret==Z_OK && (this->gz.avail_in || !this->gz.avail_out));      #ifdef _REENTRANT    CALL_AND_UNSET_ONERROR (uwp);   #endif    return ret;   }    - void low_zlibmod_pack(struct memobj data, dynamic_buffer *buf, + void low_zlibmod_pack(struct memobj data, struct byte_buffer *buf,    int level, int strategy, int wbits)   {    struct zipper z;    int ret;       if(level < Z_NO_COMPRESSION ||    level > Z_BEST_COMPRESSION)    Pike_error("Compression level out of range for pack. %d %d %d\n",    Z_DEFAULT_COMPRESSION, Z_NO_COMPRESSION, Z_BEST_COMPRESSION);   
pike.git/src/modules/Gz/zlibmod.c:444:       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);   }    - void zlibmod_pack(struct pike_string *data, dynamic_buffer *buf, + void zlibmod_pack(struct pike_string *data, struct byte_buffer *buf,    int level, int strategy, int wbits)   {    struct memobj lowdata;    lowdata.ptr = data->str;    lowdata.len = data->len;    lowdata.shift = data->size_shift;    low_zlibmod_pack(lowdata, buf, level, strategy, wbits);   }      /*! @endclass
pike.git/src/modules/Gz/zlibmod.c:516:    *! Defines the size of the LZ77 window from 256 bytes to 32768    *! bytes, expressed as 2^x.    *!    *! @seealso    *! @[deflate], @[inflate], @[uncompress]    */   static void gz_compress(INT32 args)   {    struct svalue *data_arg;    struct memobj data; -  dynamic_buffer buf; +  struct byte_buffer buf;    ONERROR err;       int wbits = 15;    int raw = 0;    int level = 8;    int strategy = Z_DEFAULT_STRATEGY;       get_all_args("compress", args, "%*.%d%d%d%d", &data_arg, &raw, &level, &strategy,    &wbits);   
pike.git/src/modules/Gz/zlibmod.c:558:    }    if (data.shift)    Pike_error("Cannot input wide string to compress\n");       if( !wbits )    wbits = 15;       if( raw )    wbits = -wbits;    -  initialize_buf(&buf); -  SET_ONERROR(err, toss_buffer, &buf); +  buffer_init(&buf); +  SET_ONERROR(err, buffer_free, &buf);    low_zlibmod_pack(data, &buf, level, strategy, wbits);    UNSET_ONERROR(err);       pop_n_elems(args); -  push_string(low_free_buf(&buf)); +  push_string(buffer_finish_pike_string(&buf));   }      /*! @class deflate    */      /*! @decl string(8bit) deflate(string(8bit)|String.Buffer|System.Memory|Stdio.Buffer data, @    *! int|void flush)    *!    *! This function performs gzip style compression on a string @[data] and    *! returns the packed data. Streaming can be done by calling this
pike.git/src/modules/Gz/zlibmod.c:597:    *! @endint    *!    *! @seealso    *! @[Gz.inflate->inflate()]    */   static void gz_deflate(INT32 args)   {    struct memobj data;    int flush, fail;    struct zipper *this=THIS; -  dynamic_buffer buf; +  struct byte_buffer buf;    ONERROR err;       if(THIS->state == 1)    {    deflateEnd(& THIS->gz);    deflateInit(& THIS->gz, THIS->level);    THIS->state=0;    }       if(!THIS->gz.state)
pike.git/src/modules/Gz/zlibmod.c:664:    default:    Pike_error("Argument 2 to gz_deflate->deflate() out of range.\n");    }    }else{    flush=Z_FINISH;    }       this->gz.next_in=(Bytef *)data.ptr;    this->gz.avail_in = (unsigned INT32)(data.len);    -  initialize_buf(&buf); +  buffer_init(&buf);    -  SET_ONERROR(err,toss_buffer,&buf); +  SET_ONERROR(err,buffer_free,&buf);    fail=do_deflate(&buf,this,flush);    UNSET_ONERROR(err);       if(fail != Z_OK && fail != Z_STREAM_END)    { -  toss_buffer(&buf); +  buffer_free(&buf);    if(THIS->gz.msg)    Pike_error("Error in gz_deflate->deflate(): %s\n",THIS->gz.msg);    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)); +  push_string(buffer_finish_pike_string(&buf));   }         static void init_gz_deflate(struct object *UNUSED(o))   {    mt_init(& THIS->lock);    memset(& THIS->gz, 0, sizeof(THIS->gz));    THIS->gz.zalloc=Z_NULL;    THIS->gz.zfree=Z_NULL;    THIS->gz.opaque=(void *)THIS;
pike.git/src/modules/Gz/zlibmod.c:840:    break;       default:    if(THIS->gz.msg)    Pike_error("Failed to initialize Gz.inflate: %s\n",THIS->gz.msg);    else    Pike_error("Failed to initialize Gz.inflate (%d).\n", tmp);    }   }    - static int do_inflate(dynamic_buffer *buf, + static int do_inflate(struct byte_buffer *buf,    struct zipper *this,    int flush)   {    int fail=0;      #ifdef _REENTRANT    ONERROR uwp;    THREADS_ALLOW();    mt_lock(& this->lock);    THREADS_DISALLOW();
pike.git/src/modules/Gz/zlibmod.c:867: Inside #if 0
   }else{   #if 0    static int fnord=0;    fnord++;   #endif       do    {    char *loc;    int ret; -  loc=low_make_buf_space(BUF,buf); +  loc=buffer_alloc(buf, BUF);    THREADS_ALLOW();    this->gz.next_out=(Bytef *)loc;    this->gz.avail_out=BUF;       ret=inflate(& this->gz, flush);       THREADS_DISALLOW(); -  low_make_buf_space(-((ptrdiff_t)this->gz.avail_out), buf); +  buffer_remove(buf, this->gz.avail_out);       if(ret == Z_BUF_ERROR) ret=Z_OK;       if (ret == Z_NEED_DICT && this->dict)    ret = inflateSetDictionary(&this->gz,    (const Bytef*)this->dict->str,    this->dict->len);       if(ret != Z_OK)    {
pike.git/src/modules/Gz/zlibmod.c:898:    }    } while(!this->gz.avail_out || flush==Z_FINISH || this->gz.avail_in);    }      #ifdef _REENTRANT    CALL_AND_UNSET_ONERROR (uwp);   #endif    return fail;   }    - void low_zlibmod_unpack(struct memobj data, dynamic_buffer *buf, int raw) + void low_zlibmod_unpack(struct memobj data, struct byte_buffer *buf, int raw)   {    struct zipper z;    int ret;       memset(&z, 0, sizeof(z));    z.gz.zalloc = Z_NULL;    z.gz.zfree = Z_NULL;       z.gz.next_in=(Bytef *)data.ptr;    z.gz.avail_in = (unsigned INT32)(data.len);
pike.git/src/modules/Gz/zlibmod.c:948:    ret = do_inflate(buf, &z, Z_SYNC_FLUSH);    mt_destroy(&z.lock);    inflateEnd( &z.gz );       if(ret==Z_OK)    Pike_error("Compressed data is truncated.\n");    if(ret!=Z_STREAM_END)    Pike_error("Failed to inflate data (%d).\n", ret);   }    - void zlibmod_unpack(struct pike_string *data, dynamic_buffer *buf, int raw) + void zlibmod_unpack(struct pike_string *data, struct byte_buffer *buf, int raw)   {    struct memobj lowdata;    lowdata.ptr = data->str;    lowdata.len = data->len;    lowdata.shift = data->size_shift;    low_zlibmod_unpack(lowdata, buf, raw);   }      /*! @endclass   */      /*! @decl string(8bit) uncompress(string(8bit)|String.Buffer|System.Memory|Stdio.Buffer data, void|int(0..1) raw)    *!    *! Uncompresses the @[data] and returns it. The @[raw] parameter    *! tells the decoder that the indata lacks the data header and footer    *! defined in @rfc{1950@}.    */   static void gz_uncompress(INT32 args)   { -  dynamic_buffer buf; +  struct byte_buffer buf;    struct memobj data;    ONERROR err;    int raw = 0;       if(args<1)    SIMPLE_WRONG_NUM_ARGS_ERROR("uncompress", 1);    switch (TYPEOF(Pike_sp[-args]))    {    case PIKE_T_STRING:    {
pike.git/src/modules/Gz/zlibmod.c:1007:    if (data.shift)    Pike_error("Cannot input wide string to uncompress\n");    if(args>1)    {    if(TYPEOF(Pike_sp[1-args]) == PIKE_T_INT)    raw = Pike_sp[1-args].u.integer;    else    SIMPLE_ARG_TYPE_ERROR("uncompress", 2, "int");    }    -  initialize_buf(&buf); -  SET_ONERROR(err, toss_buffer, &buf); +  buffer_init(&buf); +  SET_ONERROR(err, buffer_free, &buf);    low_zlibmod_unpack(data, &buf, raw);    UNSET_ONERROR(err);       pop_n_elems(args); -  push_string(low_free_buf(&buf)); +  push_string(buffer_finish_pike_string(&buf));      }      /*! @class inflate    */      /*! @decl string(8bit) inflate(string(8bit)|String.Buffer|System.Memory|Stdio.Buffer data)    *!    *! This function performs gzip style decompression. It can inflate    *! a whole file at once or in blocks.
pike.git/src/modules/Gz/zlibmod.c:1044:    *! @endcode    *!    *! @seealso    *! @[Gz.deflate->deflate()], @[Gz.decompress]    */   static void gz_inflate(INT32 args)   {    struct memobj data;    int fail;    struct zipper *this=THIS; -  dynamic_buffer buf; +  struct byte_buffer buf;    ONERROR err;       if(!THIS->gz.state)    Pike_error("gz_inflate not initialized or destructed\n");       if(args<1)    Pike_error("Too few arguments to gz_inflate->inflate()\n");       switch (TYPEOF(Pike_sp[-args]))    {
pike.git/src/modules/Gz/zlibmod.c:1082:    default:    Pike_error("Bad argument 1 to gz_inflate->inflate()\n");    }       if (data.shift)    Pike_error("Cannot input wide string to gz_inflate->inflate()\n");       this->gz.next_in=(Bytef *)data.ptr;    this->gz.avail_in = (unsigned INT32)(data.len);    -  initialize_buf(&buf); +  buffer_init(&buf);    -  SET_ONERROR(err,toss_buffer,&buf); +  SET_ONERROR(err,buffer_free,&buf);    fail=do_inflate(&buf,this,Z_SYNC_FLUSH);    UNSET_ONERROR(err);       if(fail != Z_OK && fail != Z_STREAM_END)    { -  toss_buffer(&buf); +  buffer_free(&buf);    if(THIS->gz.msg)    Pike_error("Error in gz_inflate->inflate(): %s\n",THIS->gz.msg);    else    Pike_error("Error in gz_inflate->inflate(): %d\n",fail);    }       pop_n_elems(args);    -  push_string(low_free_buf(&buf)); +  push_string(buffer_finish_pike_string(&buf));       if(fail == Z_STREAM_END)    {    struct pike_string *old_epilogue = this->epilogue;    if(old_epilogue) {    push_string(old_epilogue);    this->epilogue = NULL;    }    push_string(make_shared_binary_string((const char *)this->gz.next_in,    this->gz.avail_in));