From 7f59b345cee54f004bcbd89db9a625974a0070c4 Mon Sep 17 00:00:00 2001 From: Przemyslaw Czerpak Date: Fri, 23 Nov 2007 00:20:02 +0000 Subject: [PATCH] 2007-11-23 01:19 UTC+0100 Przemyslaw Czerpak (druzus/at/priv.onet.pl) * harbour/include/hbvm.h * harbour/source/vm/hvm.c * make hb_vmPushNumInt() public function * harbour/contrib/gtwvg/wvtcore.c ! fixed hb_wvt_gtDlgProcMLess() and hb_wvt_gtDlgProcModal() - fixed GPF when codeblock are used - use hb_vmPushNumInt() instead of hb_vmPushLong() to push handles and numbers with potentially unknown size. I still suggest to use pointers ITEMs instead of converting handles to numbers but I'm leaving such modifications to library authors - using hb_vmPushNumInt() is a workaround for striping highest 32 bit from handles by hb_vmPushLong() in XP64 - use hb_vmRequestReenter() / hb_vmRequestRestore() to avoid crash when function/codeblock is executed during HVM has been serving an exception (f.e. BREAK/QUIT/RETURN) --- harbour/ChangeLog | 18 +++ harbour/contrib/gtwvg/wvtcore.c | 222 +++++++++++++------------------- harbour/include/hbvm.h | 1 + harbour/source/vm/hvm.c | 17 ++- 4 files changed, 113 insertions(+), 145 deletions(-) diff --git a/harbour/ChangeLog b/harbour/ChangeLog index 66cd450bd8..7b53acb393 100644 --- a/harbour/ChangeLog +++ b/harbour/ChangeLog @@ -8,6 +8,24 @@ 2002-12-01 13:30 UTC+0100 Foo Bar */ +2007-11-23 01:19 UTC+0100 Przemyslaw Czerpak (druzus/at/priv.onet.pl) + * harbour/include/hbvm.h + * harbour/source/vm/hvm.c + * make hb_vmPushNumInt() public function + + * harbour/contrib/gtwvg/wvtcore.c + ! fixed hb_wvt_gtDlgProcMLess() and hb_wvt_gtDlgProcModal() + - fixed GPF when codeblock are used + - use hb_vmPushNumInt() instead of hb_vmPushLong() to push + handles and numbers with potentially unknown size. + I still suggest to use pointers ITEMs instead of converting + handles to numbers but I'm leaving such modifications to library + authors - using hb_vmPushNumInt() is a workaround for striping + highest 32 bit from handles by hb_vmPushLong() in XP64 + - use hb_vmRequestReenter() / hb_vmRequestRestore() to avoid crash + when function/codeblock is executed during HVM has been serving + an exception (f.e. BREAK/QUIT/RETURN) + 2007-11-22 18:33 UTC+0100 Przemyslaw Czerpak (druzus/at/priv.onet.pl) * harbour/source/rtl/gtwvt/gtwvt.c * declared two functions diff --git a/harbour/contrib/gtwvg/wvtcore.c b/harbour/contrib/gtwvg/wvtcore.c index 7b89fc3aca..46e588f036 100644 --- a/harbour/contrib/gtwvg/wvtcore.c +++ b/harbour/contrib/gtwvg/wvtcore.c @@ -122,9 +122,8 @@ HB_FUNC( WVT_CORE ) HB_EXPORT BOOL CALLBACK hb_wvt_gtDlgProcMLess( HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam ) { int iIndex, iType; - long int bReturn = FALSE ; + long int lReturn = 0; PHB_ITEM pFunc = NULL; - PHB_DYNS pDynSym; iType = (int) NULL; @@ -145,92 +144,69 @@ HB_EXPORT BOOL CALLBACK hb_wvt_gtDlgProcMLess( HWND hDlg, UINT message, WPARAM w { switch ( iType ) { - case 1: // Function Name - { - pDynSym = ( PHB_DYNS ) pFunc; - hb_vmPushState(); - hb_vmPushSymbol( hb_dynsymSymbol( pDynSym ) ); - hb_vmPushNil(); - hb_vmPushLong( ( ULONG ) hDlg ); - hb_vmPushLong( ( UINT ) message ); - hb_vmPushLong( ( ULONG ) wParam ); - hb_vmPushLong( ( ULONG ) lParam ); - hb_vmDo( 4 ); - //bReturn = hb_itemGetNL( hb_stackReturnItem() ); - bReturn = hb_parnl( -1 ); - - hb_vmPopState(); - break; - } - - case 2: // Block - { - /* eval the codeblock */ - //if ( _s->pFunc[ iIndex ]->type == HB_IT_BLOCK ) - if ( hb_itemType( _s->pFunc[ iIndex ] ) == HB_IT_BLOCK ) + case 1: /* Function Name */ + if( hb_vmRequestReenter() ) { - PHB_ITEM hihDlg, himessage, hiwParam, hilParam; - PHB_ITEM pReturn; + hb_vmPushDynSym( ( PHB_DYNS ) pFunc ); + hb_vmPushNil(); + hb_vmPushNumInt( ( HB_LONG ) ( HB_PTRDIFF ) hDlg ); + hb_vmPushNumInt( message ); + hb_vmPushNumInt( wParam ); + hb_vmPushNumInt( lParam ); + hb_vmDo( 4 ); + lReturn = hb_parnl( -1 ); + hb_vmRequestRestore(); + } + break; - //hihDlg.type = HB_IT_NIL; - hb_itemPutNL( &hihDlg, (ULONG) hDlg ); - - //himessage.type = HB_IT_NIL; - hb_itemPutNL( &himessage, (ULONG) message ); - - //hiwParam.type = HB_IT_NIL; - hb_itemPutNL( &hiwParam, (ULONG) wParam ); - - //hilParam.type = HB_IT_NIL; - hb_itemPutNL( &hilParam, (ULONG) lParam ); - - pReturn = hb_itemDo( (PHB_ITEM) _s->pFunc[ iIndex ], 4, &hihDlg, &himessage, &hiwParam, &hilParam ); - bReturn = hb_itemGetNL( pReturn ); - hb_itemRelease( pReturn ); + case 2: /* Block */ + /* eval the codeblock */ + if ( HB_IS_BLOCK( pFunc ) ) + { + if( hb_vmRequestReenter() ) + { + hb_vmPushEvalSym(); + hb_vmPush( _s->pFunc[ iIndex ] ); + hb_vmPushNumInt( ( HB_LONG ) ( HB_PTRDIFF ) hDlg ); + hb_vmPushNumInt( message ); + hb_vmPushNumInt( wParam ); + hb_vmPushNumInt( lParam ); + hb_vmSend( 4 ); + lReturn = hb_parnl( -1 ); + hb_vmRequestRestore(); + } } else { - //internal error: missing codeblock + /* TODO: internal error: missing codeblock */ } - - break; - } } } switch( message ) { case WM_COMMAND: - { switch( LOWORD( wParam ) ) { case IDOK: - { DestroyWindow( hDlg ); - bReturn = TRUE; - } - break; + lReturn = 1; + break; case IDCANCEL: - { DestroyWindow( hDlg ); - bReturn = FALSE; - } - break; + lReturn = 0; + break; } - } - break; + break; case WM_CLOSE: - { DestroyWindow( hDlg ); - bReturn = FALSE; - } - break; + lReturn = 0; + break; case WM_NCDESTROY: - { if ( _s->pFunc[ iIndex ] != NULL && _s->iType[ iIndex ] == 2 ) { hb_itemRelease( ( PHB_ITEM ) _s->pFunc[ iIndex ] ); @@ -238,12 +214,11 @@ HB_EXPORT BOOL CALLBACK hb_wvt_gtDlgProcMLess( HWND hDlg, UINT message, WPARAM w _s->hDlgModeless[ iIndex ] = NULL; _s->pFunc[ iIndex ] = NULL; _s->iType[ iIndex ] = (int) NULL; - bReturn = FALSE; - } - break; + lReturn = 0; + break; } - return bReturn; + return lReturn; } //-------------------------------------------------------------------// @@ -251,16 +226,15 @@ HB_EXPORT BOOL CALLBACK hb_wvt_gtDlgProcMLess( HWND hDlg, UINT message, WPARAM w HB_EXPORT BOOL CALLBACK hb_wvt_gtDlgProcModal( HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam ) { int iIndex, iType; - long int bReturn = FALSE ; + long int lReturn = 0; PHB_ITEM pFunc = NULL; - PHB_DYNS pDynSym; int iFirst = ( int ) lParam; if ( iFirst > 0 && iFirst <= WVT_DLGMD_MAX ) { _s->hDlgModal[ iFirst-1 ] = hDlg ; SendMessage( hDlg, WM_INITDIALOG, 0, 0 ); - return ( bReturn ); + return lReturn; } iType = ( int ) NULL; @@ -282,105 +256,81 @@ HB_EXPORT BOOL CALLBACK hb_wvt_gtDlgProcModal( HWND hDlg, UINT message, WPARAM w { switch ( iType ) { - case 1: // Function Name - { - pDynSym = ( PHB_DYNS ) pFunc; - hb_vmPushState(); - hb_vmPushSymbol( hb_dynsymSymbol( pDynSym ) ); - - hb_vmPushNil(); - hb_vmPushLong( ( ULONG ) hDlg ); - hb_vmPushLong( ( UINT ) message ); - hb_vmPushLong( ( ULONG ) wParam ); - hb_vmPushLong( ( ULONG ) lParam ); - hb_vmDo( 4 ); - //bReturn = hb_itemGetNL( hb_stackReturnItem() ); - bReturn = hb_parnl( -1 ); - - hb_vmPopState(); - break; - } - - case 2: // Block - { - /* eval the codeblock */ - if ( hb_itemType( _s->pFuncModal[ iIndex ] ) == HB_IT_BLOCK ) + case 1: /* Function Name */ + if( hb_vmRequestReenter() ) { - PHB_ITEM hihDlg, himessage, hiwParam, hilParam; - PHB_ITEM pReturn; + hb_vmPushDynSym( ( PHB_DYNS ) pFunc ); + hb_vmPushNil(); + hb_vmPushNumInt( ( HB_LONG ) ( HB_PTRDIFF ) hDlg ); + hb_vmPushNumInt( message ); + hb_vmPushNumInt( wParam ); + hb_vmPushNumInt( lParam ); + hb_vmDo( 4 ); + lReturn = hb_parnl( -1 ); + hb_vmRequestRestore(); + } + break; - //hihDlg.type = HB_IT_NIL; - hb_itemPutNL( &hihDlg, (ULONG) hDlg ); - - //himessage.type = HB_IT_NIL; - hb_itemPutNL( &himessage, (ULONG) message ); - - //hiwParam.type = HB_IT_NIL; - hb_itemPutNL( &hiwParam, (ULONG) wParam ); - - //hilParam.type = HB_IT_NIL; - hb_itemPutNL( &hilParam, (ULONG) lParam ); - - pReturn = hb_itemDo( (PHB_ITEM) _s->pFuncModal[ iIndex ], 4, &hihDlg, &himessage, &hiwParam, &hilParam ); - bReturn = hb_itemGetNL( pReturn ); - hb_itemRelease( pReturn ); + case 2: /* Block */ + /* eval the codeblock */ + if ( HB_IS_BLOCK( pFunc ) ) + { + if( hb_vmRequestReenter() ) + { + hb_vmPushEvalSym(); + hb_vmPush( _s->pFunc[ iIndex ] ); + hb_vmPushNumInt( ( HB_LONG ) ( HB_PTRDIFF ) hDlg ); + hb_vmPushNumInt( message ); + hb_vmPushNumInt( wParam ); + hb_vmPushNumInt( lParam ); + hb_vmSend( 4 ); + lReturn = hb_parnl( -1 ); + hb_vmRequestRestore(); + } } else { - //internal error: missing codeblock + /* TODO: internal error: missing codeblock */ } - break; - } } } switch( message ) { case WM_COMMAND: - { switch( LOWORD( wParam ) ) { case IDOK: - { EndDialog( hDlg, IDOK ); - bReturn = TRUE; - } - break; + lReturn = 1; + break; case IDCANCEL: - { EndDialog( hDlg, IDCANCEL ); - bReturn = FALSE; - } - break; + lReturn = 0; + break; } - } - break; + break; case WM_CLOSE: - { EndDialog( hDlg, IDCANCEL ); - bReturn = FALSE; - } - break; + lReturn = 0; + break; case WM_NCDESTROY: - { if ( _s->pFuncModal[ iIndex ] != NULL && _s->iTypeModal[ iIndex ] == 2 ) { hb_itemRelease( ( PHB_ITEM ) _s->pFuncModal[ iIndex ] ); } - - _s->hDlgModal[ iIndex ] = NULL; - _s->pFuncModal[ iIndex ] = NULL; - _s->iTypeModal[ iIndex ] = ( int ) NULL; - bReturn = FALSE; - } - break; + _s->hDlgModal[ iIndex ] = NULL; + _s->pFuncModal[ iIndex ] = NULL; + _s->iTypeModal[ iIndex ] = ( int ) NULL; + lReturn = 0; + break; } - return bReturn; + return lReturn; } //-------------------------------------------------------------------// diff --git a/harbour/include/hbvm.h b/harbour/include/hbvm.h index 485ac96fb8..0adcb4907d 100644 --- a/harbour/include/hbvm.h +++ b/harbour/include/hbvm.h @@ -135,6 +135,7 @@ extern HB_EXPORT void hb_vmPushNumber( double dNumber, int iDec ); /* pushes extern HB_EXPORT void hb_vmPushInteger( int iNumber ); /* pushes a integer number onto the stack */ extern HB_EXPORT void hb_vmPushLong( long lNumber ); /* pushes a long number onto the stack */ extern HB_EXPORT void hb_vmPushDouble( double lNumber, int iDec ); /* pushes a double number onto the stack */ +extern HB_EXPORT void hb_vmPushNumInt( HB_LONG lNumber ); /* pushes a number on to the stack and decides if it is integer or HB_LONG */ extern HB_EXPORT void hb_vmPushLogical( BOOL bValue ); /* pushes a logical value onto the stack */ extern HB_EXPORT void hb_vmPushString( const char * szText, ULONG length ); /* pushes a string on to the stack */ extern HB_EXPORT void hb_vmPushStringPcode( const char * szText, ULONG length ); /* pushes a string from pcode on to the stack */ diff --git a/harbour/source/vm/hvm.c b/harbour/source/vm/hvm.c index f0c08d660b..1a3be84fc6 100644 --- a/harbour/source/vm/hvm.c +++ b/harbour/source/vm/hvm.c @@ -193,7 +193,6 @@ static void hb_vmPushIntegerConst( int iNumber ); /* Pushes a int constant ( #else static void hb_vmPushLongConst( long lNumber ); /* Pushes a long constant (pcode) */ #endif -static void hb_vmPushNumInt( HB_LONG lNumber ); /* pushes a number on to the stack and decides if it is integer or HB_LONG */ static void hb_vmPushNumType( double dNumber, int iDec, int iType1, int iType2 ); /* pushes a number on to the stack and decides if it is integer, long or double */ static void hb_vmPushStatic( USHORT uiStatic ); /* pushes the containts of a static onto the stack */ static void hb_vmPushStaticByRef( USHORT uiStatic ); /* pushes a static by refrence onto the stack */ @@ -5412,14 +5411,6 @@ static int hb_vmCalcIntWidth( HB_LONG lNumber ) return iWidth; } -static void hb_vmPushNumInt( HB_LONG lNumber ) -{ - if( HB_LIM_INT( lNumber ) ) - hb_vmPushInteger( ( int ) lNumber ); - else - hb_vmPushHBLong( lNumber ); -} - HB_EXPORT void hb_vmPushInteger( int iNumber ) { PHB_ITEM pItem = hb_stackAllocItem(); @@ -5497,6 +5488,14 @@ static void hb_vmPushLongLongConst( LONGLONG llNumber ) } #endif +HB_EXPORT void hb_vmPushNumInt( HB_LONG lNumber ) +{ + if( HB_LIM_INT( lNumber ) ) + hb_vmPushInteger( ( int ) lNumber ); + else + hb_vmPushHBLong( lNumber ); +} + HB_EXPORT void hb_vmPushDouble( double dNumber, int iDec ) { PHB_ITEM pItem = hb_stackAllocItem();