From 0ab0d778c8475554d9e79084f5976267c0e6b2bf Mon Sep 17 00:00:00 2001 From: Viktor Szakats Date: Thu, 9 Dec 2010 13:39:03 +0000 Subject: [PATCH] 2010-12-09 14:38 UTC+0200 Viktor Szakats (harbour.01 syenar.hu) * contrib/hblzf/hblzf.c ! Fixed for MT mode by moving static vars to TSD. --- harbour/ChangeLog | 6 ++++- harbour/contrib/hblzf/hblzf.c | 41 ++++++++++++++++++++++++++--------- 2 files changed, 36 insertions(+), 11 deletions(-) diff --git a/harbour/ChangeLog b/harbour/ChangeLog index f572205211..ba522dfdeb 100644 --- a/harbour/ChangeLog +++ b/harbour/ChangeLog @@ -16,6 +16,10 @@ The license applies to all entries newer than 2009-04-28. */ +2010-12-09 14:38 UTC+0200 Viktor Szakats (harbour.01 syenar.hu) + * contrib/hblzf/hblzf.c + ! Fixed for MT mode by moving static vars to TSD. + 2010-12-09 13:37 UTC+0200 Viktor Szakats (harbour.01 syenar.hu) - contrib/3rd/sqlite3/sqlite3ext.h + contrib/3rd/sqlite3/sqlite3x.h @@ -40,7 +44,7 @@ % 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 static vars for MT compliance [DONE] + 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_ diff --git a/harbour/contrib/hblzf/hblzf.c b/harbour/contrib/hblzf/hblzf.c index 9945c3186d..d316c46718 100644 --- a/harbour/contrib/hblzf/hblzf.c +++ b/harbour/contrib/hblzf/hblzf.c @@ -56,6 +56,7 @@ #include "hbapi.h" #include "hbapierr.h" #include "hbapiitm.h" +#include "hbstack.h" #include "lzf.h" #include "lzfP.h" @@ -66,11 +67,23 @@ # define HB_LZF_OPTIMIZED_FOR 0 #endif -#define LZF_BUFFSIZE 1024 +#define HB_LZF_BUFFSIZE 1024 -/* TOFIX: Make it MT compatible */ -HB_SIZE s_delta = 0; -HB_SIZE s_buffer_size = LZF_BUFFSIZE; +typedef struct +{ + HB_SIZE delta; + HB_SIZE buffer_size; +} HB_LZF_VAR, * PHB_LZF_VAR; + +static void hb_lzf_var_init( void * cargo ) +{ + PHB_LZF_VAR pLZF_VAR = ( PHB_LZF_VAR ) cargo; + + pLZF_VAR->delta = 0; + pLZF_VAR->buffer_size = HB_LZF_BUFFSIZE; +} + +static HB_TSD_NEW( s_lzf_var, sizeof( HB_LZF_VAR ), hb_lzf_var_init, NULL ); /** Return a LZF_VERSION, API version @@ -95,9 +108,11 @@ HB_FUNC( HB_LZF_OPTIMIZED_FOR ) HB_FUNC( HB_LZF_DELTA ) { - hb_retni( s_delta ); + PHB_LZF_VAR pLZF_VAR = ( PHB_LZF_VAR ) hb_stackGetTSD( &s_lzf_var ); + + hb_retni( pLZF_VAR->delta ); if( hb_pcount() >= 1 ) - s_delta = ( HB_SIZE ) hb_parnidef( 1, 0 ); + pLZF_VAR->delta = ( HB_SIZE ) hb_parnidef( 1, 0 ); } /** @@ -105,9 +120,11 @@ HB_FUNC( HB_LZF_DELTA ) HB_FUNC( HB_LZF_BUFFERSIZE ) { - hb_retni( s_buffer_size ); + PHB_LZF_VAR pLZF_VAR = ( PHB_LZF_VAR ) hb_stackGetTSD( &s_lzf_var ); + + hb_retni( pLZF_VAR->buffer_size ); if( hb_pcount() >= 1 ) - s_buffer_size = ( HB_SIZE ) hb_parnidef( 1, LZF_BUFFSIZE ); + pLZF_VAR->buffer_size = ( HB_SIZE ) hb_parnidef( 1, HB_LZF_BUFFSIZE ); } /** @@ -120,6 +137,8 @@ HB_FUNC( LZF_COMPRESS ) if( pArg != NULL ) { + PHB_LZF_VAR pLZF_VAR = ( PHB_LZF_VAR ) hb_stackGetTSD( &s_lzf_var ); + const char * in_data = NULL; char * out_data; HB_SIZE in_len, out_len; @@ -127,7 +146,7 @@ HB_FUNC( LZF_COMPRESS ) in_data = hb_itemGetCPtr( pArg ); in_len = hb_itemGetCLen( pArg ); - out_len = in_len + ( ( s_delta ) ? s_delta : ( ( HB_SIZE ) ( in_len * 1.04 ) + 1 ) ); + out_len = in_len + ( ( pLZF_VAR->delta ) ? pLZF_VAR->delta : ( ( HB_SIZE ) ( in_len * 1.04 ) + 1 ) ); out_data = ( char * ) hb_xgrab( out_len + 1 ); @@ -154,6 +173,8 @@ HB_FUNC( LZF_DECOMPRESS ) if( pArg != NULL ) { + PHB_LZF_VAR pLZF_VAR = ( PHB_LZF_VAR ) hb_stackGetTSD( &s_lzf_var ); + const char * in_data = NULL; char * buffer; HB_SIZE in_len, buffer_size, i = 1; @@ -161,7 +182,7 @@ HB_FUNC( LZF_DECOMPRESS ) in_data = hb_itemGetCPtr( pArg ); in_len = hb_itemGetCLen( pArg ); - buffer_size = s_buffer_size; + buffer_size = pLZF_VAR->buffer_size; buffer = hb_xgrab( buffer_size + 1 );