/* Release all allocated memory when called from the garbage collector */ static HB_GARBAGE_FUNC( hb_codeblockGarbageDelete ) { PHB_CODEBLOCK pCBlock = ( PHB_CODEBLOCK ) Cargo; HB_TRACE( HB_TR_DEBUG, ( "hb_codeblockGarbageDelete(%p)", Cargo ) ); /* free space allocated for pcodes - if it was a macro-compiled codeblock */ if( pCBlock->pCode && pCBlock->dynBuffer ) { pCBlock->dynBuffer = HB_FALSE; hb_xfree( HB_UNCONST( pCBlock->pCode ) ); } pCBlock->pCode = s_pCode; /* free space allocated for local variables */ if( pCBlock->pLocals ) { if( hb_xRefDec( pCBlock->pLocals ) ) { while( pCBlock->uiLocals ) hb_memvarValueDecRef( pCBlock->pLocals[ pCBlock->uiLocals-- ].item.asMemvar.value ); hb_xfree( pCBlock->pLocals ); } pCBlock->pLocals = NULL; pCBlock->uiLocals = 0; } }
/* * Detach public or private variable (swap current value with a memvar handle) */ static void hb_memvarDetachDynSym( PHB_DYNS pDynSym, PHB_ITEM pPrevMemvar ) { PHB_ITEM pMemvar; HB_TRACE( HB_TR_DEBUG, ( "hb_memvarDetachDynSym(%p,%p)", pDynSym, pPrevMemvar ) ); pMemvar = hb_dynsymGetMemvar( pDynSym ); hb_dynsymSetMemvar( pDynSym, pPrevMemvar ); hb_memvarValueDecRef( pMemvar ); }
void hb_stackClearMemvars( int iExcept ) { HB_STACK_TLS_PRELOAD int iDynSym; HB_TRACE( HB_TR_DEBUG, ( "hb_stackClearMemvars(%d)", iExcept ) ); iDynSym = hb_stack.iDynH; while( --iDynSym >= 0 ) { if( hb_stack.pDynH[ iDynSym ].pMemvar && iDynSym != iExcept ) { PHB_ITEM pMemvar = ( PHB_ITEM ) hb_stack.pDynH[ iDynSym ].pMemvar; hb_stack.pDynH[ iDynSym ].pMemvar = NULL; hb_memvarValueDecRef( pMemvar ); } } }
/* Release all allocated memory when called from the garbage collector */ static HB_GARBAGE_FUNC( hb_codeblockGarbageDelete ) { PHB_CODEBLOCK pCBlock = ( PHB_CODEBLOCK ) Cargo; HB_TRACE( HB_TR_DEBUG, ( "hb_codeblockGarbageDelete(%p)", Cargo ) ); /* free space allocated for pcodes - if it was a macro-compiled codeblock */ if( pCBlock->pCode && pCBlock->dynBuffer ) { pCBlock->dynBuffer = HB_FALSE; hb_xfree( ( void * ) pCBlock->pCode ); } pCBlock->pCode = s_pCode; /* free space allocated for local variables */ if( pCBlock->pLocals ) { PHB_ITEM pLocals = pCBlock->pLocals; HB_USHORT uiLocals = pCBlock->uiLocals; /* clear pCBlock->pLocals to avoid infinit loop in cross * referenced items */ pCBlock->pLocals = NULL; pCBlock->uiLocals = 0; if( hb_xRefDec( pLocals ) ) { while( uiLocals ) hb_memvarValueDecRef( pLocals[ uiLocals-- ].item.asMemvar.value ); hb_xfree( pLocals ); } } }