diff --git a/harbour/ChangeLog b/harbour/ChangeLog index bc1d57e9e9..e9ebb2772f 100644 --- a/harbour/ChangeLog +++ b/harbour/ChangeLog @@ -16,6 +16,33 @@ The license applies to all entries newer than 2009-04-28. */ +2010-12-09 11:46 UTC+0200 Viktor Szakats (harbour.01 syenar.hu) + * contrib/hblzf/hblzf.c + * contrib/hblzf/tests/test.prg + ! Rearranged to not have code after hb_err*() call. + % Deleted HB_IS*() checks before hb_stor*() call. (unnecessary) + ! Fixed formatting to comply with Harbour style. Pls don't + reformat it with local style. + + Added TOFIX: eliminate static vars for MT compliance + + Added TOFIX: eliminate reliance on errno.h, as it's not present on + some systems. + * Renamed HB_LZF_DECOMPRESS()/HB_LZF_COMPRESS() to not have HB_ + prefix. (HB_ prefix is only needed for functions which are not + strict wrappers) + ! Fixed HB_LZF_DELTA(), HB_LZF_BUFFERSIZE() to only set settings + when parameter was passed. To reset to default value: pass NIL. + This makes it possible to read these values without resetting them. + ! Fixed LZF_DECOMPRESS() to allocate space for termination byte, + this also fixes allocating zero bytes when empty string is passed. + + * contrib/hblzf/hblzf.hbp + * Minor formatting. + + * INSTALL + ! Restored my latest change. Please ALWAYS update before commit. + (and needless to say, work in local SVN sandbox, instead of + copying in changes from elsewhere) + 2010-12-09 12:10 UTC+0200 Petr Chornyj (myorg63 at mail.ru) * contrib/3rd/sqlite3/sqlite3.c * contrib/3rd/sqlite3/sqlite3.h @@ -29,7 +56,7 @@ * contrib/hbsqlit3/hbsqlit3.c + Added sqlite3_blob_reopen(), sqlite3_stmt_readonly() + sqlite3_enable_load_extension() function guarded with SQLITE_OMIT_LOAD_EXTENSION - It's needed for some 3rd sqlite extension, + It's needed for some 3rd sqlite extension, f.e. SQLCIPHER for security reasons + contrib/hblzf diff --git a/harbour/INSTALL b/harbour/INSTALL index 787f17e2ee..f0aabccc2e 100644 --- a/harbour/INSTALL +++ b/harbour/INSTALL @@ -1659,7 +1659,7 @@ HARBOUR -[ Copyright (c) 2009-2010 Viktor Szakats (harbour.01 syenar.hu) +[ Copyright (c) 2009-2011 Viktor Szakats (harbour.01 syenar.hu) Licensed under Creative Commons Attribution-ShareAlike 3.0: http://creativecommons.org/licenses/by-sa/3.0/ See COPYING. ] diff --git a/harbour/contrib/hblzf/hblzf.c b/harbour/contrib/hblzf/hblzf.c index 1f8029e23d..9945c3186d 100644 --- a/harbour/contrib/hblzf/hblzf.c +++ b/harbour/contrib/hblzf/hblzf.c @@ -50,6 +50,7 @@ * */ +/* TOFIX: Some platforms don't have this. Build breaker. */ #include #include "hbapi.h" @@ -67,11 +68,12 @@ #define LZF_BUFFSIZE 1024 +/* TOFIX: Make it MT compatible */ HB_SIZE s_delta = 0; HB_SIZE s_buffer_size = LZF_BUFFSIZE; /** - Return a LZF_VERSION, API version + Return a LZF_VERSION, API version */ HB_FUNC( HB_LZF_VERSION ) @@ -79,8 +81,8 @@ HB_FUNC( HB_LZF_VERSION ) hb_retni( LZF_VERSION ); } -/** - Return 1 if lzf was optimized for speed, 0 for compression +/** + Return 1 if lzf was optimized for speed, 0 for compression */ HB_FUNC( HB_LZF_OPTIMIZED_FOR ) @@ -88,104 +90,104 @@ HB_FUNC( HB_LZF_OPTIMIZED_FOR ) hb_retni( HB_LZF_OPTIMIZED_FOR ); } -/** +/** */ HB_FUNC( HB_LZF_DELTA ) { hb_retni( s_delta ); - s_delta = (HB_SIZE) hb_parnidef( 1, 0 ); + if( hb_pcount() >= 1 ) + s_delta = ( HB_SIZE ) hb_parnidef( 1, 0 ); } -/** +/** */ HB_FUNC( HB_LZF_BUFFERSIZE ) { hb_retni( s_buffer_size ); - s_buffer_size = (HB_SIZE) hb_parnidef( 1, LZF_BUFFSIZE ); + if( hb_pcount() >= 1 ) + s_buffer_size = ( HB_SIZE ) hb_parnidef( 1, LZF_BUFFSIZE ); } /** - Return a string compressed with LZF + Return a string compressed with LZF */ -HB_FUNC( HB_LZF_COMPRESS ) +HB_FUNC( LZF_COMPRESS ) { PHB_ITEM pArg = hb_param( 1, HB_IT_STRING ); - const char *in_data = NULL; - char *out_data; - HB_SIZE in_len, out_len; - unsigned int uiResult; if( pArg != NULL ) + { + const char * in_data = NULL; + char * out_data; + HB_SIZE in_len, out_len; + unsigned int uiResult; + in_data = hb_itemGetCPtr( pArg ); - else - hb_errRT_BASE_SubstR( EG_ARG, 3012, NULL, HB_ERR_FUNCNAME, HB_ERR_ARGS_BASEPARAMS ); + in_len = hb_itemGetCLen( pArg ); + out_len = in_len + ( ( s_delta ) ? s_delta : ( ( HB_SIZE ) ( in_len * 1.04 ) + 1 ) ); - in_len = hb_itemGetCLen( pArg ); - out_len = in_len + ( (s_delta) ? s_delta : ( ( HB_SIZE ) ( in_len * 1.04 ) + 1 ) ); + out_data = ( char * ) hb_xgrab( out_len + 1 ); - out_data = (char *) hb_xgrab( out_len ); - - uiResult = lzf_compress( in_data, in_len, out_data, out_len ); - if ( uiResult == 0 ) - { - hb_xfree( out_data ); - hb_retc_null(); - } - else - { - hb_retclen_buffer( out_data, uiResult ); - } -} - -/** - Return a string decompressed with LZF -*/ - -HB_FUNC( HB_LZF_DECOMPRESS ) -{ - PHB_ITEM pArg = hb_param( 1, HB_IT_STRING ); - const char *in_data = NULL; - char *buffer; - HB_SIZE in_len, buffer_size, i = 1; - unsigned int uiResult; - - if( pArg != NULL ) - in_data = hb_itemGetCPtr( pArg ); - else - hb_errRT_BASE_SubstR( EG_ARG, 3012, NULL, HB_ERR_FUNCNAME, HB_ERR_ARGS_BASEPARAMS ); - - in_len = hb_itemGetCLen( pArg ); - buffer_size = s_buffer_size; - - buffer = hb_xgrab( buffer_size ); - - do - { - buffer_size *= i++; - buffer = hb_xrealloc( buffer, buffer_size ); - - uiResult = lzf_decompress( in_data, in_len, buffer, buffer_size ); - } while ( uiResult == 0 && errno == E2BIG ); - - if ( uiResult == 0 ) - { - if ( errno == EINVAL ) + uiResult = lzf_compress( in_data, in_len, out_data, out_len ); + if( uiResult == 0 ) { - HB_TRACE( HB_TR_DEBUG, "LZF decompression failed, compressed data corrupted" ); + hb_xfree( out_data ); + hb_retc_null(); + } + else + hb_retclen_buffer( out_data, uiResult ); + } + else + hb_errRT_BASE_SubstR( EG_ARG, 3012, NULL, HB_ERR_FUNCNAME, HB_ERR_ARGS_BASEPARAMS ); +} - if( hb_pcount() > 1 && (HB_ISNUM(2) && HB_ISBYREF(2)) ) +/** + Return a string decompressed with LZF +*/ + +HB_FUNC( LZF_DECOMPRESS ) +{ + PHB_ITEM pArg = hb_param( 1, HB_IT_STRING ); + + if( pArg != NULL ) + { + const char * in_data = NULL; + char * buffer; + HB_SIZE in_len, buffer_size, i = 1; + unsigned int uiResult; + + in_data = hb_itemGetCPtr( pArg ); + in_len = hb_itemGetCLen( pArg ); + buffer_size = s_buffer_size; + + buffer = hb_xgrab( buffer_size + 1 ); + + do + { + buffer_size *= i++; + buffer = hb_xrealloc( buffer, buffer_size ); + + uiResult = lzf_decompress( in_data, in_len, buffer, buffer_size ); + } while( uiResult == 0 && errno == E2BIG ); + + if( uiResult == 0 ) + { + if( errno == EINVAL ) { + HB_TRACE( HB_TR_DEBUG, "LZF decompression failed, compressed data corrupted" ); + hb_storni( errno, 2 ); } + + hb_xfree( buffer ); + hb_retc_null(); } - hb_xfree( buffer ); - hb_retc_null(); + else + hb_retclen_buffer( buffer, uiResult ); } else - { - hb_retclen_buffer( buffer, uiResult ); - } + hb_errRT_BASE_SubstR( EG_ARG, 3012, NULL, HB_ERR_FUNCNAME, HB_ERR_ARGS_BASEPARAMS ); } diff --git a/harbour/contrib/hblzf/hblzf.hbp b/harbour/contrib/hblzf/hblzf.hbp index c334146428..117b139eaa 100644 --- a/harbour/contrib/hblzf/hblzf.hbp +++ b/harbour/contrib/hblzf/hblzf.hbp @@ -16,7 +16,6 @@ -depincpathlocal=lzf:3rd/liblzf -depfinish=lzf - hblzf.c 3rd/liblzf/lzf.hbc{HBMK_HAS_LZF_LOCAL} diff --git a/harbour/contrib/hblzf/tests/test.prg b/harbour/contrib/hblzf/tests/test.prg index 0c7f75914e..d52411a6a0 100644 --- a/harbour/contrib/hblzf/tests/test.prg +++ b/harbour/contrib/hblzf/tests/test.prg @@ -10,24 +10,24 @@ #define EINVAL 22 /* Invalid argument */ PROCEDURE Main() - LOCAL cStr, str_compressed, str_decompressed - LOCAL b64_expected_result := "BFRoaXMgIAIUdGVzdCBvZiBMWkYgZXh0ZW5zaW9u" + LOCAL cStr, str_compressed, str_decompressed + LOCAL b64_expected_result := "BFRoaXMgIAIUdGVzdCBvZiBMWkYgZXh0ZW5zaW9u" LOCAL errno := 0 ? "LZF Api version is", ; - hb_ntos( hb_lzf_version() ) + "(" + hb_numtohex(hb_lzf_version()) +")" + hb_ntos( hb_lzf_version() ) + "(" + hb_numtohex( hb_lzf_version() ) +")" ? "LibLZF optimized for", iif( hb_lzf_optimized_for() > 0, "speed.", "compression." ) ? "--- test 1 ---" /* Lenght of output buffer is calculated as out_len := in_len + delta - If the output buffer is not large enough or any error occurs + If the output buffer is not large enough or any error occurs hb_lzf_compress return 0 */ hb_lzf_delta( -1 ) cStr := TEST_STRING - str_compressed := hb_lzf_compress( cStr ) + str_compressed := lzf_compress( cStr ) ? "Lenght of a string is", hb_ntos( Len( cStr ) ) ? "Lenght of a compressed string is", hb_ntos( Len( str_compressed ) ) @@ -37,10 +37,10 @@ PROCEDURE Main() By default ( delta == 0 ) lenght of output buffer is int( len( data_in ) * 1.04 ) + 1 */ - hb_lzf_delta() + hb_lzf_delta( NIL ) cStr := TEST_STRING - str_compressed := hb_lzf_compress( cStr ) + str_compressed := lzf_compress( cStr ) ? "Lenght of a string is", hb_ntos( Len( cStr ) ) ? "Lenght of a compressed string is", hb_ntos( Len( str_compressed ) ) @@ -49,16 +49,16 @@ PROCEDURE Main() ? "--- test 3 ---" cStr := Replicate( TEST_STRING, _NREPL_ ) - str_compressed := hb_lzf_compress( cStr ) + str_compressed := lzf_compress( cStr ) ? "Lenght of a string is", hb_ntos( Len( cStr ) ) ? "Lenght of a compressed string is", hb_ntos( Len( str_compressed ) ) ? "--- test 4 ---" - ? hb_lzf_bufferSize() - str_decompressed := hb_lzf_decompress( str_compressed, @errno ) + ? hb_lzf_bufferSize( NIL ) + str_decompressed := lzf_decompress( str_compressed, @errno ) - IF errno == EINVAL + IF errno == EINVAL ? "LZF decompression failed, compressed data corrupted" ELSE ? cStr == str_decompressed