From efee430f3bd9ddf3cf18b01dfc078ab5267bdd94 Mon Sep 17 00:00:00 2001 From: Przemyslaw Czerpak Date: Tue, 12 Dec 2006 13:58:20 +0000 Subject: [PATCH] 2006-12-12 14:55 UTC+0100 Przemyslaw Czerpak (druzus/at/priv.onet.pl) * harbour/include/hbstack.h ! fixed typo in function name, should be: hb_stackLocalVariable() not hb_stacklocalVariable() + added hb_stackId() * hide hb_stack declaration when HB_STACK_MACROS is not set * harbour/source/vm/dynlibhb.c * use hb_stackId() * harbour/source/vm/estack.c + added hb_stackId() ! fixed some condition used to check stack access - they were reporting internal errors for valid code * harbour/source/vm/hvm.c ! fixed code which executed hb_stackLocalVariable() with pointer to SHORT not int --- harbour/ChangeLog | 19 ++++++++++++++++++ harbour/include/hbstack.h | 9 ++++++++- harbour/source/vm/dynlibhb.c | 4 ++-- harbour/source/vm/estack.c | 25 ++++++++++++++++-------- harbour/source/vm/hvm.c | 38 +++++++++++++++++++----------------- 5 files changed, 66 insertions(+), 29 deletions(-) diff --git a/harbour/ChangeLog b/harbour/ChangeLog index a509ecffc2..152721a4e9 100644 --- a/harbour/ChangeLog +++ b/harbour/ChangeLog @@ -8,6 +8,25 @@ 2002-12-01 13:30 UTC+0100 Foo Bar */ +2006-12-12 14:55 UTC+0100 Przemyslaw Czerpak (druzus/at/priv.onet.pl) + * harbour/include/hbstack.h + ! fixed typo in function name, should be: hb_stackLocalVariable() + not hb_stacklocalVariable() + + added hb_stackId() + * hide hb_stack declaration when HB_STACK_MACROS is not set + + * harbour/source/vm/dynlibhb.c + * use hb_stackId() + + * harbour/source/vm/estack.c + + added hb_stackId() + ! fixed some condition used to check stack access - they were + reporting internal errors for valid code + + * harbour/source/vm/hvm.c + ! fixed code which executed hb_stackLocalVariable() with pointer + to SHORT not int + 2006-12-11 22:15 UTC+0100 Przemyslaw Czerpak (druzus/at/priv.onet.pl) * harbour/source/rtl/memoline.c ! added fix sent to me by Randy Portnoff - it's a little bit differ diff --git a/harbour/include/hbstack.h b/harbour/include/hbstack.h index d7a68bf68d..72fa7b83ee 100644 --- a/harbour/include/hbstack.h +++ b/harbour/include/hbstack.h @@ -80,7 +80,9 @@ typedef struct char szDate[ 9 ]; /* last returned date from _pards() yyyymmdd format */ } HB_STACK; +#if defined(HB_STACK_MACROS) extern HB_STACK hb_stack; +#endif #endif @@ -89,7 +91,7 @@ extern HB_EXPORT HB_ITEM_PTR hb_stackReturnItem( void );// returns RETURN Item f extern HB_ITEM_PTR hb_stackItemFromTop( int nFromTop ); extern HB_ITEM_PTR hb_stackItemFromBase( int nFromBase ); -extern HB_ITEM_PTR hb_stacklocalVariable( int *piFromBase ); +extern HB_ITEM_PTR hb_stackLocalVariable( int *piFromBase ); extern LONG hb_stackTopOffset( void ); extern LONG hb_stackBaseOffset( void ); extern LONG hb_stackTotalItems( void ); @@ -102,6 +104,7 @@ extern PHB_ITEM ** hb_stackItemBasePtr( void ); extern PHB_ITEM hb_stackWithObjectItem( void ); extern LONG hb_stackWithObjectOffset( void ); extern void hb_stackWithObjectSetOffset( LONG ); +extern void * hb_stackId( void ); extern void hb_stackDec( void ); /* pops an item from the stack without clearing it's contents */ extern void hb_stackPop( void ); /* pops an item from the stack */ @@ -147,6 +150,8 @@ extern void hb_stackClearMevarsBase( void ); #define hb_stackWithObjectOffset( ) ( hb_stack.lWithObject ) #define hb_stackWithObjectSetOffset( n ) do { hb_stack.lWithObject = ( n ); } while( 0 ) +#define hb_stackId( ) ( ( void * ) &hb_stack ) + #define hb_stackAllocItem( ) ( ( ++hb_stack.pPos == hb_stack.pEnd ? \ hb_stackIncrease() : (void) 0 ), \ * ( hb_stack.pPos - 1 ) ) @@ -205,6 +210,7 @@ extern void hb_stackClearMevarsBase( void ); if( ++hb_stack.pPos == hb_stack.pEnd ) \ hb_stackIncrease(); \ } while ( 0 ) + #define hb_stackLocalVariable( p ) ( ( ( ( *hb_stack.pBase )->item.asSymbol.paramcnt > \ ( * hb_stack.pBase )->item.asSymbol.paramdeclcnt ) && \ ( * (p) ) > ( * hb_stack.pBase )->item.asSymbol.paramdeclcnt ) ? \ @@ -212,6 +218,7 @@ extern void hb_stackClearMevarsBase( void ); ( * hb_stack.pBase )->item.asSymbol.paramcnt - \ ( * hb_stack.pBase )->item.asSymbol.paramdeclcnt ) + 1 ) ) : \ ( * ( hb_stack.pBase + ( int ) ( * (p) ) + 1 ) ) ) + #endif diff --git a/harbour/source/vm/dynlibhb.c b/harbour/source/vm/dynlibhb.c index e2f8dd97ae..ea43f7c268 100644 --- a/harbour/source/vm/dynlibhb.c +++ b/harbour/source/vm/dynlibhb.c @@ -87,7 +87,7 @@ HB_FUNC( HB_LIBLOAD ) } /* use stack address as first level marker */ - hb_vmBeginSymbolGroup( ( void * ) &hb_stack, TRUE ); + hb_vmBeginSymbolGroup( ( void * ) hb_stackId(), TRUE ); hDynLib = ( void * ) LoadLibrary( hb_parc( 1 ) ); /* set real marker */ hb_vmInitSymbolGroup( hDynLib, argc, argv ); @@ -112,7 +112,7 @@ HB_FUNC( HB_LIBLOAD ) } /* use stack address as first level marker */ - hb_vmBeginSymbolGroup( ( void * ) &hb_stack, TRUE ); + hb_vmBeginSymbolGroup( ( void * ) hb_stackId(), TRUE ); hDynLib = ( void * ) dlopen( hb_parc( 1 ), RTLD_LAZY | RTLD_GLOBAL ); /* set real marker */ hb_vmInitSymbolGroup( hDynLib, argc, argv ); diff --git a/harbour/source/vm/estack.c b/harbour/source/vm/estack.c index f66df2bd5b..ea3a7ae40f 100644 --- a/harbour/source/vm/estack.c +++ b/harbour/source/vm/estack.c @@ -77,6 +77,14 @@ HB_SYMB s_initSymbol = { "hb_stackInit", {HB_FS_STATIC}, {NULL}, NULL }; /* ------------------------------- */ +#undef hb_stackId +void * hb_stackId( void ) +{ + HB_TRACE(HB_TR_DEBUG, ("hb_stackId()")); + + return ( void * ) &hb_stack; +} + #undef hb_stackPop void hb_stackPop( void ) { @@ -292,31 +300,32 @@ HB_ITEM_PTR hb_stackItem( LONG iItemPos ) } #undef hb_stackItemFromTop -HB_ITEM_PTR hb_stackItemFromTop( int nFromTop ) +HB_ITEM_PTR hb_stackItemFromTop( int iFromTop ) { - if( nFromTop >= 0 ) + if( iFromTop >= 0 ) hb_errInternal( HB_EI_STACKUFLOW, NULL, NULL, NULL ); - return * ( hb_stack.pPos + nFromTop ); + return * ( hb_stack.pPos + iFromTop ); } #undef hb_stackItemFromBase -HB_ITEM_PTR hb_stackItemFromBase( int nFromBase ) +HB_ITEM_PTR hb_stackItemFromBase( int iFromBase ) { - if( nFromBase <= 0 ) + if( iFromBase < 0 ) hb_errInternal( HB_EI_STACKUFLOW, NULL, NULL, NULL ); - return * ( hb_stack.pBase + nFromBase + 1 ); + return * ( hb_stack.pBase + iFromBase + 1 ); } #undef hb_stackLocalVariable HB_ITEM_PTR hb_stackLocalVariable( int *piFromBase ) { HB_ITEM_PTR pBase = *hb_stack.pBase; - + +/* if( *piFromBase <= 0 ) hb_errInternal( HB_EI_STACKUFLOW, NULL, NULL, NULL ); - +*/ if( pBase->item.asSymbol.paramcnt > pBase->item.asSymbol.paramdeclcnt ) { /* function with variable number of parameters: diff --git a/harbour/source/vm/hvm.c b/harbour/source/vm/hvm.c index 20467fc5ec..bc59c9402a 100644 --- a/harbour/source/vm/hvm.c +++ b/harbour/source/vm/hvm.c @@ -174,9 +174,9 @@ static void hb_vmPushBlock( const BYTE * pCode, PHB_SYMB pSymbols, USHORT usL static void hb_vmPushBlockShort( const BYTE * pCode, PHB_SYMB pSymbols, USHORT usLen ); /* creates a codeblock */ static void hb_vmPushDoubleConst( double dNumber, int iWidth, int iDec ); /* Pushes a double constant (pcode) */ static void hb_vmPushMacroBlock( BYTE * pCode, PHB_SYMB pSymbols ); /* creates a macro-compiled codeblock */ -static void hb_vmPushLocal( SHORT iLocal ); /* pushes the containts of a local onto the stack */ -static void hb_vmPushLocalByRef( SHORT iLocal ); /* pushes a local by refrence onto the stack */ -static void hb_vmPushLongConst( long lNumber ); /* Pushes a long constant (pcode) */ +static void hb_vmPushLocal( int iLocal ); /* pushes the containts of a local onto the stack */ +static void hb_vmPushLocalByRef( int iLocal ); /* pushes a local by refrence onto the stack */ +static void hb_vmPushLongConst( long lNumber ); /* Pushes a long constant (pcode) */ static void hb_vmPushHBLong( HB_LONG lNumber ); /* pushes a HB_LONG number onto the stack */ #if !defined( HB_LONG_LONG_OFF ) static void hb_vmPushLongLongConst( LONGLONG lNumber ); /* Pushes a long long constant (pcode) */ @@ -202,7 +202,7 @@ static double hb_vmPopDouble( int * ); /* pops the stack latest value static void hb_vmPopAlias( void ); /* pops the workarea number form the eval stack */ static void hb_vmPopAliasedField( PHB_SYMB ); /* pops an aliased field from the eval stack*/ static void hb_vmPopAliasedVar( PHB_SYMB ); /* pops an aliased variable from the eval stack*/ -static void hb_vmPopLocal( SHORT iLocal ); /* pops the stack latest value onto a local */ +static void hb_vmPopLocal( int iLocal ); /* pops the stack latest value onto a local */ static void hb_vmPopStatic( USHORT uiStatic ); /* pops the stack latest value onto a static */ /* Take the value from stack top without POP */ @@ -1397,7 +1397,7 @@ HB_EXPORT void hb_vmExecute( const BYTE * pCode, PHB_SYMB pSymbols ) break; case HB_P_PUSHLOCAL: - hb_vmPushLocal( HB_PCODE_MKSHORT( &( pCode[ w + 1 ] ) ) ); + hb_vmPushLocal( HB_PCODE_MKSHORT( &pCode[ w + 1 ] ) ); w += 3; break; @@ -1407,12 +1407,12 @@ HB_EXPORT void hb_vmExecute( const BYTE * pCode, PHB_SYMB pSymbols ) break; case HB_P_PUSHLOCALREF: - hb_vmPushLocalByRef( HB_PCODE_MKSHORT( &( pCode[ w + 1 ] ) ) ); + hb_vmPushLocalByRef( HB_PCODE_MKSHORT( &pCode[ w + 1 ] ) ); w += 3; break; case HB_P_PUSHSTATIC: - hb_vmPushStatic( HB_PCODE_MKUSHORT( &( pCode[ w + 1 ] ) ) ); + hb_vmPushStatic( HB_PCODE_MKUSHORT( &pCode[ w + 1 ] ) ); w += 3; break; @@ -1789,7 +1789,7 @@ HB_EXPORT void hb_vmExecute( const BYTE * pCode, PHB_SYMB pSymbols ) case HB_P_LOCALNEARADDINT: { - SHORT iLocal = pCode[ w + 1 ]; + int iLocal = pCode[ w + 1 ]; HB_TRACE( HB_TR_DEBUG, ("HB_P_LOCALNEARADDINT") ); hb_vmAddInt( hb_stackLocalVariable( &iLocal ), @@ -5012,11 +5012,11 @@ static void hb_vmPushAliasedVar( PHB_SYMB pSym ) hb_vmPushAliasedField( pSym ); } -static void hb_vmPushLocal( SHORT iLocal ) +static void hb_vmPushLocal( int iLocal ) { PHB_ITEM pLocal; - HB_TRACE(HB_TR_DEBUG, ("hb_vmPushLocal(%hd)", iLocal)); + HB_TRACE(HB_TR_DEBUG, ("hb_vmPushLocal(%d)", iLocal)); if( iLocal >= 0 ) { @@ -5041,18 +5041,17 @@ static void hb_vmPushLocal( SHORT iLocal ) } } -static void hb_vmPushLocalByRef( SHORT iLocal ) +static void hb_vmPushLocalByRef( int iLocal ) { HB_ITEM_PTR pTop = hb_stackAllocItem(); - HB_TRACE(HB_TR_DEBUG, ("hb_vmPushLocalByRef(%hd)", iLocal)); + HB_TRACE(HB_TR_DEBUG, ("hb_vmPushLocalByRef(%d)", iLocal)); - pTop->type = HB_IT_BYREF; /* we store its stack offset instead of a pointer to support a dynamic stack */ - hb_stackLocalVariable( &iLocal ); - pTop->item.asRefer.value = iLocal; - pTop->item.asRefer.offset = hb_stackBaseOffset(); if( iLocal >= 0 ) + { + hb_stackLocalVariable( &iLocal ); pTop->item.asRefer.BasePtr.itemsbasePtr = hb_stackItemBasePtr(); + } else { /* store direct codeblock address because an item where a codeblock @@ -5061,6 +5060,9 @@ static void hb_vmPushLocalByRef( SHORT iLocal ) */ pTop->item.asRefer.BasePtr.block = hb_stackSelfItem()->item.asBlock.value; } + pTop->type = HB_IT_BYREF; + pTop->item.asRefer.value = iLocal; + pTop->item.asRefer.offset = hb_stackBaseOffset(); } static void hb_vmPushStatic( USHORT uiStatic ) @@ -5370,11 +5372,11 @@ static void hb_vmPopAliasedVar( PHB_SYMB pSym ) hb_vmPopAliasedField( pSym ); } -static void hb_vmPopLocal( SHORT iLocal ) +static void hb_vmPopLocal( int iLocal ) { PHB_ITEM pLocal, pVal; - HB_TRACE(HB_TR_DEBUG, ("hb_vmPopLocal(%hd)", iLocal)); + HB_TRACE(HB_TR_DEBUG, ("hb_vmPopLocal(%d)", iLocal)); pVal = hb_stackItemFromTop( -1 );