From eaf56593d039ea4f4e91c133ec82a4c2f63f8a5b Mon Sep 17 00:00:00 2001 From: Przemyslaw Czerpak Date: Mon, 13 Sep 2010 09:40:53 +0000 Subject: [PATCH] 2010-09-13 11:40 UTC+0200 Przemyslaw Czerpak (druzus/at/priv.onet.pl) * harbour/src/rtl/hbzlib.c + added new PRG function: HB_GZCOMPRESSBOUND( | ) -> ! fixed compilation with ZLIB versions earlier then 1.2.0 broken by missing deflateBound() function which I used recently. --- harbour/ChangeLog | 7 +++++++ harbour/src/rtl/hbzlib.c | 38 ++++++++++++++++++++++---------------- 2 files changed, 29 insertions(+), 16 deletions(-) diff --git a/harbour/ChangeLog b/harbour/ChangeLog index aeee5d05fd..702a0facf2 100644 --- a/harbour/ChangeLog +++ b/harbour/ChangeLog @@ -16,6 +16,13 @@ The license applies to all entries newer than 2009-04-28. */ +2010-09-13 11:40 UTC+0200 Przemyslaw Czerpak (druzus/at/priv.onet.pl) + * harbour/src/rtl/hbzlib.c + + added new PRG function: + HB_GZCOMPRESSBOUND( | ) -> + ! fixed compilation with ZLIB versions earlier then 1.2.0 broken by + missing deflateBound() function which I used recently. + 2010-09-13 09:59 UTC+0200 Przemyslaw Czerpak (druzus/at/priv.onet.pl) * harbour/src/rtl/hbzlib.c ! added our own version of compressBound() function for diff --git a/harbour/src/rtl/hbzlib.c b/harbour/src/rtl/hbzlib.c index b8fe48696a..8160fe5fcf 100644 --- a/harbour/src/rtl/hbzlib.c +++ b/harbour/src/rtl/hbzlib.c @@ -57,8 +57,10 @@ #include /* Try to figure if we have this function. Z_RLE was introduced in 1.2.0.1, - while compressBound() was added in 1.2.0. This means we have to miss - compressBound() when using zlib 1.2.0. [vszakats] */ + while compressBound() and deflateBound() were added in 1.2.0. This means + we have to miss compressBound() when using zlib 1.2.0. [vszakats] */ +/* ZLIB_VERNUM were added in version 1.2.0.2 so it cannot be used for older + zlib libraries */ #if defined( Z_RLE ) #define _HB_Z_COMPRESSBOUND #endif @@ -68,6 +70,9 @@ static uLong hb_zlibCompressBound( uLong ulLen ) { return ulLen + ( ulLen >> 12 ) + ( ulLen >> 14 ) + ( ulLen >> 25 ) + 13; } +#define compressBound( n ) ( hb_zlibCompressBound( n ) +/* additional 12 bytes is for GZIP compression which uses bigger header */ +#define deflateBound( s, n ) ( hb_zlibCompressBound( n ) + 12 ) #endif static HB_SIZE hb_zlibUncompressedSize( const char * szSrc, HB_SIZE nLen, @@ -151,7 +156,7 @@ static int hb_gz_compress( char ** pDstPtr, HB_SIZE * pnDst, memset( &stream, 0, sizeof( z_stream ) ); stream.next_in = ( Bytef* ) pSrc; stream.avail_in = ( uInt ) nSrc; - iResult = deflateInit2( &stream, level, Z_DEFLATED, 31, 8, + iResult = deflateInit2( &stream, level, Z_DEFLATED, 15 + 16, 8, Z_DEFAULT_STRATEGY ); if( iResult == Z_OK ) { @@ -209,17 +214,9 @@ HB_FUNC( HB_ZLIBVERSION ) HB_FUNC( HB_ZCOMPRESSBOUND ) { if( HB_ISCHAR( 1 ) ) -#if defined( _HB_Z_COMPRESSBOUND ) hb_retnint( compressBound( ( uLong ) hb_parclen( 1 ) ) ); -#else - hb_retnint( hb_zlibCompressBound( ( uLong ) hb_parclen( 1 ) ) ); -#endif else if( HB_ISNUM( 1 ) ) -#if defined( _HB_Z_COMPRESSBOUND ) hb_retnint( compressBound( ( uLong ) hb_parns( 1 ) ) ); -#else - hb_retnint( hb_zlibCompressBound( ( uLong ) hb_parns( 1 ) ) ); -#endif else hb_errRT_BASE_SubstR( EG_ARG, 3012, NULL, HB_ERR_FUNCNAME, HB_ERR_ARGS_BASEPARAMS ); } @@ -279,11 +276,7 @@ HB_FUNC( HB_ZCOMPRESS ) else { ulDstLen = HB_ISNUM( 2 ) ? ( uLong ) hb_parns( 2 ) : -#if defined( _HB_Z_COMPRESSBOUND ) - compressBound( ( uLong ) nLen ); -#else - hb_zlibCompressBound( ( uLong ) nLen ); -#endif + compressBound( ( uLong ) nLen ); pDest = ( char * ) hb_xalloc( ulDstLen + 1 ); } @@ -381,6 +374,19 @@ HB_FUNC( HB_ZUNCOMPRESS ) hb_errRT_BASE_SubstR( EG_ARG, 3012, NULL, HB_ERR_FUNCNAME, HB_ERR_ARGS_BASEPARAMS ); } +/* + * HB_GZCOMPRESSBOUND( | ) -> + */ +HB_FUNC( HB_GZCOMPRESSBOUND ) +{ + if( HB_ISCHAR( 1 ) ) + hb_retnint( compressBound( ( uLong ) hb_parclen( 1 ) ) + 12 ); + else if( HB_ISNUM( 1 ) ) + hb_retnint( compressBound( ( uLong ) hb_parns( 1 ) ) + 12 ); + else + hb_errRT_BASE_SubstR( EG_ARG, 3012, NULL, HB_ERR_FUNCNAME, HB_ERR_ARGS_BASEPARAMS ); +} + /* * HB_GZCOMPRESS( , [|<@cBuffer>], [<@nResult>], [] ) * => or NIL on Error