From 61321e47393ca0586c28c683ed1104dc748ba2d3 Mon Sep 17 00:00:00 2001 From: Przemyslaw Czerpak Date: Tue, 11 Jul 2006 12:21:22 +0000 Subject: [PATCH] 2006-07-11 14:20 UTC+0200 Przemyslaw Czerpak (druzus/at/priv.onet.pl) * harbour/source/vm/estack.c * minor optimizations * harbour/source/vm/itemapi.c * make hb_itemClear() safe for not allocated stack items --- harbour/ChangeLog | 7 +++++++ harbour/source/vm/estack.c | 13 +++++++++++-- harbour/source/vm/itemapi.c | 12 ++++++++++-- 3 files changed, 28 insertions(+), 4 deletions(-) diff --git a/harbour/ChangeLog b/harbour/ChangeLog index c154be38c8..4e0417c383 100644 --- a/harbour/ChangeLog +++ b/harbour/ChangeLog @@ -8,6 +8,13 @@ 2002-12-01 13:30 UTC+0100 Foo Bar */ + * doc/en/rddmisc.txt + * doc/en/rdddb.txt + ! Fix the sample for AFIELDS() + * Mark AFIELDS() as obsolete + +2006-07-11 14:20 UTC+0200 Przemyslaw Czerpak (druzus/at/priv.onet.pl) + * harbour/source/vm/estack.c * minor optimizations * harbour/source/vm/itemapi.c diff --git a/harbour/source/vm/estack.c b/harbour/source/vm/estack.c index 667a868a77..d14026136c 100644 --- a/harbour/source/vm/estack.c +++ b/harbour/source/vm/estack.c @@ -221,8 +221,13 @@ void hb_stackInit( void ) void hb_stackRemove( LONG lUntilPos ) { HB_ITEM_PTR * pEnd = hb_stack.pItems + lUntilPos; + while( hb_stack.pPos > pEnd ) - hb_stackPop(); + { + --hb_stack.pPos; + if( HB_IS_COMPLEX( * hb_stack.pPos ) ) + hb_itemClear( * hb_stack.pPos ); + } } HB_ITEM_PTR hb_stackNewFrame( HB_STACK_STATE * pStack, USHORT uiParams ) @@ -251,7 +256,11 @@ HB_ITEM_PTR hb_stackNewFrame( HB_STACK_STATE * pStack, USHORT uiParams ) void hb_stackOldFrame( HB_STACK_STATE * pStack ) { while( hb_stack.pPos > hb_stack.pBase ) - hb_stackPop(); + { + --hb_stack.pPos; + if( HB_IS_COMPLEX( * hb_stack.pPos ) ) + hb_itemClear( * hb_stack.pPos ); + } hb_stack.pBase = hb_stack.pItems + pStack->lBaseItem; hb_stack.iStatics = pStack->iStatics; diff --git a/harbour/source/vm/itemapi.c b/harbour/source/vm/itemapi.c index 2fb17a961a..93fa9d2e8a 100644 --- a/harbour/source/vm/itemapi.c +++ b/harbour/source/vm/itemapi.c @@ -1274,9 +1274,17 @@ HB_EXPORT void hb_itemClear( PHB_ITEM pItem ) } else if( HB_IS_ENUM( pItem ) ) /* FOR EACH control variable */ { + /* + * pItem->item.asEnum.valuePtr is intentionally assigned to pValue to + * avoid possible problems when pItem is stack item just freed which + * can be overwritten if hb_itemRelease( pItem->item.asEnum.basePtr ) + * activate .prg destructor [druzus] + */ + PHB_ITEM pValue = pItem->item.asEnum.valuePtr; + hb_itemRelease( pItem->item.asEnum.basePtr ); - if( pItem->item.asEnum.valuePtr ) - hb_itemRelease( pItem->item.asEnum.valuePtr ); + if( pValue ) + hb_itemRelease( pValue ); } #if defined( HB_FM_STATISTICS ) && defined( HB_PARANOID_MEM_CHECK )