2001-04-17 19:30 UTC-0800 Ron Pinkas <ron@profit-master.com>

* include/hbapi.h
     + Added typedef struct HB_NESTED_CLONED
     * Changed declaration of hb_arrayClone to hb_arrayClone( PHB_ITEM pArray, PHB_NESTED_CLONED pClonedList, BOOL *bCyclic )

   * source/vm/arrays.c
     ! Fixed hb_arrayClone() to correctly clone any array including RELATIVE Ciclic Referncing of any level.

   * source/vm/arrayshb.c
   * source/vm/classes.c
   * source/vm/hvm.c
     * Changed calls to hb_arrayClone() to pass 2 additional NULLs as 2nd. and 3rd. parameters.
This commit is contained in:
Ron Pinkas
2001-04-18 02:28:39 +00:00
parent dabef65e18
commit e21cb2b118
6 changed files with 121 additions and 26 deletions

View File

@@ -1,5 +1,17 @@
2001-04-17 17:15 UTC-0400 David G. Holm <dholm@jsd-llc.com>
2001-04-17 19:30 UTC-0800 Ron Pinkas <ron@profit-master.com>
* include/hbapi.h
+ Added typedef struct HB_NESTED_CLONED
* Changed declaration of hb_arrayClone to hb_arrayClone( PHB_ITEM pArray, PHB_NESTED_CLONED pClonedList, BOOL *bCyclic )
* source/vm/arrays.c
! Fixed hb_arrayClone() to correctly clone any array including RELATIVE Ciclic Referncing of any level.
* source/vm/arrayshb.c
* source/vm/classes.c
* source/vm/hvm.c
* Changed calls to hb_arrayClone() to pass 2 additional NULLs as 2nd. and 3rd. parameters.
2001-04-17 17:15 UTC-0400 David G. Holm <dholm@jsd-llc.com>
* hb_slex.bc
* hb_slex.vc
* makefile.bc

View File

@@ -256,6 +256,13 @@ typedef struct _HB_VALUE
HB_HANDLE hPrevMemvar;
} HB_VALUE, * PHB_VALUE, * HB_VALUE_PTR;
typedef struct _HB_NESTED_CLONED
{
PHB_ITEM pSrc;
PHB_ITEM pDest;
struct _HB_NESTED_CLONED * pNext;
} HB_NESTED_CLONED, * PHB_NESTED_CLONED;
/* RDD method return codes */
typedef USHORT ERRCODE;
#define SUCCESS 0
@@ -378,7 +385,7 @@ extern BOOL hb_arrayFill( PHB_ITEM pArray, PHB_ITEM pValue, ULONG * pulStart
extern ULONG hb_arrayScan( PHB_ITEM pArray, PHB_ITEM pValue, ULONG * pulStart, ULONG * pulCount ); /* scan an array for a given item, or until code-block item returns TRUE */
extern BOOL hb_arrayEval( PHB_ITEM pArray, PHB_ITEM bBlock, ULONG * pulStart, ULONG * pulCount ); /* execute a code-block for every element of an array item */
extern BOOL hb_arrayCopy( PHB_ITEM pSrcArray, PHB_ITEM pDstArray, ULONG * pulStart, ULONG * pulCount, ULONG * pulTarget ); /* copy items from one array to another */
extern PHB_ITEM hb_arrayClone( PHB_ITEM pArray ); /* returns a duplicate of an existing array, including all nested items */
extern PHB_ITEM hb_arrayClone( PHB_ITEM pArray, PHB_NESTED_CLONED pClonedList, BOOL *bCyclic ); /* returns a duplicate of an existing array, including all nested items */
extern BOOL hb_arraySort( PHB_ITEM pArray, ULONG * pulStart, ULONG * pulCount, PHB_ITEM pBlock ); /* sorts an array item */
extern PHB_ITEM hb_arrayFromStack( USHORT uiLen ); /* Creates and returns an Array of n Elements from the Eval Stack - Does NOT pop the items. */
extern PHB_ITEM hb_arrayFromParams( void ); /* Creates and returns an Array of current Generic Parameters. */

View File

@@ -700,11 +700,9 @@ BOOL hb_arrayCopy( PHB_ITEM pSrcArray, PHB_ITEM pDstArray, ULONG * pulStart,
return FALSE;
}
PHB_ITEM hb_arrayClone( PHB_ITEM pSrcArray )
PHB_ITEM hb_arrayClone( PHB_ITEM pSrcArray, PHB_NESTED_CLONED pClonedList, BOOL *bCyclic )
{
PHB_ITEM pDstArray = hb_itemNew( NULL );
HB_TRACE(HB_TR_DEBUG, ("hb_arrayClone(%p)", pSrcArray));
HB_TRACE(HB_TR_DEBUG, ("hb_arrayClone(%p, %p)", pSrcArray, pClonedList));
if( HB_IS_ARRAY( pSrcArray ) )
{
@@ -712,7 +710,52 @@ PHB_ITEM hb_arrayClone( PHB_ITEM pSrcArray )
PHB_BASEARRAY pDstBaseArray;
ULONG ulSrcLen = pSrcBaseArray->ulLen;
ULONG ulCount;
PHB_ITEM pDstArray;
PHB_NESTED_CLONED pCloned;
BOOL bTop;
if( pClonedList )
{
bTop = FALSE;
/* Broken down like this to avoid redandant comparisons. */
pCloned = pClonedList;
if( pCloned->pSrc == pSrcArray )
{
if( bCyclic )
{
*bCyclic = TRUE;
}
return pCloned->pDest;
}
while( pCloned->pNext )
{
pCloned = pCloned->pNext;
if( pCloned->pSrc == pSrcArray )
{
if( bCyclic )
{
*bCyclic = TRUE;
}
return pCloned->pDest;
}
}
if( pCloned->pSrc == pSrcArray )
{
if( bCyclic )
{
*bCyclic = TRUE;
}
return pCloned->pDest;
}
}
else
{
bTop = TRUE;
}
pDstArray = hb_itemNew( NULL );
hb_arrayNew( pDstArray, ulSrcLen );
pDstBaseArray = pDstArray->item.asArray.value;
@@ -721,28 +764,61 @@ PHB_ITEM hb_arrayClone( PHB_ITEM pSrcArray )
for( ulCount = 0; ulCount < ulSrcLen; ulCount++ )
{
PHB_ITEM pSrcItem = pSrcBaseArray->pItems + ulCount;
BOOL bDontRelease = FALSE;
if( pSrcItem->type == HB_IT_ARRAY )
{
/* Circular. */
if( pSrcItem == pSrcArray )
PHB_ITEM pClone;
if( bTop )
{
hb_itemArrayPut( pDstArray, ulCount + 1, pDstArray );
/* Top Level - create an empty list. */
pClonedList = ( PHB_NESTED_CLONED ) hb_xgrab( sizeof( HB_NESTED_CLONED ) );
pCloned = pClonedList;
}
else
{
PHB_ITEM pClone = hb_arrayClone( pSrcItem );
/* pCloned must alreay point to last item in the list (see above). */
pCloned->pNext = ( PHB_NESTED_CLONED ) hb_xgrab( sizeof( HB_NESTED_CLONED ) );
pCloned = pCloned->pNext;
}
hb_itemArrayPut( pDstArray, ulCount + 1, pClone );
pCloned->pSrc = pSrcArray;
pCloned->pDest = pDstArray;
pCloned->pNext = NULL;
pClone = hb_arrayClone( pSrcItem, pClonedList, &bDontRelease );
hb_itemArrayPut( pDstArray, ulCount + 1, pClone );
if( ! bDontRelease )
{
hb_itemRelease( pClone );
}
/* Top Level - Release the created list. */
if( bTop )
{
while( pClonedList->pNext )
{
pCloned = pClonedList;
pClonedList = pClonedList->pNext;
hb_xfree( pCloned );
}
hb_xfree( pClonedList );
}
}
else
{
hb_itemArrayPut( pDstArray, ulCount + 1, pSrcItem );
}
}
}
return pDstArray;
return pDstArray;
}
else
{
return hb_itemNew( NULL );
}
}
PHB_ITEM hb_arrayFromStack( USHORT uiLen )

View File

@@ -288,6 +288,6 @@ HB_FUNC( ACLONE )
PHB_ITEM pSrcArray = hb_param( 1, HB_IT_ARRAY );
if( pSrcArray && ! hb_arrayIsObject( pSrcArray ) )
hb_itemRelease( hb_itemReturn( hb_arrayClone( pSrcArray ) ) ); /* AClone() returns the new array */
hb_itemRelease( hb_itemReturn( hb_arrayClone( pSrcArray, NULL, NULL ) ) ); /* AClone() returns the new array */
}

View File

@@ -823,7 +823,7 @@ HB_FUNC( __CLSADDMSG )
if( pInit && ! HB_IS_NIL( pInit ) ) /* Initializer found */
{
if( HB_IS_ARRAY( pInit ) )
pNewMeth->pInitValue = hb_arrayClone( pInit );
pNewMeth->pInitValue = hb_arrayClone( pInit, NULL, NULL );
else
{
pNewMeth->pInitValue = hb_itemNew( NULL );
@@ -850,7 +850,7 @@ HB_FUNC( __CLSADDMSG )
if( pInit && ! HB_IS_NIL( pInit ) ) /* Initializer found */
{
if( HB_IS_ARRAY( pInit ) )
pNewMeth->pInitValue = hb_arrayClone( pInit );
pNewMeth->pInitValue = hb_arrayClone( pInit, NULL, NULL );
else
{
pNewMeth->pInitValue = hb_itemNew( NULL );
@@ -994,9 +994,9 @@ HB_FUNC( __CLSNEW )
pNewCls->uiHashKey = pSprCls->uiHashKey;
/* CLASS DATA Not Shared ( new array, new value ) */
pNewCls->pClassDatas = hb_arrayClone( pSprCls->pClassDatas );
pNewCls->pClassDatas = hb_arrayClone( pSprCls->pClassDatas, NULL, NULL );
pNewCls->pInlines = hb_arrayClone( pSprCls->pInlines );
pNewCls->pInlines = hb_arrayClone( pSprCls->pInlines, NULL, NULL );
pNewCls->uiDatasShared = pSprCls->uiDatasShared;
@@ -1009,7 +1009,7 @@ HB_FUNC( __CLSNEW )
nLenDatas = ( USHORT ) pNewCls->uiDatas;
/* ClassDatas */
pClsAnyTmp = hb_arrayClone( pSprCls->pClassDatas );
pClsAnyTmp = hb_arrayClone( pSprCls->pClassDatas, NULL, NULL );
nLen = ( USHORT ) hb_itemSize( pClsAnyTmp );
for( ui = 1; ui <= nLen; ui++ )
{
@@ -1024,7 +1024,7 @@ HB_FUNC( __CLSNEW )
pNewCls->uiDatasShared += pSprCls->uiDatasShared;
/* Inlines */
pClsAnyTmp = hb_arrayClone( pSprCls->pInlines );
pClsAnyTmp = hb_arrayClone( pSprCls->pInlines, NULL, NULL );
nLen = ( USHORT ) hb_itemSize( pClsAnyTmp );
for( ui = 1; ui <= nLen; ui++ )
{
@@ -1122,7 +1122,7 @@ HB_FUNC( __CLSNEW )
PHB_ITEM pInitValue;
if( HB_IS_ARRAY( pSprCls->pMethods[ ui ].pInitValue ) )
pNewCls->pMethods[ uiAt + uiBucket ].pInitValue = hb_arrayClone( pSprCls->pMethods[ ui ].pInitValue );
pNewCls->pMethods[ uiAt + uiBucket ].pInitValue = hb_arrayClone( pSprCls->pMethods[ ui ].pInitValue, NULL, NULL );
else
{
pInitValue = hb_itemNew( NULL );
@@ -1353,7 +1353,7 @@ static PHB_ITEM hb_clsInst( USHORT uiClass, PHB_ITEM * * ppObjects, USHORT * pui
{
if( HB_IS_ARRAY( pMeth->pInitValue ) )
pInit = hb_arrayClone( pMeth->pInitValue );
pInit = hb_arrayClone( pMeth->pInitValue, NULL, NULL );
else
{
pInit = hb_itemNew( NULL );
@@ -1414,7 +1414,7 @@ static PHB_ITEM hb_clsInst( USHORT uiClass, PHB_ITEM * * ppObjects, USHORT * pui
if( HB_IS_ARRAY( pMeth->pInitValue ) )
{
pInitValue = hb_arrayClone( pMeth->pInitValue );
pInitValue = hb_arrayClone( pMeth->pInitValue, NULL, NULL );
}
else
{
@@ -1439,7 +1439,7 @@ static PHB_ITEM hb_clsInst( USHORT uiClass, PHB_ITEM * * ppObjects, USHORT * pui
{
if( HB_IS_ARRAY( pMeth->pInitValue ) )
pInit = hb_arrayClone( pMeth->pInitValue );
pInit = hb_arrayClone( pMeth->pInitValue, NULL, NULL );
else
{
pInit = hb_itemNew( NULL );
@@ -1571,7 +1571,7 @@ HB_FUNC( __OBJCLONE )
PHB_ITEM pSrcObject = hb_param( 1, HB_IT_OBJECT );
if( pSrcObject )
hb_itemRelease( hb_itemReturn( hb_arrayClone( pSrcObject ) ) );
hb_itemRelease( hb_itemReturn( hb_arrayClone( pSrcObject, NULL, NULL ) ) );
else
hb_errRT_BASE( EG_ARG, 3001, NULL, "__OBJCLONE", 0 );
}

View File

@@ -4300,7 +4300,7 @@ void hb_vmRequestCancel( void )
* $End$ */
HB_FUNC( __VMVARSLIST )
{
PHB_ITEM pStatics = hb_arrayClone( &s_aStatics );
PHB_ITEM pStatics = hb_arrayClone( &s_aStatics, NULL, NULL );
hb_itemCopy( &hb_stack.Return, pStatics );
hb_itemRelease( pStatics );