Skip to content

Commit

Permalink
Kill z_crc_t
Browse files Browse the repository at this point in the history
Signed-off-by: Daniel Axtens <[email protected]>

Conflicts:
	crc32.c
  • Loading branch information
daxtens authored and Dead2 committed May 13, 2015
1 parent 08cef61 commit 4db4cfd
Show file tree
Hide file tree
Showing 5 changed files with 20 additions and 38 deletions.
1 change: 0 additions & 1 deletion configure
Original file line number Diff line number Diff line change
Expand Up @@ -741,7 +741,6 @@ echo BUILDDIR = $BUILDDIR >> configure.log
echo STATICLIB = $STATICLIB >> configure.log
echo TEST = $TEST >> configure.log
echo VER = $VER >> configure.log
echo Z_U4 = $Z_U4 >> configure.log
echo exec_prefix = $exec_prefix >> configure.log
echo includedir = $includedir >> configure.log
echo libdir = $libdir >> configure.log
Expand Down
36 changes: 18 additions & 18 deletions crc32.c
Original file line number Diff line number Diff line change
Expand Up @@ -59,10 +59,10 @@ static uint32_t crc32_combine_ (uint32_t crc1, uint32_t crc2, z_off64_t len2);
#ifdef DYNAMIC_CRC_TABLE

static volatile int crc_table_empty = 1;
static z_crc_t crc_table[8][256];
static uint32_t crc_table[8][256];
static void make_crc_table (void);
#ifdef MAKECRCH
static void write_table (FILE *, const z_crc_t *);
static void write_table (FILE *, const uint32_t *);
#endif /* MAKECRCH */
/*
Generate tables for a byte-wise 32-bit CRC calculation on the polynomial:
Expand Down Expand Up @@ -92,9 +92,9 @@ static void make_crc_table (void);
*/
static void make_crc_table()
{
z_crc_t c;
uint32_t c;
int n, k;
z_crc_t poly; /* polynomial exclusive-or pattern */
uint32_t poly; /* polynomial exclusive-or pattern */
/* terms of polynomial defining this crc (except x^32): */
static volatile int first = 1; /* flag to limit concurrent making */
static const unsigned char p[] = {0,1,2,4,5,7,8,10,11,12,16,22,23,26};
Expand All @@ -108,11 +108,11 @@ static void make_crc_table()
/* make exclusive-or pattern from polynomial (0xedb88320) */
poly = 0;
for (n = 0; n < (int)(sizeof(p)/sizeof(unsigned char)); n++)
poly |= (z_crc_t)1 << (31 - p[n]);
poly |= (uint32_t)1 << (31 - p[n]);

/* generate a crc for every 8-bit value */
for (n = 0; n < 256; n++) {
c = (z_crc_t)n;
c = (uint32_t)n;
for (k = 0; k < 8; k++)
c = c & 1 ? poly ^ (c >> 1) : c >> 1;
crc_table[0][n] = c;
Expand Down Expand Up @@ -147,7 +147,7 @@ static void make_crc_table()
if (out == NULL) return;
fprintf(out, "/* crc32.h -- tables for rapid CRC calculation\n");
fprintf(out, " * Generated automatically by crc32.c\n */\n\n");
fprintf(out, "static const z_crc_t ");
fprintf(out, "static const uint32_t ");
fprintf(out, "crc_table[8][256] =\n{\n {\n");
write_table(out, crc_table[0]);
for (k = 1; k < 8; k++) {
Expand All @@ -161,7 +161,7 @@ static void make_crc_table()
}

#ifdef MAKECRCH
static void write_table(FILE *out, const z_crc_t *table)
static void write_table(FILE *out, const uint32_t *table)
{
int n;

Expand All @@ -182,13 +182,13 @@ static void write_table(FILE *out, const z_crc_t *table)
/* =========================================================================
* This function can be used by asm versions of crc32()
*/
const z_crc_t * ZEXPORT get_crc_table()
const uint32_t * ZEXPORT get_crc_table()
{
#ifdef DYNAMIC_CRC_TABLE
if (crc_table_empty)
make_crc_table();
#endif /* DYNAMIC_CRC_TABLE */
return (const z_crc_t *)crc_table;
return (const uint32_t *)crc_table;
}

/* ========================================================================= */
Expand Down Expand Up @@ -244,17 +244,17 @@ uint32_t ZEXPORT crc32(uint32_t crc, const unsigned char *buf, uInt len)
/* ========================================================================= */
static uint32_t crc32_little(uint32_t crc, const unsigned char *buf, unsigned len)
{
register z_crc_t c;
register const z_crc_t *buf4;
register uint32_t c;
register const uint32_t *buf4;

c = (z_crc_t)crc;
c = (uint32_t)crc;
c = ~c;
while (len && ((ptrdiff_t)buf & 3)) {
c = crc_table[0][(c ^ *buf++) & 0xff] ^ (c >> 8);
len--;
}

buf4 = (const z_crc_t *)(const void *)buf;
buf4 = (const uint32_t *)(const void *)buf;

#ifndef UNROLL_LESS
while (len >= 32) {
Expand Down Expand Up @@ -287,17 +287,17 @@ static uint32_t crc32_little(uint32_t crc, const unsigned char *buf, unsigned le
/* ========================================================================= */
static uint32_t crc32_big(uint32_t crc, const unsigned char *buf, unsigned len)
{
register z_crc_t c;
register const z_crc_t *buf4;
register uint32_t c;
register const uint32_t *buf4;

c = ZSWAP32((z_crc_t)crc);
c = ZSWAP32((uint32_t)crc);
c = ~c;
while (len && ((ptrdiff_t)buf & 3)) {
c = crc_table[4][(c >> 24) ^ *buf++] ^ (c << 8);
len--;
}

buf4 = (const z_crc_t *)(const void *)buf;
buf4 = (const uint32_t *)(const void *)buf;
buf4--;

#ifndef UNROLL_LESS
Expand Down
2 changes: 1 addition & 1 deletion crc32.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
* Generated automatically by crc32.c
*/

static const z_crc_t crc_table[8][256] =
static const uint32_t crc_table[8][256] =
{
{
0x00000000, 0x77073096, 0xee0e612c, 0x990951ba, 0x076dc419,
Expand Down
17 changes: 0 additions & 17 deletions zconf.h.in
Original file line number Diff line number Diff line change
Expand Up @@ -107,23 +107,6 @@ typedef void const *voidpc;
typedef void *voidpf;
typedef void *voidp;

#if !defined(Z_U4)
# include <limits.h>
# if (UINT_MAX == 0xffffffffUL)
# define Z_U4 unsigned
# elif (ULONG_MAX == 0xffffffffUL)
# define Z_U4 unsigned long
# elif (USHRT_MAX == 0xffffffffUL)
# define Z_U4 unsigned short
# endif
#endif

#ifdef Z_U4
typedef Z_U4 z_crc_t;
#else
typedef unsigned long z_crc_t;
#endif

#ifdef HAVE_UNISTD_H /* may be set to #if 1 by ./configure */
# define Z_HAVE_UNISTD_H
#endif
Expand Down
2 changes: 1 addition & 1 deletion zlib.h
Original file line number Diff line number Diff line change
Expand Up @@ -1727,7 +1727,7 @@ ZEXTERN int ZEXPORT gzgetc_ (gzFile file); /* backward compatibility */
/* undocumented functions */
ZEXTERN const char * ZEXPORT zError (int);
ZEXTERN int ZEXPORT inflateSyncPoint (z_stream *);
ZEXTERN const z_crc_t * ZEXPORT get_crc_table (void);
ZEXTERN const uint32_t * ZEXPORT get_crc_table (void);
ZEXTERN int ZEXPORT inflateUndermine (z_stream *, int);
ZEXTERN int ZEXPORT inflateResetKeep (z_stream *);
ZEXTERN int ZEXPORT deflateResetKeep (z_stream *);
Expand Down

0 comments on commit 4db4cfd

Please sign in to comment.