I have mixed feelings about this patch ...
Building rpm --without-zlib (and --without-db and --without-sqlite
and ...) leads
only to a useless /usr/bin/rpm imho.
But its easier to do the mechnical compile engineering than it is to
try and describe why building rpm without -lz and -ldb is unlikely to
be useful.
73 de Jeff
On Sep 28, 2008, at 5:50 PM, Jeff Johnson wrote:
> RPM Package Manager, CVS Repository
> http://rpm5.org/cvs/
>
> ______________________________________________________________________
> ______
>
> Server: rpm5.org Name: Jeff Johnson
> Root: /v/rpm/cvs Email: jbj@rpm5.org
> Module: rpm Date: 28-Sep-2008
> 23:50:28
> Branch: HEAD Handle: 2008092821502700
>
> Added files:
> rpm/rpmio adler32.c
> Modified files:
> rpm CHANGES
> rpm/rpmio Makefile.am digest.c gzdio.c rpmio.c
>
> Log:
> - jbj: rpmio: permit adler32/crc32/crc64 in spite of --without-
> zlib.
> - jbj: rpmio: eliminate HAVE_ZLIB_H tests, use WITH_ZLIB tests
> instead.
>
> Summary:
> Revision Changes Path
> 1.2578 +2 -0 rpm/CHANGES
> 1.194 +1 -1 rpm/rpmio/Makefile.am
> 2.1 +140 -0 rpm/rpmio/adler32.c
> 2.41 +113 -25 rpm/rpmio/digest.c
> 2.13 +2 -2 rpm/rpmio/gzdio.c
> 1.148 +7 -7 rpm/rpmio/rpmio.c
>
> ______________________________________________________________________
> ______
>
> patch -p0 <<'@@ .'
> Index: rpm/CHANGES
>
> ======================================================================
> ======
> $ cvs diff -u -r1.2577 -r1.2578 CHANGES
> --- rpm/CHANGES 27 Sep 2008 13:00:13 -0000 1.2577
> +++ rpm/CHANGES 28 Sep 2008 21:50:27 -0000 1.2578
> @@ -1,5 +1,7 @@
>
> 5.1.0 -> 5.2a0:
> + - jbj: rpmio: permit adler32/crc32/crc64 in spite of --
> without-zlib.
> + - jbj: rpmio: eliminate HAVE_ZLIB_H tests, use WITH_ZLIB
> tests instead.
> - rse: rpmio: allow newer fnmatch to build on non-Linux
> platforms, too.
> - jbj: rpmio: upgrade fnmatch to version that implements
> FNM_EXTMATCH.
> - jbj: rpmpsm: simplify runTriggers() by adding
> rpmTriggersLoop().
> @@ .
> patch -p0 <<'@@ .'
> Index: rpm/rpmio/Makefile.am
>
> ======================================================================
> ======
> $ cvs diff -u -r1.193 -r1.194 Makefile.am
> --- rpm/rpmio/Makefile.am 25 Sep 2008 19:39:28 -0000 1.193
> +++ rpm/rpmio/Makefile.am 28 Sep 2008 21:50:27 -0000 1.194
> @@ -7,7 +7,7 @@
> SUBDIRS = # tests
>
> EXTRA_DIST = \
> - fnmatch_loop.c getdate.y rpmcpio.c rpmcpio.h \
> + adler32.c fnmatch_loop.c getdate.y rpmcpio.c rpmcpio.h \
> rpmgenbasedir.c rpmgenpkglist.c rpmgensrclist.c \
> rpmtar.c rpmtar.h \
> tdir.c tfts.c tget.c tglob.c thkp.c thtml.c tinv.c tkey.c
> tmire.c \
> @@ .
> patch -p0 <<'@@ .'
> Index: rpm/rpmio/adler32.c
>
> ======================================================================
> ======
> $ cvs diff -u -r0 -r2.1 adler32.c
> --- /dev/null 2008-09-28 23:45:21 +0200
> +++ adler32.c 2008-09-28 23:50:28 +0200
> @@ -0,0 +1,140 @@
> +/* adler32.c -- compute the Adler-32 checksum of a data stream
> + * Copyright (C) 1995-2004 Mark Adler
> + * For conditions of distribution and use, see copyright notice
> in zlib.h
> + */
> +
> +#define BASE 65521UL /* largest prime smaller than 65536 */
> +#define NMAX 5552
> +/* NMAX is the largest n such that 255n(n+1)/2 + (n+1)(BASE-1)
> <= 2^32-1 */
> +
> +#define DO1(buf,i) {adler += (buf)[i]; sum2 += adler;}
> +#define DO2(buf,i) DO1(buf,i); DO1(buf,i+1);
> +#define DO4(buf,i) DO2(buf,i); DO2(buf,i+2);
> +#define DO8(buf,i) DO4(buf,i); DO4(buf,i+4);
> +#define DO16(buf) DO8(buf,0); DO8(buf,8);
> +
> +/* use NO_DIVIDE if your processor does not do division in
> hardware */
> +#ifdef NO_DIVIDE
> +# define MOD(a) \
> + do { \
> + if (a >= (BASE << 16)) a -= (BASE << 16); \
> + if (a >= (BASE << 15)) a -= (BASE << 15); \
> + if (a >= (BASE << 14)) a -= (BASE << 14); \
> + if (a >= (BASE << 13)) a -= (BASE << 13); \
> + if (a >= (BASE << 12)) a -= (BASE << 12); \
> + if (a >= (BASE << 11)) a -= (BASE << 11); \
> + if (a >= (BASE << 10)) a -= (BASE << 10); \
> + if (a >= (BASE << 9)) a -= (BASE << 9); \
> + if (a >= (BASE << 8)) a -= (BASE << 8); \
> + if (a >= (BASE << 7)) a -= (BASE << 7); \
> + if (a >= (BASE << 6)) a -= (BASE << 6); \
> + if (a >= (BASE << 5)) a -= (BASE << 5); \
> + if (a >= (BASE << 4)) a -= (BASE << 4); \
> + if (a >= (BASE << 3)) a -= (BASE << 3); \
> + if (a >= (BASE << 2)) a -= (BASE << 2); \
> + if (a >= (BASE << 1)) a -= (BASE << 1); \
> + if (a >= BASE) a -= BASE; \
> + } while (0)
> +# define MOD4(a) \
> + do { \
> + if (a >= (BASE << 4)) a -= (BASE << 4); \
> + if (a >= (BASE << 3)) a -= (BASE << 3); \
> + if (a >= (BASE << 2)) a -= (BASE << 2); \
> + if (a >= (BASE << 1)) a -= (BASE << 1); \
> + if (a >= BASE) a -= BASE; \
> + } while (0)
> +#else
> +# define MOD(a) a %= BASE
> +# define MOD4(a) a %= BASE
> +#endif
> +
> +/*
> ======================================================================
> === */
> +static
> +rpmuint32_t adler32(rpmuint32_t adler, const rpmuint8_t * buf,
> rpmuint32_t len)
> +{
> + rpmuint32_t sum2;
> + unsigned n;
> +
> + /* split Adler-32 into component sums */
> + sum2 = (adler >> 16) & 0xffff;
> + adler &= 0xffff;
> +
> + /* in case user likes doing a byte at a time, keep it fast */
> + if (len == 1) {
> + adler += buf[0];
> + if (adler >= BASE)
> + adler -= BASE;
> + sum2 += adler;
> + if (sum2 >= BASE)
> + sum2 -= BASE;
> + return adler | (sum2 << 16);
> + }
> +
> + /* initial Adler-32 value (deferred check for len == 1
> speed) */
> + if (buf == NULL)
> + return 1UL;
> +
> + /* in case short lengths are provided, keep it somewhat fast */
> + if (len < 16) {
> + while (len--) {
> + adler += *buf++;
> + sum2 += adler;
> + }
> + if (adler >= BASE)
> + adler -= BASE;
> + MOD4(sum2); /* only added so many BASE's */
> + return adler | (sum2 << 16);
> + }
> +
> + /* do length NMAX blocks -- requires just one modulo
> operation */
> + while (len >= NMAX) {
> + len -= NMAX;
> + n = NMAX / 16; /* NMAX is divisible by 16 */
> + do {
> + DO16(buf); /* 16 sums unrolled */
> + buf += 16;
> + } while (--n);
> + MOD(adler);
> + MOD(sum2);
> + }
> +
> + /* do remaining bytes (less than NMAX, still just one
> modulo) */
> + if (len) { /* avoid modulos if none
> remaining */
> + while (len >= 16) {
> + len -= 16;
> + DO16(buf);
> + buf += 16;
> + }
> + while (len--) {
> + adler += *buf++;
> + sum2 += adler;
> + }
> + MOD(adler);
> + MOD(sum2);
> + }
> +
> + /* return recombined sums */
> + return adler | (sum2 << 16);
> +}
> +
> +/*
> ======================================================================
> === */
> +static
> +rpmuint32_t adler32_combine(rpmuint32_t adler1, rpmuint32_t
> adler2, size_t len2)
> +{
> + rpmuint32_t sum1;
> + rpmuint32_t sum2;
> + unsigned rem;
> +
> + /* the derivation of this formula is left as an exercise for
> the reader */
> + rem = (unsigned)(len2 % BASE);
> + sum1 = adler1 & 0xffff;
> + sum2 = rem * sum1;
> + MOD(sum2);
> + sum1 += (adler2 & 0xffff) + BASE - 1;
> + sum2 += ((adler1 >> 16) & 0xffff) + ((adler2 >> 16) &
> 0xffff) + BASE - rem;
> + if (sum1 > BASE) sum1 -= BASE;
> + if (sum1 > BASE) sum1 -= BASE;
> + if (sum2 > (BASE << 1)) sum2 -= (BASE << 1);
> + if (sum2 > BASE) sum2 -= BASE;
> + return sum1 | (sum2 << 16);
> +}
> @@ .
> patch -p0 <<'@@ .'
> Index: rpm/rpmio/digest.c
>
> ======================================================================
> ======
> $ cvs diff -u -r2.40 -r2.41 digest.c
> --- rpm/rpmio/digest.c 19 Aug 2008 15:02:59 -0000 2.40
> +++ rpm/rpmio/digest.c 28 Sep 2008 21:50:27 -0000 2.41
> @@ -4,7 +4,9 @@
>
> #include "system.h"
>
> +#if defined(WITH_ZLIB)
> #include <zlib.h>
> +#endif
>
> #include "rpmio_internal.h"
>
> @@ -29,7 +31,11 @@
> #define DPRINTF(_a)
> #endif
>
> -#if !defined(ZLIB_H) || defined(__LCLINT__)
> +#if !defined(WITH_ZLIB) || defined(__LCLINT__)
> +
> +/* XXX Make sure that --adler32 is in rpmio even if --without-
> zlib is used. */
> +#include "adler32.c"
> +
> /**
> */
> /*@-shadow@*/
> @@ -69,7 +75,97 @@
>
> }
> /*@=shadow@*/
> -#endif
> +
> +/*
> + * Swiped from zlib, using rpmuint32_t rather than unsigned long
> computation.
> + */
> +static int gf2_dim32 = 32;
> +
> +/**
> + */
> +static rpmuint32_t gf2_matrix_times32(rpmuint32_t *mat,
> rpmuint32_t vec)
> + /*@*/
> +{
> + rpmuint32_t sum;
> +
> + sum = 0;
> + while (vec) {
> + if (vec & 1)
> + sum ^= *mat;
> + vec >>= 1;
> + mat++;
> + }
> + return sum;
> +}
> +
> +/**
> + */
> +static void gf2_matrix_square32(/*@out@*/ rpmuint32_t *square,
> rpmuint32_t *mat)
> + /*@modifies square @*/
> +{
> + int n;
> +
> + for (n = 0; n < gf2_dim32; n++)
> + square[n] = gf2_matrix_times32(mat, mat[n]);
> +}
> +
> +/**
> + */
> +static rpmuint32_t crc32_combine(rpmuint32_t crc1, rpmuint32_t
> crc2, size_t len2)
> + /*@*/
> +{
> + int n;
> + rpmuint32_t row;
> + size_t nb = gf2_dim32 * sizeof(rpmuint32_t);
> + rpmuint32_t * even = alloca(nb); /* even-power-of-two zeros
> operator */
> + rpmuint32_t * odd = alloca(nb); /* odd-power-of-two zeros
> operator */
> +
> + /* degenerate case */
> + if (len2 == 0)
> + return crc1;
> +
> + /* put operator for one zero bit in odd */
> + odd[0] = 0xedb88320UL; /* CRC-32 polynomial */
> + row = 1;
> + for (n = 1; n < gf2_dim32; n++) {
> + odd[n] = row;
> + row <<= 1;
> + }
> +
> + /* put operator for two zero bits in even */
> + gf2_matrix_square32(even, odd);
> +
> + /* put operator for four zero bits in odd */
> + gf2_matrix_square32(odd, even);
> +
> + /* apply len2 zeros to crc1 (first square will put the
> operator for one
> + zero byte, eight zero bits, in even) */
> + do {
> + /* apply zeros operator for this bit of len2 */
> + gf2_matrix_square32(even, odd);
> + if (len2 & 1)
> + crc1 = gf2_matrix_times32(even, crc1);
> + len2 >>= 1;
> +
> + /* if no more bits set, then done */
> + if (len2 == 0)
> + break;
> +
> + /* another iteration of the loop with odd and even
> swapped */
> + gf2_matrix_square32(odd, even);
> + if (len2 & 1)
> + crc1 = gf2_matrix_times32(odd, crc1);
> + len2 >>= 1;
> +
> + /* if no more bits set, then done */
> + } while (len2 != 0);
> +
> + /* return combined crc */
> + crc1 ^= crc2;
> + return crc1;
> +}
> +
> +#endif /* !defined(WITH_ZLIB) */
>
> /* Include Bob Jenkins lookup3 hash */
> #define _JLU3_jlu32l
> @@ -165,13 +261,12 @@
>
> /*
> * Swiped from zlib, using rpmuint64_t rather than unsigned long
> computation.
> - * Use at your own risk, rpmuint64_t problems with compilers may
> exist.
> */
> -#define GF2_DIM 64
> +static int gf2_dim64 = 64;
>
> /**
> */
> -static rpmuint64_t gf2_matrix_times(rpmuint64_t *mat,
> rpmuint64_t vec)
> +static rpmuint64_t gf2_matrix_times64(rpmuint64_t *mat,
> rpmuint64_t vec)
> /*@*/
> {
> rpmuint64_t sum;
> @@ -188,13 +283,13 @@
>
> /**
> */
> -static void gf2_matrix_square(/*@out@*/ rpmuint64_t *square,
> rpmuint64_t *mat)
> +static void gf2_matrix_square64(/*@out@*/ rpmuint64_t *square,
> rpmuint64_t *mat)
> /*@modifies square @*/
> {
> int n;
>
> - for (n = 0; n < GF2_DIM; n++)
> - square[n] = gf2_matrix_times(mat, mat[n]);
> + for (n = 0; n < gf2_dim64; n++)
> + square[n] = gf2_matrix_times64(mat, mat[n]);
> }
>
> /**
> @@ -204,8 +299,9 @@
> {
> int n;
> rpmuint64_t row;
> - rpmuint64_t even[GF2_DIM]; /* even-power-of-two zeros
> operator */
> - rpmuint64_t odd[GF2_DIM]; /* odd-power-of-two zeros
> operator */
> + size_t nb = gf2_dim64 * sizeof(rpmuint64_t);
> + rpmuint64_t * even = alloca(nb); /* even-power-of-two zeros
> operator */
> + rpmuint64_t * odd = alloca(nb); /* odd-power-of-two zeros
> operator */
>
> /* degenerate case */
> if (len2 == 0)
> @@ -214,24 +310,24 @@
> /* put operator for one zero bit in odd */
> odd[0] = 0xc96c5795d7870f42ULL; /* reflected
> 0x42f0e1eba9ea3693ULL */
> row = 1;
> - for (n = 1; n < GF2_DIM; n++) {
> + for (n = 1; n < gf2_dim64; n++) {
> odd[n] = row;
> row <<= 1;
> }
>
> /* put operator for two zero bits in even */
> - gf2_matrix_square(even, odd);
> + gf2_matrix_square64(even, odd);
>
> /* put operator for four zero bits in odd */
> - gf2_matrix_square(odd, even);
> + gf2_matrix_square64(odd, even);
>
> /* apply len2 zeros to crc1 (first square will put the
> operator for one
> zero byte, eight zero bits, in even) */
> do {
> /* apply zeros operator for this bit of len2 */
> - gf2_matrix_square(even, odd);
> + gf2_matrix_square64(even, odd);
> if (len2 & 1)
> - crc1 = gf2_matrix_times(even, crc1);
> + crc1 = gf2_matrix_times64(even, crc1);
> len2 >>= 1;
>
> /* if no more bits set, then done */
> @@ -239,9 +335,9 @@
> break;
>
> /* another iteration of the loop with odd and even
> swapped */
> - gf2_matrix_square(odd, even);
> + gf2_matrix_square64(odd, even);
> if (len2 & 1)
> - crc1 = gf2_matrix_times(odd, crc1);
> + crc1 = gf2_matrix_times64(odd, crc1);
> len2 >>= 1;
>
> /* if no more bits set, then done */
> @@ -501,11 +597,7 @@
> { sum32Param * mp = xcalloc(1, sizeof(*mp));
> /*@-type @*/
> mp->update = (rpmuint32_t (*)(rpmuint32_t, const byte *,
> size_t)) crc32;
> -#if defined(ZLIB_H)
> -#if defined(HAVE_ZLIB_CRC32_COMBINE)
> mp->combine = (rpmuint32_t (*)(rpmuint32_t, rpmuint32_t,
> size_t)) crc32_combine;
> -#endif
> -#endif
> /*@=type @*/
> ctx->paramsize = sizeof(*mp);
> ctx->param = mp;
> @@ -522,12 +614,8 @@
> ctx->datasize = 8;
> { sum32Param * mp = xcalloc(1, sizeof(*mp));
> /*@-type @*/
> -#if defined(ZLIB_H)
> mp->update = (rpmuint32_t (*)(rpmuint32_t, const byte *,
> size_t)) adler32;
> -#if defined(HAVE_ZLIB_ADLER32_COMBINE)
> mp->combine = (rpmuint32_t (*)(rpmuint32_t, rpmuint32_t,
> size_t)) adler32_combine;
> -#endif
> -#endif
> /*@=type @*/
> ctx->paramsize = sizeof(*mp);
> ctx->param = mp;
> @@ .
> patch -p0 <<'@@ .'
> Index: rpm/rpmio/gzdio.c
>
> ======================================================================
> ======
> $ cvs diff -u -r2.12 -r2.13 gzdio.c
> --- rpm/rpmio/gzdio.c 6 Aug 2008 06:20:21 -0000 2.12
> +++ rpm/rpmio/gzdio.c 28 Sep 2008 21:50:27 -0000 2.13
> @@ -15,7 +15,7 @@
> #include <rpmmacro.h>
> #include <rpmcb.h>
>
> -#ifdef HAVE_ZLIB_H
> +#if defined(WITH_ZLIB)
>
> /*@-noparams@*/
> #include <zlib.h>
> @@ -458,4 +458,4 @@
> FDIO_t gzdio = /*@-compmempass@*/ &gzdio_s /*@=compmempass@*/ ;
>
> /*@=moduncon@*/
> -#endif /* HAVE_ZLIB_H */
> +#endif /* WITH_ZLIB */
> @@ .
> patch -p0 <<'@@ .'
> Index: rpm/rpmio/rpmio.c
>
> ======================================================================
> ======
> $ cvs diff -u -r1.147 -r1.148 rpmio.c
> --- rpm/rpmio/rpmio.c 3 Aug 2008 19:59:09 -0000 1.147
> +++ rpm/rpmio/rpmio.c 28 Sep 2008 21:50:27 -0000 1.148
> @@ -203,7 +203,7 @@
> sprintf(be, "FD %d fp %p", fps->fdno, fps->fp);
> } else if (fps->io == ufdio) {
> sprintf(be, "UFD %d fp %p", fps->fdno, fps->fp);
> -#ifdef HAVE_ZLIB_H
> +#if defined(WITH_ZLIB)
> } else if (fps->io == gzdio) {
> sprintf(be, "GZD %p fdno %d", fps->fp, fps->fdno);
> #endif
> @@ -2325,11 +2325,11 @@
> {
> const char *errstr = NULL;
>
> -#ifdef HAVE_ZLIB_H
> +#if defined(WITH_ZLIB)
> if (fdGetIo(fd) == gzdio) {
> errstr = fd->errcookie;
> } else
> -#endif /* HAVE_ZLIB_H */
> +#endif /* WITH_ZLIB */
>
> #ifdef HAVE_BZLIB_H
> if (fdGetIo(fd) == bzdio) {
> @@ -2648,7 +2648,7 @@
> if (end && *end) {
> if (!strcmp(end, "fdio")) {
> iof = fdio;
> -#if defined(HAVE_ZLIB_H)
> +#if defined(WITH_ZLIB)
> } else if (!strcmp(end, "gzdio")) {
> iof = gzdio;
> /*@-internalglobs@*/
> @@ -2692,7 +2692,7 @@
> for (end = other; *end && strchr("0123456789fh", *end); end++)
> {};
> if (*end == '\0') {
> -#if defined(HAVE_ZLIB_H)
> +#if defined(WITH_ZLIB)
> iof = gzdio;
> /*@-internalglobs@*/
> fd = iof->_fdopen(fd, zstdio);
> @@ -2825,7 +2825,7 @@
> /*@=voidabstract =nullpass@*/
>
> vh = fdGetFp(fd);
> -#if defined(HAVE_ZLIB_H)
> +#if defined(WITH_ZLIB)
> if (vh && fdGetIo(fd) == gzdio && gzdio->_flush != NULL)
> return (*gzdio->_flush) ((void *)fd);
> #endif
> @@ -2858,7 +2858,7 @@
> /*@+voidabstract -nullpass@*/
> ec = ferror(fdGetFILE(fd));
> /*@=voidabstract =nullpass@*/
> -#if defined(HAVE_ZLIB_H)
> +#if defined(WITH_ZLIB)
> } else if (fps->io == gzdio) {
> ec = (fd->syserrno || fd->errcookie != NULL) ? -1 : 0;
> i--; /* XXX fdio under gzdio always has fdno == -1 */
> @@ .
> ______________________________________________________________________
> RPM Package Manager http://rpm5.org
> CVS Sources Repository rpm-cvs@rpm5.org
Received on Sun Sep 28 23:58:08 2008