From: Paul Mackerras Date: Wed, 30 Apr 1997 05:41:20 +0000 (+0000) Subject: mods to separate allocations during initialization and operation X-Git-Tag: RELEASE_2_3_6~228 X-Git-Url: http://git.ozlabs.org/?p=ppp.git;a=commitdiff_plain;h=93afd27dab977b4fcca4d54c0a0a90539a1e5f69;hp=d8f539f8de6c09c8689f21404cdc09947a80114b mods to separate allocations during initialization and operation --- diff --git a/common/zlib.c b/common/zlib.c index 6390220..8883bac 100644 --- a/common/zlib.c +++ b/common/zlib.c @@ -11,11 +11,11 @@ * - added Z_PACKET_FLUSH (see zlib.h for details) * - added inflateIncomp * - * $Id: zlib.c,v 1.5 1997/03/04 03:26:35 paulus Exp $ + * $Id: zlib.c,v 1.6 1997/04/30 05:41:19 paulus Exp $ */ /* - * ==FILEVERSION 960926== + * ==FILEVERSION 970421== * * This marker is used by the Linux installation script to determine * whether an up-to-date version of this file is already installed. @@ -144,6 +144,8 @@ typedef uLong (*check_func) OF((uLong check, Bytef *buf, uInt len)); #define ZALLOC(strm, items, size) \ (*((strm)->zalloc))((strm)->opaque, (items), (size)) +#define ZALLOC_INIT(strm, items, size) \ + (*((strm)->zalloc_init))((strm)->opaque, (items), (size)) #define ZFREE(strm, addr, size) \ (*((strm)->zfree))((strm)->opaque, (voidpf)(addr), (size)) #define TRY_FREE(s, p, n) {if (p) ZFREE(s, p, n);} @@ -167,7 +169,7 @@ typedef uLong (*check_func) OF((uLong check, Bytef *buf, uInt len)); */ /* Data type */ -#define BINARY 0 +#define Z_BINARY 0 #define ASCII 1 #define UNKNOWN 2 @@ -240,7 +242,7 @@ typedef struct deflate_state { int pending; /* nb of bytes in the pending buffer */ uLong adler; /* adler32 of uncompressed data */ int noheader; /* suppress zlib header and adler32 */ - Byte data_type; /* UNKNOWN, BINARY or ASCII */ + Byte data_type; /* UNKNOWN, Z_BINARY or ASCII */ Byte method; /* STORED (for zip only) or DEFLATED */ int minCompr; /* min size decrease for Z_FLUSH_NOSTORE */ @@ -634,7 +636,7 @@ int deflateInit2 (strm, level, method, windowBits, memLevel, windowBits < 8 || windowBits > 15 || level < 1 || level > 9) { return Z_STREAM_ERROR; } - s = (deflate_state *) ZALLOC(strm, 1, sizeof(deflate_state)); + s = (deflate_state *) ZALLOC_INIT(strm, 1, sizeof(deflate_state)); if (s == Z_NULL) return Z_MEM_ERROR; strm->state = (struct internal_state FAR *)s; s->strm = strm; @@ -649,13 +651,13 @@ int deflateInit2 (strm, level, method, windowBits, memLevel, s->hash_mask = s->hash_size - 1; s->hash_shift = ((s->hash_bits+MIN_MATCH-1)/MIN_MATCH); - s->window = (Bytef *) ZALLOC(strm, s->w_size, 2*sizeof(Byte)); - s->prev = (Posf *) ZALLOC(strm, s->w_size, sizeof(Pos)); - s->head = (Posf *) ZALLOC(strm, s->hash_size, sizeof(Pos)); + s->window = (Bytef *) ZALLOC_INIT(strm, s->w_size, 2*sizeof(Byte)); + s->prev = (Posf *) ZALLOC_INIT(strm, s->w_size, sizeof(Pos)); + s->head = (Posf *) ZALLOC_INIT(strm, s->hash_size, sizeof(Pos)); s->lit_bufsize = 1 << (memLevel + 6); /* 16K elements by default */ - s->pending_buf = (uchf *) ZALLOC(strm, s->lit_bufsize, 2*sizeof(ush)); + s->pending_buf = (uchf *) ZALLOC_INIT(strm, s->lit_bufsize, 2*sizeof(ush)); if (s->window == Z_NULL || s->prev == Z_NULL || s->head == Z_NULL || s->pending_buf == Z_NULL) { @@ -686,7 +688,8 @@ int deflateReset (strm) deflate_state *s; if (strm == Z_NULL || strm->state == Z_NULL || - strm->zalloc == Z_NULL || strm->zfree == Z_NULL) return Z_STREAM_ERROR; + strm->zalloc == Z_NULL || strm->zfree == Z_NULL || + strm->zalloc_init == Z_NULL) return Z_STREAM_ERROR; strm->total_in = strm->total_out = 0; strm->msg = Z_NULL; /* use zfree if we ever allocate msg dynamically */ @@ -2515,7 +2518,7 @@ local void compress_block(s, ltree, dtree) } /* =========================================================================== - * Set the data type to ASCII or BINARY, using a crude approximation: + * Set the data type to ASCII or Z_BINARY, using a crude approximation: * binary if more than 20% of the bytes are <= 6 or >= 128, ascii otherwise. * IN assertion: the fields freq of dyn_ltree are set and the total of all * frequencies does not exceed 64K (to fit in an int on 16 bit machines). @@ -2529,7 +2532,7 @@ local void set_data_type(s) while (n < 7) bin_freq += s->dyn_ltree[n++].Freq; while (n < 128) ascii_freq += s->dyn_ltree[n++].Freq; while (n < LITERALS) bin_freq += s->dyn_ltree[n++].Freq; - s->data_type = (Byte)(bin_freq > (ascii_freq >> 2) ? BINARY : ASCII); + s->data_type = (Byte)(bin_freq > (ascii_freq >> 2) ? Z_BINARY : ASCII); } /* =========================================================================== @@ -2828,7 +2831,7 @@ int w; /* if (z->zalloc == Z_NULL) z->zalloc = zcalloc; */ /* if (z->zfree == Z_NULL) z->zfree = zcfree; */ if ((z->state = (struct internal_state FAR *) - ZALLOC(z,1,sizeof(struct internal_state))) == Z_NULL) + ZALLOC_INIT(z,1,sizeof(struct internal_state))) == Z_NULL) return Z_MEM_ERROR; z->state->blocks = Z_NULL; @@ -3256,10 +3259,10 @@ uInt w; { inflate_blocks_statef *s; - if ((s = (inflate_blocks_statef *)ZALLOC + if ((s = (inflate_blocks_statef *)ZALLOC_INIT (z,1,sizeof(struct inflate_blocks_state))) == Z_NULL) return s; - if ((s->window = (Bytef *)ZALLOC(z, 1, w)) == Z_NULL) + if ((s->window = (Bytef *)ZALLOC_INIT(z, 1, w)) == Z_NULL) { ZFREE(z, s, sizeof(struct inflate_blocks_state)); return Z_NULL; diff --git a/common/zlib.h b/common/zlib.h index 36cb515..01d1a5d 100644 --- a/common/zlib.h +++ b/common/zlib.h @@ -1,4 +1,4 @@ -/* $Id: zlib.h,v 1.4 1997/03/04 03:26:36 paulus Exp $ */ +/* $Id: zlib.h,v 1.5 1997/04/30 05:41:20 paulus Exp $ */ /* * This file is derived from zlib.h and zconf.h from the zlib-0.95 @@ -8,7 +8,7 @@ */ /* - * ==FILEVERSION 960122== + * ==FILEVERSION 970421== * * This marker is used by the Linux installation script to determine * whether an up-to-date version of this file is already installed. @@ -176,6 +176,7 @@ typedef struct z_stream_s { struct internal_state FAR *state; /* not visible by applications */ alloc_func zalloc; /* used to allocate the internal state */ + alloc_func zalloc_init; /* used to allocate the internal state during initialization */ free_func zfree; /* used to free the internal state */ voidp opaque; /* private data object passed to zalloc and zfree */