diff --git a/harbour/ChangeLog b/harbour/ChangeLog index ed544e33d7..99d27f4378 100644 --- a/harbour/ChangeLog +++ b/harbour/ChangeLog @@ -8,6 +8,38 @@ 2002-12-01 13:30 UTC+0100 Foo Bar */ + ! fixed casting for C++ compilation + + * harbour/source/compiler/harbour.c + ! fixed removing locals frame - bSkipFrame was not initialized + + * harbour/include/hbapi.h + * harbour/source/vm/estack.c + * harbour/source/vm/hvm.c + * harbour/source/vm/itemapi.c + * harbour/source/vm/proc.c + * moved current line number information from hb_struSymbol + to current stack state to keep 16 bytes size for HB_ITEM + on 32bit systems with 4 bytes alignment + +2006-09-20 18:40 UTC+0200 Przemyslaw Czerpak (druzus/at/priv.onet.pl) + * harbour/contrib/rdd_ads/ads1.c + * synced with recent xHarbour fixes + + * harbour/include/hbdefs.h + * indenting + + * harbour/include/hbexprb.c + * harbour/include/hbexprop.h + * harbour/source/common/expropt2.c + + added compile time optimization for STOD(cConstDateString) + covered by -kh compiler extension (default) + It allows to keep the same source code for Clipper and + Harbour and benefits from data constants without using + 0dYYYYMMDD values + + * harbour/source/vm/classes.c + * restored the original 3-rd parameter in hb_clsAdd to void(void) - PHB_FUNC - and added translation for PHB_SYMB to not force using [P]HB_SYMB in 3-rd party code diff --git a/harbour/contrib/rdd_ads/ads1.c b/harbour/contrib/rdd_ads/ads1.c index b70163ae8d..fef4e056b6 100644 --- a/harbour/contrib/rdd_ads/ads1.c +++ b/harbour/contrib/rdd_ads/ads1.c @@ -2341,10 +2341,10 @@ static ERRCODE adsClose( ADSAREAP pArea ) static ERRCODE adsCreate( ADSAREAP pArea, LPDBOPENINFO pCreateInfo ) { ADSHANDLE hTable, hConnection; - UNSIGNED32 uRetVal, u32Length; - UNSIGNED8 *ucfieldDefs; + UNSIGNED32 uRetVal, u32Length, uiFldLen, uiLen; + UNSIGNED8 *ucfieldDefs, *ucfieldPtr ; UNSIGNED8 ucBuffer[MAX_STR_LEN + 1], ucField[ADS_MAX_FIELD_NAME + 1]; - USHORT uiCount, uiLen; + USHORT uiCount; LPFIELD pField; char cType[8]; @@ -2361,11 +2361,25 @@ static ERRCODE adsCreate( ADSAREAP pArea, LPDBOPENINFO pCreateInfo ) there are up to 4 punctuation symbols ( ,; ), field length (8) and number of decimals (2). So, per field it should be ( 6 + 4 + 8 + 2 = 20 ): - uiMaxFieldNameLength + 20 */ - uiLen = ( pArea->uiFieldCount * (pArea->uiMaxFieldNameLength + 20) ) + 1; + uiMaxFieldNameLength + 20 + + * 9/19/2006 BH: this is an oversized buffer since most fields don't have + * 128-byte names. But the overhead in counting up the bytes is worse than + * allocating a bigger buffer. We need to make sure it's not too big, though. + * ADS docs say max # of fields is fnameLen + 10 + * 65135 / ( 10 + AverageFieldNameLength ) + */ + + uiLen = ( UNSIGNED32 ) pArea->uiFieldCount * (pArea->uiMaxFieldNameLength + 20) + 1; + if ( uiLen > 65135 ) + { + uiLen = 65135; + } ucfieldDefs = (UNSIGNED8 *) hb_xgrab( uiLen ); ucfieldDefs[0]='\0'; + ucfieldPtr = ucfieldDefs; + pField = pArea->lpFields; for( uiCount = 0; uiCount < pArea->uiFieldCount; uiCount++ ) { @@ -2374,7 +2388,7 @@ static ERRCODE adsCreate( ADSAREAP pArea, LPDBOPENINFO pCreateInfo ) pArea->maxFieldLen = pField->uiLen; } - switch ( pField->uiType ) + switch( pField->uiType ) { case HB_IT_DATE: if( pField->uiTypeExtended == 0 ) @@ -2453,47 +2467,62 @@ static ERRCODE adsCreate( ADSAREAP pArea, LPDBOPENINFO pCreateInfo ) strcpy( cType, "CurD" ); } break; - } - switch ( pField->uiType ) - { - case HB_IT_DATE: - case HB_IT_LOGICAL: - case HB_IT_MEMO: + } + + switch( pField->uiType ) + { + case HB_IT_DATE: + case HB_IT_LOGICAL: + case HB_IT_MEMO: if( pField->uiTypeExtended != ADS_VARCHAR ) { char * szName = hb_dynsymName( ( PHB_DYNS ) pField->sym ); if( strlen( szName ) > (unsigned int) pArea->uiMaxFieldNameLength ) { - strncpy( (char*)ucField, szName, pArea->uiMaxFieldNameLength ); - sprintf( (char*)ucBuffer, "%s,%s;", ucField, cType ); + strncpy( (char*)ucField, szName, pArea->uiMaxFieldNameLength ); + uiFldLen = sprintf( (char*)ucBuffer, "%s,%s;", ucField, cType ); } else { - sprintf( (char*)ucBuffer, "%s,%s;", szName, cType ); + uiFldLen = sprintf( (char*)ucBuffer, "%s,%s;", szName, cType ); } break; } - default: + default: + { + char * szName ; + szName = hb_dynsymName( ( PHB_DYNS ) pField->sym ); + if( strlen( szName) > (unsigned int) pArea->uiMaxFieldNameLength ) { - char * szName = hb_dynsymName( ( PHB_DYNS ) pField->sym ); - if( strlen( szName) > (unsigned int) pArea->uiMaxFieldNameLength ) - { - strncpy( (char*)ucField, szName, pArea->uiMaxFieldNameLength ); - sprintf( (char*)ucBuffer, "%s,%s,%d,%d;", ucField, cType, pField->uiLen, pField->uiDec ); - } - else - { - sprintf( (char*)ucBuffer, "%s,%s,%d,%d;", szName, cType, pField->uiLen, pField->uiDec ); - } - break; + strncpy( (char*)ucField, szName, pArea->uiMaxFieldNameLength ); + uiFldLen = sprintf( (char*)ucBuffer, "%s,%s,%d,%d;", ucField, cType, pField->uiLen, pField->uiDec ); } - } + else + { + uiFldLen = sprintf( (char*)ucBuffer, "%s,%s,%d,%d;", szName, cType, pField->uiLen, pField->uiDec ); + } + break; + } + } - strcat( (char*)ucfieldDefs, (char*)ucBuffer ); - pField++; + if( uiFldLen == 0 ) + { + uiFldLen = strlen( ucBuffer ); // should have been set by sprintf above. + } + if( uiFldLen >= uiLen ) + { + /* RT_ERROR; probably too many fields */ + return FAILURE; + } + memcpy( ucfieldPtr, ucBuffer, uiFldLen ); + uiLen -= uiFldLen; + ucfieldPtr += uiFldLen; + + pField++; } - /* printf( "\n%s",(char*)ucfieldDefs ); */ + *ucfieldPtr = '\0'; + uRetVal = AdsCreateTable( hConnection, pCreateInfo->abName, pCreateInfo->atomAlias, pArea->iFileType, adsCharType, adsLockType, adsRights, @@ -2507,7 +2536,7 @@ static ERRCODE adsCreate( ADSAREAP pArea, LPDBOPENINFO pCreateInfo ) return FAILURE; } /* - * In Clipper CREATE() keeps darabase open on success [druzus] + * In Clipper CREATE() keeps database open on success [druzus] */ pArea->hTable = hTable; pArea->fShared = FALSE; /* pCreateInfo->fShared; */ diff --git a/harbour/include/hbapi.h b/harbour/include/hbapi.h index 5b414a9152..b15218f6a8 100644 --- a/harbour/include/hbapi.h +++ b/harbour/include/hbapi.h @@ -322,8 +322,8 @@ struct hb_struSymbol PHB_SYMB value; PHB_STACK_STATE stackstate; /* function stack state */ USHORT lineno; - USHORT paramcnt; /* number of passed parameters in function call */ - USHORT paramdeclcnt; /* number of declared parameters in function definition */ + USHORT paramcnt; /* number of passed parameters in function call */ + USHORT paramdeclcnt; /* number of declared parameters in function definition */ }; /* items hold at the virtual machine stack */ diff --git a/harbour/include/hbdefs.h b/harbour/include/hbdefs.h index 94b3b9c35e..d1e8b875a1 100644 --- a/harbour/include/hbdefs.h +++ b/harbour/include/hbdefs.h @@ -192,7 +192,7 @@ #if defined(__GNUC__) typedef long long LONGLONG; #else - typedef __int64 LONGLONG; + typedef __int64 LONGLONG; #endif #endif #if !defined(ULONGLONG) diff --git a/harbour/include/hbexprb.c b/harbour/include/hbexprb.c index b4cf5ae2f3..5305052804 100644 --- a/harbour/include/hbexprb.c +++ b/harbour/include/hbexprb.c @@ -1673,6 +1673,11 @@ static HB_EXPR_FUNC( hb_compExprUseFunCall ) if( HB_COMP_ISSUPPORTED(HB_COMPFLAG_HARBOUR) ) hb_compExprReduceASC( pSelf, HB_MACRO_PARAM ); } + else if( ( strcmp( "STOD", pName->value.asSymbol ) == 0 ) && usCount ) + { + if( HB_COMP_ISSUPPORTED(HB_COMPFLAG_HARBOUR) ) + hb_compExprReduceSTOD( pSelf, HB_MACRO_PARAM ); + } } } break; diff --git a/harbour/include/hbexprop.h b/harbour/include/hbexprop.h index 903deca35e..fe16d7a578 100644 --- a/harbour/include/hbexprop.h +++ b/harbour/include/hbexprop.h @@ -393,6 +393,7 @@ BOOL hb_compExprReduceAT( HB_EXPR_PTR, HB_MACRO_DECL ); BOOL hb_compExprReduceCHR( HB_EXPR_PTR, HB_MACRO_DECL ); BOOL hb_compExprReduceLEN( HB_EXPR_PTR, HB_MACRO_DECL ); BOOL hb_compExprReduceASC( HB_EXPR_PTR, HB_MACRO_DECL ); +BOOL hb_compExprReduceSTOD( HB_EXPR_PTR pSelf, HB_MACRO_DECL ); BOOL hb_compExprIsValidMacro( char *, BOOL *, HB_MACRO_DECL ); #ifdef HB_MACRO_SUPPORT diff --git a/harbour/source/common/expropt2.c b/harbour/source/common/expropt2.c index 35033c8ada..7f41f50dcc 100644 --- a/harbour/source/common/expropt2.c +++ b/harbour/source/common/expropt2.c @@ -68,6 +68,7 @@ #include #include "hbmacro.h" #include "hbcomp.h" +#include "hbdate.h" HB_EXPR_PTR hb_compExprReduceMod( HB_EXPR_PTR pSelf, HB_MACRO_DECL ) { @@ -1281,3 +1282,21 @@ BOOL hb_compExprReduceASC( HB_EXPR_PTR pSelf, HB_MACRO_DECL ) } return FALSE; } + +BOOL hb_compExprReduceSTOD( HB_EXPR_PTR pSelf, HB_MACRO_DECL ) +{ + HB_EXPR_PTR pParms = pSelf->value.asFunCall.pParms; + HB_EXPR_PTR pArg = pParms->value.asList.pExprList; + + if( pArg->ExprType == HB_ET_STRING && pArg->ulLength == 8 ) + { + HB_EXPR_PTR pExpr = hb_compExprNewDate( hb_dateEncStr( pArg->value.asString.string ) ); + + hb_compExprFree( pParms, HB_MACRO_PARAM ); + hb_compExprFree( pSelf->value.asFunCall.pFunName, HB_MACRO_PARAM ); + memcpy( pSelf, pExpr, sizeof( HB_EXPR ) ); + hb_compExprClear( pExpr ); + return TRUE; + } + return FALSE; +} diff --git a/harbour/source/vm/classes.c b/harbour/source/vm/classes.c index 4f7b5f83b5..eee3a73c31 100644 --- a/harbour/source/vm/classes.c +++ b/harbour/source/vm/classes.c @@ -3230,9 +3230,12 @@ HB_FUNC( HB_SETCLSHANDLE ) /* ( oObject, nClassHandle ) --> nPrevClassHandle */ /* Harbour equivalent for Clipper internal __mdCreate() */ USHORT hb_clsCreate( USHORT usSize, char * szClassName ) { - PHB_DYNS pDynSym = hb_dynsymGet( "__CLSNEW" ); + static PHB_DYNS pDynSym = NULL; - hb_vmPushSymbol( pDynSym->pSymbol ); + if( pDynSym == NULL ) + pDynSym = hb_dynsymGet( "__CLSNEW" ); + + hb_vmPushDynSym( pDynSym ); hb_vmPushNil(); hb_vmPushString( szClassName, strlen( szClassName ) ); hb_vmPushLong( usSize ); @@ -3242,26 +3245,41 @@ USHORT hb_clsCreate( USHORT usSize, char * szClassName ) } /* Harbour equivalent for Clipper internal __mdAdd() */ -void hb_clsAdd( USHORT usClassH, char * szMethodName, PHB_SYMB pFuncSym ) +void hb_clsAdd( USHORT usClassH, char * szMethodName, PHB_FUNC pFuncPtr ) { - PHB_DYNS pDynSym = hb_dynsymGet( "__CLSADDMSG" ); + static PHB_DYNS pDynSym = NULL; + PHB_SYMB pExecSym; - hb_vmPushSymbol( pDynSym->pSymbol ); + /* + * We can use empty name "" for this symbol in hb_symbolNew() + * It's only envelop for function with additional execution + * information for HVM not registered symbol. [druzus] + */ + pExecSym = hb_symbolNew( "" ); + pExecSym->value.pFunPtr = pFuncPtr; + + if( pDynSym == NULL ) + pDynSym = hb_dynsymGet( "__CLSADDMSG" ); + + hb_vmPushDynSym( pDynSym ); hb_vmPushNil(); - hb_vmPushLong( usClassH ); + hb_vmPushInteger( usClassH ); hb_vmPushString( szMethodName, strlen( szMethodName ) ); - hb_vmPushSymbol( pFuncSym ); + hb_vmPushSymbol( pExecSym ); hb_vmFunction( 3 ); } /* Harbour equivalent for Clipper internal __mdAssociate() */ void hb_clsAssociate( USHORT usClassH ) { - PHB_DYNS pDynSym = hb_dynsymGet( "__CLSINST" ); + static PHB_DYNS pDynSym = NULL; - hb_vmPushSymbol( pDynSym->pSymbol ); + if( pDynSym == NULL ) + pDynSym = hb_dynsymGet( "__CLSINST" ); + + hb_vmPushDynSym( pDynSym ); hb_vmPushNil(); - hb_vmPushLong( usClassH ); + hb_vmPushInteger( usClassH ); hb_vmFunction( 1 ); } diff --git a/harbour/source/vm/estack.c b/harbour/source/vm/estack.c index ca56679482..b2eb393bb5 100644 --- a/harbour/source/vm/estack.c +++ b/harbour/source/vm/estack.c @@ -441,7 +441,7 @@ LONG hb_stackBaseProcOffset( int iLevel ) while( iLevel-- > 0 && lOffset > 0 ) lOffset = ( * ( hb_stack.pItems + lOffset ) )->item.asSymbol.stackstate->lBaseItem; - if( iLevel < 0 ) + if( iLevel < 0 && ( lOffset > 0 || HB_IS_SYMBOL( * hb_stack.pItems ) ) ) return lOffset; else return -1; diff --git a/harbour/source/vm/itemapi.c b/harbour/source/vm/itemapi.c index ffc3375a53..14fa1b87c2 100644 --- a/harbour/source/vm/itemapi.c +++ b/harbour/source/vm/itemapi.c @@ -1272,12 +1272,16 @@ HB_EXPORT void hb_itemClear( PHB_ITEM pItem ) else if( type & HB_IT_BLOCK ) hb_gcRefFree( pItem->item.asBlock.value ); - else if( type & HB_IT_MEMVAR ) - hb_memvarValueDecRef( pItem->item.asMemvar.value ); - else if( type & HB_IT_BYREF ) { - if( pItem->item.asRefer.offset == 0 && pItem->item.asRefer.value >= 0 ) + if( type & HB_IT_MEMVAR ) + hb_memvarValueDecRef( pItem->item.asMemvar.value ); + + else if( type & HB_IT_ENUM ) /* FOR EACH control variable */ + hb_vmEnumRelease( pItem->item.asEnum.basePtr, + pItem->item.asEnum.valuePtr ); + + else if( pItem->item.asRefer.offset == 0 && pItem->item.asRefer.value >= 0 ) hb_gcRefFree( pItem->item.asRefer.BasePtr.array ); } else if( type & HB_IT_POINTER ) @@ -1285,11 +1289,6 @@ HB_EXPORT void hb_itemClear( PHB_ITEM pItem ) if( pItem->item.asPointer.collect ) hb_gcRefFree( pItem->item.asPointer.value ); } - else if( type & HB_IT_ENUM ) /* FOR EACH control variable */ - { - hb_vmEnumRelease( pItem->item.asEnum.basePtr, - pItem->item.asEnum.valuePtr ); - } } /* Internal API, not standard Clipper */