From 712b7710bb2b26cd964e1500eb9ae07f22563fb0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Przemys=C5=82aw=20Czerpak?= Date: Thu, 9 Jan 2014 19:15:23 +0100 Subject: [PATCH] 2014-01-09 19:15 UTC+0100 Przemyslaw Czerpak (druzus/at/poczta.onet.pl) * src/rtl/tgetint.prg ! allow to accept complex expressions passed as string to __Get() function. It fixes the problem I introduced in previous modification. ! allow to use __GetA() for hashes * src/vm/macro.c ! do not ignore additional characters after blank ones looking for memvar name. More restrictive behavior is necessary for to fix problem with code like: MemVarBlock( "GETLIST [1]" ) --- ChangeLog.txt | 11 +++++++++++ src/rtl/tgetint.prg | 19 +++++++++++-------- src/vm/macro.c | 21 +++++++++++++++------ 3 files changed, 37 insertions(+), 14 deletions(-) diff --git a/ChangeLog.txt b/ChangeLog.txt index d7ec756126..717d893aec 100644 --- a/ChangeLog.txt +++ b/ChangeLog.txt @@ -10,6 +10,17 @@ * Change, ! Fix, % Optimization, + Addition, - Removal, ; Comment */ +2014-01-09 19:15 UTC+0100 Przemyslaw Czerpak (druzus/at/poczta.onet.pl) + * src/rtl/tgetint.prg + ! allow to accept complex expressions passed as string to __Get() + function. It fixes the problem I introduced in previous modification. + ! allow to use __GetA() for hashes + + * src/vm/macro.c + ! do not ignore additional characters after blank ones looking for + memvar name. More restrictive behavior is necessary for to fix + problem with code like: MemVarBlock( "GETLIST [1]" ) + 2014-01-09 02:01 UTC+0100 Przemyslaw Czerpak (druzus/at/poczta.onet.pl) * src/vm/itemapi.c ! clear destination item in hb_itemParamStore*() functions if passed diff --git a/src/rtl/tgetint.prg b/src/rtl/tgetint.prg index 3f7700ad5b..40233c9204 100644 --- a/src/rtl/tgetint.prg +++ b/src/rtl/tgetint.prg @@ -57,19 +57,22 @@ FUNCTION __Get( bSetGet, cVarName, cPicture, bValid, bWhen ) IF ! HB_ISBLOCK( bSetGet ) IF FieldPos( cVarName ) > 0 bSetGet := FieldWBlock( cVarName, Select() ) - ELSE + ELSEIF ( bSetGet := MemVarBlock( cVarName ) ) == NIL /* If cVarName is not a field name in current workarea then * CA-Cl*pper always tries to create SET/GET block for memvar. - * Simple loop below with __mvGet() inside is small trick to - * force the same RTE as in CA-Cl*pper so user can create - * memvar dynamically in his custom error handler. [druzus] + * If it cannot (i.e. cVarName is complex expression) then it + * macrocompile simple SET/GET block for it. [druzus] */ - DO WHILE ( bSetGet := MemVarBlock( cVarName ) ) == NIL - __mvGet( cVarName ) - ENDDO + bSetGet := hb_macroBlock( "iif(HB_PValue(1)==NIL," + cVarName + "," + cVarName + ":=hb_PValue(1))" ) ENDIF ENDIF + /* The Eval() below is executed to force the same RTE as in + * CA-Cl*pper so user can create memvar dynamically in his + * custom error handler. [druzus] + */ + Eval( bSetGet ) + oGet := GetNew(,, bSetGet, cVarName, cPicture ) oGet:PreBlock := bWhen @@ -96,7 +99,7 @@ FUNCTION __GetA( bGetArray, cVarName, cPicture, bValid, bWhen, aIndex ) ENDIF ENDIF - IF ! HB_ISARRAY( Eval( bGetArray ) ) + IF ! ValType( Eval( bGetArray ) ) $ "AH" RETURN NIL ENDIF diff --git a/src/vm/macro.c b/src/vm/macro.c index 6dd35fbed2..baaf1207d9 100644 --- a/src/vm/macro.c +++ b/src/vm/macro.c @@ -920,16 +920,25 @@ static void hb_macroSetGetBlock( PHB_DYNS pVarSym, PHB_ITEM pItem, HB_FUNC( MEMVARBLOCK ) { - const char * szVarName = hb_parc( 1 ); + const char * szName = hb_parc( 1 ); - if( szVarName ) + if( szName ) { - PHB_DYNS pVarSym = hb_dynsymFindName( szVarName ); + char szVarName[ HB_SYMBOL_NAME_LEN + 1 ]; - if( pVarSym && hb_dynsymIsMemvar( pVarSym ) ) + while( HB_ISSPACE( *szName ) ) + ++szName; + hb_strncpyUpperTrim( szVarName, szName, sizeof( szVarName ) - 1 ); + + if( *szVarName ) { - HB_STACK_TLS_PRELOAD - hb_macroSetGetBlock( pVarSym, hb_stackReturnItem(), 0, HB_TRUE ); + PHB_DYNS pVarSym = hb_dynsymFind( szVarName ); + + if( pVarSym && hb_dynsymIsMemvar( pVarSym ) ) + { + HB_STACK_TLS_PRELOAD + hb_macroSetGetBlock( pVarSym, hb_stackReturnItem(), 0, HB_TRUE ); + } } } }