From 368508e403759162b0152c4258fb0f1fa69b9840 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Przemys=C5=82aw=20Czerpak?= Date: Sat, 17 Aug 2024 17:37:12 +0200 Subject: [PATCH] 2024-08-17 17:37 UTC+0200 Przemyslaw Czerpak (druzus/at/poczta.onet.pl) * contrib/xhb/xhberror.c % cleaned code] to overload ERRORNEW() with XHB_ERRORNEW() * src/rtl/fscopy.c % removed unnecessary code * src/rtl/vfile.c ! fixed typo in comment * src/vm/dynsym.c + allow to use symbol items as parameter in functions: hb_IsFunction(), __dynsGetIndex(), __dynsIsFun() --- ChangeLog.txt | 14 ++++++++++ contrib/xhb/xhberror.c | 10 ++++--- src/rtl/fscopy.c | 5 ---- src/rtl/vfile.c | 2 +- src/vm/dynsym.c | 61 +++++++++++++++++++++++------------------- 5 files changed, 55 insertions(+), 37 deletions(-) diff --git a/ChangeLog.txt b/ChangeLog.txt index 4817c2226d..aa18dc1652 100644 --- a/ChangeLog.txt +++ b/ChangeLog.txt @@ -7,6 +7,20 @@ Entries may not always be in chronological/commit order. See license at the end of file. */ +2024-08-17 17:37 UTC+0200 Przemyslaw Czerpak (druzus/at/poczta.onet.pl) + * contrib/xhb/xhberror.c + % cleaned code] to overload ERRORNEW() with XHB_ERRORNEW() + + * src/rtl/fscopy.c + % removed unnecessary code + + * src/rtl/vfile.c + ! fixed typo in comment + + * src/vm/dynsym.c + + allow to use symbol items as parameter in functions: + hb_IsFunction(), __dynsGetIndex(), __dynsIsFun() + 2024-07-22 13:37 UTC+0200 Przemyslaw Czerpak (druzus/at/poczta.onet.pl) * contrib/xhb/xhberror.c ! fixed very bad bug introduced in this modification: diff --git a/contrib/xhb/xhberror.c b/contrib/xhb/xhberror.c index d990c15147..efa4e3e91a 100644 --- a/contrib/xhb/xhberror.c +++ b/contrib/xhb/xhberror.c @@ -65,7 +65,10 @@ static HB_SIZE s_nErrProcLine = 0; static HB_SIZE s_nErrProcModule = 0; static HB_SIZE s_nErrCallStack = 0; -static HB_SYMB s_symErrorNew = { "XHB_ERRORNEW", { HB_FS_PUBLIC | HB_FS_LOCAL }, { HB_FUNCNAME( XHB_ERRORNEW ) }, NULL }; +static HB_SYMB s_symXhbErrorNew = { "XHB_ERRORNEW", { HB_FS_PUBLIC | HB_FS_LOCAL }, { HB_FUNCNAME( XHB_ERRORNEW ) }, NULL }; +#ifdef XHB_ERROR_OVERLOAD_ERRORNEW + static HB_SYMB s_symErrorNew = { "ERRORNEW" , { HB_FS_PUBLIC | HB_FS_LOCAL }, { HB_FUNCNAME( XHB_ERRORNEW ) }, NULL }; +#endif static void s_xhbErrorResize( PHB_ITEM pError ) { @@ -342,7 +345,8 @@ static void xhb_errRedefineClass( void * cargo ) PHB_DYNS pDynSym = hb_dynsymFind( "ERRORNEW" ); if( pDynSym ) { - pDynSym->pSymbol->value.pFunPtr = s_symErrorNew.value.pFunPtr; + s_symErrorNew.pDynSym = pDynSym; + pDynSym->pSymbol = &s_symErrorNew; hb_vmSetDynFunc( pDynSym ); } } @@ -353,7 +357,7 @@ static void xhb_errRedefineClass( void * cargo ) } HB_CALL_ON_STARTUP_BEGIN( _xhb_error_init_ ) - hb_dynsymNew( &s_symErrorNew ); + hb_dynsymNew( &s_symXhbErrorNew ); hb_vmAtInit( xhb_errRedefineClass, NULL ); HB_CALL_ON_STARTUP_END( _xhb_error_init_ ) diff --git a/src/rtl/fscopy.c b/src/rtl/fscopy.c index 95af64695a..9b01f5222f 100644 --- a/src/rtl/fscopy.c +++ b/src/rtl/fscopy.c @@ -205,11 +205,6 @@ HB_FUNC( HB_FCOPY ) fResult = hb_fsCopy( pszSource, pszDest ); errCode = hb_fsError(); } - else - { - hb_fsSetFError( 2 /* file not found */ ); - hb_retni( F_ERROR ); - } hb_fsSetFError( errCode ); hb_retni( fResult ? 0 : F_ERROR ); } diff --git a/src/rtl/vfile.c b/src/rtl/vfile.c index 7bc4c2bbcf..26bee6c6a3 100644 --- a/src/rtl/vfile.c +++ b/src/rtl/vfile.c @@ -217,7 +217,7 @@ HB_FUNC( HB_VFCOPYFILE ) hb_retni( iResult ); } -/* hb_vfCopyFile( , , [], [=.t.], [] ) --> */ +/* hb_vfCopyFileEx( , , [], [=.t.], [] ) --> */ HB_FUNC( HB_VFCOPYFILEEX ) { const char * pszSource = hb_parc( 1 ), diff --git a/src/vm/dynsym.c b/src/vm/dynsym.c index 8c0fc8e15e..bbaae58346 100644 --- a/src/vm/dynsym.c +++ b/src/vm/dynsym.c @@ -518,6 +518,26 @@ static PHB_DYNS hb_dynsymGetByIndex( HB_LONG lIndex ) return pDynSym; } +static PHB_DYNS hb_dynsymByItem( PHB_ITEM pItem ) +{ + PHB_DYNS pDynSym = NULL; + + if( pItem ) + { + if( HB_IS_STRING( pItem ) ) + pDynSym = hb_dynsymFindName( pItem->item.asString.value ); + else if( HB_IS_SYMBOL( pItem ) ) + { + pDynSym = pItem->item.asSymbol.value->pDynSym; + if( pDynSym == NULL ) + pDynSym = hb_dynsymFind( pItem->item.asSymbol.value->szName ); + } + else if( HB_IS_NUMERIC( pItem ) ) + pDynSym = hb_dynsymGetByIndex( hb_itemGetNL( pItem ) ); + } + return pDynSym; +} + HB_LONG hb_dynsymCount( void ) { HB_TRACE( HB_TR_DEBUG, ( "hb_dynsymCount()" ) ); @@ -668,53 +688,38 @@ HB_FUNC( __DYNSGETNAME ) /* Get name of symbol: cSymbol = __dynsymGetName( dsInd hb_retc( pDynSym ? pDynSym->pSymbol->szName : NULL ); } -HB_FUNC( __DYNSGETINDEX ) /* Gimme index number of symbol: dsIndex = __dynsymGetIndex( cSymbol ) */ +HB_FUNC( __DYNSGETINDEX ) /* Gimme index number of symbol: dsIndex = __dynsymGetIndex( cSymbol | sSymbol ) */ { HB_STACK_TLS_PRELOAD HB_SYMCNT uiPos = 0; - const char * szName = hb_parc( 1 ); + PHB_DYNS pDynSym = hb_dynsymByItem( hb_param( 1, HB_IT_STRING | HB_IT_SYMBOL ) ); - if( szName ) + if( pDynSym ) { - PHB_DYNS pDynSym = hb_dynsymFindName( szName ); - if( pDynSym ) - { - HB_DYNSYM_LOCK(); - if( hb_dynsymPos( pDynSym->pSymbol->szName, &uiPos ) ) - ++uiPos; - else - uiPos = 0; - HB_DYNSYM_UNLOCK(); - } + HB_DYNSYM_LOCK(); + if( hb_dynsymPos( pDynSym->pSymbol->szName, &uiPos ) ) + ++uiPos; + else + uiPos = 0; + HB_DYNSYM_UNLOCK(); } - hb_retnint( uiPos ); } HB_FUNC( HB_ISFUNCTION ) /* returns .T. if a symbol has a function/procedure pointer, - given its name */ + given its symbol or name */ { HB_STACK_TLS_PRELOAD - const char * szProc = hb_parc( 1 ); - HB_BOOL fResult = HB_FALSE; + PHB_DYNS pDynSym = hb_dynsymByItem( hb_param( 1, HB_IT_STRING | HB_IT_SYMBOL ) ); - if( szProc ) - { - PHB_DYNS pDynSym = hb_dynsymFindName( szProc ); - if( pDynSym ) - fResult = hb_dynsymIsFunction( pDynSym ); - } - - hb_retl( fResult ); + hb_retl( pDynSym && hb_dynsymIsFunction( pDynSym ) ); } HB_FUNC( __DYNSISFUN ) /* returns .T. if a symbol has a function/procedure pointer, given its symbol index or name */ { HB_STACK_TLS_PRELOAD - const char * szName = hb_parc( 1 ); - PHB_DYNS pDynSym = szName ? hb_dynsymFindName( szName ) : - hb_dynsymGetByIndex( hb_parnl( 1 ) ); + PHB_DYNS pDynSym = hb_dynsymByItem( hb_param( 1, HB_IT_STRING | HB_IT_SYMBOL | HB_IT_NUMERIC ) ); hb_retl( pDynSym && hb_dynsymIsFunction( pDynSym ) ); }