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
This commit is contained in:
Przemyslaw Czerpak
2006-12-12 13:58:20 +00:00
parent 3d627021e6
commit efee430f3b
5 changed files with 66 additions and 29 deletions

View File

@@ -8,6 +8,25 @@
2002-12-01 13:30 UTC+0100 Foo Bar <foo.bar@foobar.org>
*/
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

View File

@@ -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

View File

@@ -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 );

View File

@@ -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:

View File

@@ -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 );