diff --git a/harbour/ChangeLog b/harbour/ChangeLog index 736cac7329..803bd1d0eb 100644 --- a/harbour/ChangeLog +++ b/harbour/ChangeLog @@ -17,6 +17,21 @@ past entries belonging to author(s): Viktor Szakats. */ +2009-06-23 18:15 UTC+0200 Viktor Szakats (harbour.01 syenar.hu) + * include/hbapi.h + * include/hbapiitm.h + * source/vm/itemapi.c + * source/vm/arrays.c + * source/vm/extend.c + ! Fixed hb_parvc() function to return NULL in case an array + is passed as Harbour level parameter. This makes this function + (and _parc()) fully CA-Cl*pper compatible. + ; Please review maybe there is a lighter patch to achieve this + goal. I had to add NULL versions for two functions downstream. + + * utils/hbmk2/hbmk2.prg + * Formatting. + 2009-06-23 17:14 UTC+0200 Viktor Szakats (harbour.01 syenar.hu) * INSTALL + Added section: diff --git a/harbour/include/hbapi.h b/harbour/include/hbapi.h index eb28b69797..2bc03ce8f4 100644 --- a/harbour/include/hbapi.h +++ b/harbour/include/hbapi.h @@ -778,6 +778,7 @@ extern HB_EXPORT PHB_ITEM hb_arrayGetItemPtr( PHB_ITEM pArray, ULONG ulIndex ); extern HB_EXPORT ULONG hb_arrayCopyC( PHB_ITEM pArray, ULONG ulIndex, char * szBuffer, ULONG ulLen ); /* copy a string into an array item */ extern HB_EXPORT char * hb_arrayGetC( PHB_ITEM pArray, ULONG ulIndex ); /* retrieves the string contained on an array element */ extern HB_EXPORT char * hb_arrayGetCPtr( PHB_ITEM pArray, ULONG ulIndex ); /* retrieves the string pointer on an array element */ +extern HB_EXPORT char * hb_arrayGetCPtrNULL( PHB_ITEM pArray, ULONG ulIndex ); /* retrieves the string pointer on an array element. Returns NULL on error. */ extern HB_EXPORT ULONG hb_arrayGetCLen( PHB_ITEM pArray, ULONG ulIndex ); /* retrieves the string length contained on an array element */ extern HB_EXPORT void * hb_arrayGetPtr( PHB_ITEM pArray, ULONG ulIndex ); /* retrieves the pointer contained on an array element */ extern HB_EXPORT void * hb_arrayGetPtrGC( PHB_ITEM pArray, ULONG ulIndex, HB_GARBAGE_FUNC_PTR pFunc ); /* retrieves the GC pointer contained on an array element */ diff --git a/harbour/include/hbapiitm.h b/harbour/include/hbapiitm.h index 8e6085e71b..b421551f10 100644 --- a/harbour/include/hbapiitm.h +++ b/harbour/include/hbapiitm.h @@ -86,6 +86,7 @@ extern HB_EXPORT ULONG hb_itemCopyC ( PHB_ITEM pItem, char * szBuffer, extern HB_EXPORT BOOL hb_itemFreeC ( char * szText ); extern HB_EXPORT char * hb_itemGetC ( PHB_ITEM pItem ); extern HB_EXPORT char * hb_itemGetCPtr ( PHB_ITEM pItem ); +extern HB_EXPORT char * hb_itemGetCPtrNULL( PHB_ITEM pItem ); extern HB_EXPORT ULONG hb_itemGetCLen ( PHB_ITEM pItem ); extern HB_EXPORT char * hb_itemGetDS ( PHB_ITEM pItem, char * szDate ); extern HB_EXPORT char * hb_itemGetTS ( PHB_ITEM pItem, char * szDateTime ); diff --git a/harbour/source/vm/arrays.c b/harbour/source/vm/arrays.c index 3b1e9c9730..04f20ee75b 100644 --- a/harbour/source/vm/arrays.c +++ b/harbour/source/vm/arrays.c @@ -218,14 +218,14 @@ BOOL hb_arraySize( PHB_ITEM pArray, ULONG ulLen ) { if( pBaseArray->ulAllocated < ulLen ) { - /* + /* A common practice is to double allocation buffer size. Thus, making reallocation count logarithmic to total number of added numbers. - I've used here a little different formula. ulAllocated is divided by - factor 2 ( >> 1 ) and 1 is added to requested size. This algorithm + I've used here a little different formula. ulAllocated is divided by + factor 2 ( >> 1 ) and 1 is added to requested size. This algorithm has properties: - reallocation count remains asymptoticaly logarithmic; - - saves memory for large arrays, because reallocation buffer + - saves memory for large arrays, because reallocation buffer size is not doubled, but multiplied by 1.5; - adding of 1, allows reduce reallocation count for small arrays. */ @@ -622,6 +622,19 @@ char * hb_arrayGetCPtr( PHB_ITEM pArray, ULONG ulIndex ) return ( char * ) ""; } +/* Variant of hb_arrayGetCPtr() to provide Cl*pper compatibility. + [vszakats] */ + +char * hb_arrayGetCPtrNULL( PHB_ITEM pArray, ULONG ulIndex ) +{ + HB_TRACE(HB_TR_DEBUG, ("hb_arrayGetCPtr(%p, %lu)", pArray, ulIndex)); + + if( HB_IS_ARRAY( pArray ) && ulIndex > 0 && ulIndex <= pArray->item.asArray.value->ulLen ) + return hb_itemGetCPtrNULL( pArray->item.asArray.value->pItems + ulIndex - 1 ); + else + return ( char * ) NULL; +} + ULONG hb_arrayGetCLen( PHB_ITEM pArray, ULONG ulIndex ) { HB_TRACE(HB_TR_DEBUG, ("hb_arrayGetCLen(%p, %lu)", pArray, ulIndex)); diff --git a/harbour/source/vm/extend.c b/harbour/source/vm/extend.c index ae05e78ee6..4153c60d5b 100644 --- a/harbour/source/vm/extend.c +++ b/harbour/source/vm/extend.c @@ -634,7 +634,7 @@ char * hb_parvc( int iParam, ... ) ulArrayIndex = va_arg( va, ULONG ); va_end( va ); - return hb_arrayGetCPtr( pItem, ulArrayIndex ); + return hb_arrayGetCPtrNULL( pItem, ulArrayIndex ); } } diff --git a/harbour/source/vm/itemapi.c b/harbour/source/vm/itemapi.c index 276fb38483..f1b69b17ea 100644 --- a/harbour/source/vm/itemapi.c +++ b/harbour/source/vm/itemapi.c @@ -465,6 +465,19 @@ char * hb_itemGetCPtr( PHB_ITEM pItem ) return ( char * ) ""; } +/* Variant of hb_itemGetCPtr() to provide Cl*pper compatibility. + [vszakats] */ + +char * hb_itemGetCPtrNULL( PHB_ITEM pItem ) +{ + HB_TRACE(HB_TR_DEBUG, ("hb_itemGetCPtrNULL(%p)", pItem)); + + if( pItem && HB_IS_STRING( pItem ) ) + return pItem->item.asString.value; + else + return ( char * ) NULL; +} + ULONG hb_itemGetCLen( PHB_ITEM pItem ) { HB_TRACE(HB_TR_DEBUG, ("hb_itemGetCLen(%p)", pItem)); diff --git a/harbour/utils/hbmk2/hbmk2.prg b/harbour/utils/hbmk2/hbmk2.prg index 4122383f30..f17951f97e 100644 --- a/harbour/utils/hbmk2/hbmk2.prg +++ b/harbour/utils/hbmk2/hbmk2.prg @@ -5540,7 +5540,6 @@ STATIC FUNCTION IsValidHarbourID( cName ) ENDIF RETURN .F. - STATIC FUNCTION FuncNameEncode( cName ) LOCAL cResult, c