HB_EXTERN_BEGIN PHB_ITEM hb_dbg_vmVarLGet( int iLevel, int iLocal ) { PHB_ITEM * pBase = HB_VM_STACK.pBase; while( ( iLevel-- > 0 ) && pBase != HB_VM_STACK.pItems ) { pBase = HB_VM_STACK.pItems + ( *pBase )->item.asSymbol.pCargo->stackbase; } if( iLocal > SHRT_MAX ) { hb_dbgStop(); iLocal -= USHRT_MAX; iLocal--; } if( iLocal >= 0 ) { return hb_itemUnRef( *(pBase + 1 + iLocal) ); } if ( HB_IS_BLOCK( *(pBase+1) ) ) { return hb_codeblockGetVar( *(pBase+1), ( LONG ) iLocal ); } return NULL; }
/* retrieves the codeblock unique ID */ void * hb_codeblockId( PHB_ITEM pItem ) { if( HB_IS_BLOCK( pItem ) ) return ( void * ) pItem->item.asBlock.value; else return NULL; }
PHB_ITEM hb_evalLaunch( PHB_EVALINFO pEvalInfo ) { PHB_ITEM pResult = NULL; HB_TRACE( HB_TR_DEBUG, ( "hb_evalLaunch(%p)", pEvalInfo ) ); if( pEvalInfo ) { PHB_ITEM pItem = pEvalInfo->pItems[ 0 ]; PHB_SYMB pSymbol = NULL; if( HB_IS_STRING( pItem ) ) { PHB_DYNS pDynSym = hb_dynsymFindName( pItem->item.asString.value ); if( pDynSym ) { pSymbol = pDynSym->pSymbol; pItem = NULL; } } else if( HB_IS_SYMBOL( pItem ) ) { pSymbol = pItem->item.asSymbol.value; pItem = NULL; } else if( HB_IS_BLOCK( pItem ) ) { pSymbol = &hb_symEval; } if( pSymbol ) { HB_USHORT uiParam = 0; hb_vmPushSymbol( pSymbol ); if( pItem ) hb_vmPush( pItem ); else hb_vmPushNil(); while( uiParam < pEvalInfo->paramCount ) hb_vmPush( pEvalInfo->pItems[ ++uiParam ] ); if( pItem ) hb_vmSend( uiParam ); else hb_vmProc( uiParam ); pResult = hb_itemNew( hb_stackReturnItem() ); } } return pResult; }
static void hb_zebra_draw_codeblock_callback( void * pDrawBlock, double dX, double dY, double dWidth, double dHeight ) { if( pDrawBlock && HB_IS_BLOCK( pDrawBlock ) && hb_vmRequestReenter() ) { hb_vmPushEvalSym(); hb_vmPush( ( PHB_ITEM ) pDrawBlock ); hb_vmPushDouble( dX, HB_DEFAULT_DECIMALS ); hb_vmPushDouble( dY, HB_DEFAULT_DECIMALS ); hb_vmPushDouble( dWidth, HB_DEFAULT_DECIMALS ); hb_vmPushDouble( dHeight, HB_DEFAULT_DECIMALS ); hb_vmSend( 4 ); hb_vmRequestRestore(); } }
static void xml_errorHandler( void * unused, xmlErrorPtr pError ) { if( ! unused && pError && pHandler ) { /* HB_TRACE( HB_TR_ERROR, ( "libxml2 error: file=%s domain=%d code=%d message=%s line=%d col=%d s1=%s s2=%s s3=%s", pError->file, pError->domain, pError->code, pError->message, pError->line, pError->int2, pError->str1, pError->str2, pError->str3 ) ); */ /* codeblock */ PHB_ITEM pCallback = pHandler->pErrorBlock; if( HB_IS_BLOCK( pCallback ) ) { if( hb_vmRequestReenter() ) { //int iResult; hb_vmPushEvalSym(); hb_vmPush( pCallback ); hb_vmPushPointer( pError ); hb_vmSend( 1 ); //iResult = hb_parni( -1 ); hb_vmRequestRestore(); } } } }
PHB_ITEM hb_evalLaunch( PHB_EVALINFO pEvalInfo ) { HB_THREAD_STUB PHB_ITEM pResult = NULL; HB_TRACE( HB_TR_DEBUG, ( "hb_evalLaunch(%p)", pEvalInfo ) ); if( pEvalInfo ) { register USHORT uiParam = 1; if( HB_IS_STRING( pEvalInfo->pItems[ 0 ] ) ) { const char * ptr = pEvalInfo->pItems[ 0 ]->item.asString.value; hb_vmPushSymbol( hb_dynsymFindName( ptr )->pSymbol ); hb_vmPushNil(); while( uiParam <= pEvalInfo->paramCount ) hb_vmPush( pEvalInfo->pItems[ uiParam++ ] ); hb_vmDo( pEvalInfo->paramCount ); pResult = hb_itemNew( NULL ); hb_itemForwardValue( pResult, &( HB_VM_STACK.Return ) ); } else if( HB_IS_BLOCK( pEvalInfo->pItems[ 0 ] ) ) { hb_vmPushSymbol( &hb_symEval ); hb_vmPush( pEvalInfo->pItems[ 0 ] ); while( uiParam <= pEvalInfo->paramCount ) hb_vmPush( pEvalInfo->pItems[ uiParam++ ] ); hb_vmSend( pEvalInfo->paramCount ); pResult = hb_itemNew( NULL ); hb_itemForwardValue( pResult, &( HB_VM_STACK.Return ) ); } } return pResult; }
static PHB_ITEM hb_i18n_pluralexp_compile( PHB_ITEM pExp ) { HB_SIZE nLen = hb_itemGetCLen( pExp ); PHB_ITEM pBlock = NULL; if( nLen > 0 ) { char * szMacro = ( char * ) hb_xgrab( nLen + 6 ); const char * szType; PHB_ITEM pMacro; szMacro[ 0 ] = '{'; szMacro[ 1 ] = '|'; szMacro[ 2 ] = 'n'; szMacro[ 3 ] = '|'; memcpy( &szMacro[ 4 ], hb_itemGetCPtr( pExp ), nLen ); szMacro[ 4 + nLen ] = '}'; szMacro[ 5 + nLen ] = '\0'; pMacro = hb_itemPutCLPtr( NULL, szMacro, nLen ); szType = hb_macroGetType( pMacro ); if( *szType == 'B' ) { hb_vmPush( pMacro ); hb_macroGetValue( hb_stackItemFromTop( -1 ), 0, 0 ); if( hb_vmRequestQuery() == 0 ) { pExp = hb_stackItemFromTop( -1 ); if( HB_IS_BLOCK( pExp ) ) pBlock = hb_itemNew( pExp ); hb_stackPop(); } } hb_itemRelease( pMacro ); } return pBlock; }
int hb_CmpTdSpan( const char * szFile, PHB_ITEM pArray, int iCompLevel, PHB_ITEM pBlock, BOOL bOverWrite, const char * szPassWord, int iSpanSize, BOOL bPath, BOOL bDrive, PHB_ITEM pProgress ) { ULONG ulCount = 0; const char * szDummy; DWORD dwSize; BOOL bAdded = FALSE; BOOL bReturn = TRUE; BOOL bFileExist = hb_fsFile( szFile ); CZipArchive szZip; SpanCallbackc span; SpanActionCallbackc spanac; szZip.SetSpanCallback( &span ); if( iSpanSize == 0 ) { iSpanSize = 1457664; } try { if( ( bFileExist && bOverWrite ) || ! bFileExist ) { szZip.Open( szFile, CZipArchive::zipCreateSpan, iSpanSize ); } else { bReturn = FALSE; return ( int ) bReturn; } } catch( CZipException ) { bReturn = FALSE; } catch( ... ) { } //if (! bReturn ) //{ if( szPassWord != NULL ) { szZip.SetPassword( szPassWord ); } if( pZipI.szComment != NULL ) { szZip.SetGlobalComment( pZipI.szComment ); hb_xfree( pZipI.szComment ); } if( HB_IS_BLOCK( pProgress ) ) { pProgressInfo = pProgress; szZip.SetCallback( &spanac ); } for( ulCount = 1; ( ulCount <= hb_arrayLen( pArray ) ); ulCount++ ) { szDummy = ( char * ) hb_arrayGetCPtr( pArray, ulCount ); dwSize = GetCurrentFileSize( szDummy ); bAdded = FALSE; if( dwSize != ( DWORD ) -1 ) { if( pBlock != NULL ) { PHB_ITEM FileName = hb_itemPutC( NULL, hb_arrayGetCPtr( pArray, ulCount ) ), FilePos = hb_itemPutNI( NULL, ulCount ); hb_vmEvalBlockV( pBlock, 2, FileName, FilePos ); hb_itemRelease( FileName ); hb_itemRelease( FilePos ); } try { if( bPath && ! bAdded ) { szZip.AddNewFile( szDummy, iCompLevel, true, CZipArchive::zipsmSafeSmart, 65536 ); bAdded = TRUE; } else if( ! bDrive && ! bPath && ! bAdded ) { szZip.AddNewFile( szDummy, iCompLevel, false, CZipArchive::zipsmSafeSmart, 65536 ); } } catch( ... ) { } } } //} try { szZip.Close(); } catch( CZipException ) { bReturn = FALSE; } catch( ... ) { } return ( int ) bReturn; }
/* Creates the codeblock structure * * pBuffer -> the buffer with pcodes (without HB_P_PUSHBLOCK) * wLocals -> number of local variables referenced in a codeblock * pLocalPosTable -> a table with positions on eval stack for referenced variables * pSymbols -> a pointer to the module symbol table * * Note: pLocalPosTable cannot be used if uiLocals is ZERO */ PHB_CODEBLOCK hb_codeblockNew( const HB_BYTE * pBuffer, HB_USHORT uiLocals, const HB_BYTE * pLocalPosTable, PHB_SYMB pSymbols, HB_SIZE nLen ) { HB_STACK_TLS_PRELOAD PHB_CODEBLOCK pCBlock; PHB_ITEM pLocals, pBase; const HB_BYTE * pCode; HB_TRACE( HB_TR_DEBUG, ( "hb_codeblockNew(%p, %hu, %p, %p, %" HB_PFS "u)", pBuffer, uiLocals, pLocalPosTable, pSymbols, nLen ) ); /* Allocate memory for code block body and detach items hb_gcAllocRaw() * to be safe for automatic GC activation in hb_xgrab() without * calling hb_gcLock()/hb_gcUnlock(). [druzus] */ if( nLen ) { /* The codeblock pcode is stored in dynamically allocated memory that * can be deallocated after creation of a codeblock. We have to duplicate * the passed buffer */ pCode = ( const HB_BYTE * ) memcpy( hb_xgrab( nLen ), pBuffer, nLen ); } else { /* The codeblock pcode is stored in static segment. * The only allowed operation on a codeblock is evaluating it then * there is no need to duplicate its pcode - just store the pointer to it */ pCode = pBuffer; } if( uiLocals ) { /* NOTE: if a codeblock will be created by macro compiler then * uiLocal have to be ZERO * uiLocal will be also ZERO if it is a nested codeblock */ HB_USHORT ui = 1; PHB_ITEM pLocal; /* Create a table that will store the values of local variables * accessed in a codeblock * The element 0 is unused * NOTE: This table can be shared by codeblocks created during * evaluation of this codeblock */ pLocals = ( PHB_ITEM ) hb_xgrab( ( uiLocals + 1 ) * sizeof( HB_ITEM ) ); pLocals[ 0 ].type = HB_IT_NIL; do { /* Swap the current value of local variable with the reference to this * value. */ int iLocal = HB_PCODE_MKUSHORT( pLocalPosTable ); pLocal = hb_stackLocalVariable( iLocal ); pLocalPosTable += 2; pLocal = hb_memvarDetachLocal( pLocal ); hb_itemRawCpy( pLocals + ui, pLocal ); /* Increment the reference counter so this value will not be * released if other codeblock will be deleted */ hb_memvarValueIncRef( pLocal->item.asMemvar.value ); } while( ++ui <= uiLocals ); } else { /* Check if this codeblock is created during evaluation of another * codeblock - all inner codeblocks use the local variables table * created during creation of the outermost codeblock */ PHB_ITEM pLocal; pLocal = hb_stackSelfItem(); if( HB_IS_BLOCK( pLocal ) ) { PHB_CODEBLOCK pOwner = pLocal->item.asBlock.value; uiLocals = pOwner->uiLocals; pLocals = pOwner->pLocals; if( pLocals ) hb_xRefInc( pLocals ); } else pLocals = NULL; } pBase = hb_stackBaseItem(); pCBlock = ( PHB_CODEBLOCK ) hb_gcAllocRaw( sizeof( HB_CODEBLOCK ), &s_gcCodeblockFuncs ); pCBlock->pCode = pCode; pCBlock->dynBuffer = nLen != 0; pCBlock->pDefSymb = pBase->item.asSymbol.stackstate->uiClass ? hb_clsMethodSym( pBase ) : pBase->item.asSymbol.value; pCBlock->pSymbols = pSymbols; pCBlock->pStatics = hb_stackGetStaticsBase(); pCBlock->uiLocals = uiLocals; pCBlock->pLocals = pLocals; HB_TRACE( HB_TR_INFO, ( "codeblock created %p", pCBlock ) ); return pCBlock; }
BOOL hb_execFromArray( PHB_ITEM pFirst ) { register ULONG i; HB_SIZE ulLen; ULONG ulStart = 1; PHB_ITEM pArgs; PHB_ITEM pString; PHB_ITEM pSelf = NULL; PHB_DYNS pExecSym = NULL; PHB_SYMB pSymbol = NULL; if( pFirst == NULL || pFirst->type != HB_IT_ARRAY ) return FALSE; pString = hb_arrayGetItemPtr( pFirst, 1 ); pArgs = pFirst; if( HB_IS_OBJECT( pString ) && hb_arrayLen( pFirst ) >= 2 ) { pSelf = pString; pString = hb_arrayGetItemPtr( pFirst, 2 ); if( pString->type == HB_IT_STRING ) pExecSym = hb_dynsymFindName( pString->item.asString.value ); else if( pString->type == HB_IT_POINTER ) pSymbol = ( PHB_SYMB ) hb_itemGetPtr( pString ); ulStart = 3; } else if( pString->type == HB_IT_STRING ) { pExecSym = hb_dynsymFindName( pString->item.asString.value ); ulStart = 2; } else if( pString->type == HB_IT_POINTER ) { pSymbol = ( PHB_SYMB ) hb_itemGetPtr( pString ); ulStart = 2; } else if( HB_IS_BLOCK( pString ) ) { pSymbol = &hb_symEval; ulStart = 2; } if( pExecSym ) pSymbol = pExecSym->pSymbol; if( pSymbol == NULL ) return FALSE; hb_vmPushSymbol( pSymbol ); if( pSelf ) hb_vmPush( pSelf ); else hb_vmPushNil(); ulLen = hb_arrayLen( pArgs ); /* pushing the contents of the array */ for( i = ulStart; i <= ulLen; i++ ) hb_vmPush( hb_arrayGetItemPtr( pArgs, i ) ); if( pSelf ) hb_vmSend( ( USHORT ) ( ulLen - ulStart + 1 ) ); else hb_vmDo( ( USHORT ) ( ulLen - ulStart + 1 ) ); return TRUE; }
static void sk_add( PHB_SETKEY * sk_list_ptr, HB_BOOL bReturn, int iKeyCode, PHB_ITEM pAction, PHB_ITEM pIsActive ) { if( iKeyCode ) { PHB_SETKEY sk_list_tmp, sk_list_end; if( pIsActive && ! HB_IS_BLOCK( pIsActive ) ) pIsActive = NULL; if( pAction && ! HB_IS_BLOCK( pAction ) ) pAction = NULL; sk_list_tmp = sk_findkey( iKeyCode, *sk_list_ptr, &sk_list_end ); if( sk_list_tmp == NULL ) { if( pAction ) { sk_list_tmp = ( PHB_SETKEY ) hb_xgrab( sizeof( HB_SETKEY ) ); sk_list_tmp->next = NULL; sk_list_tmp->iKeyCode = iKeyCode; sk_list_tmp->pAction = hb_itemNew( pAction ); sk_list_tmp->pIsActive = pIsActive ? hb_itemNew( pIsActive ) : NULL; if( sk_list_end == NULL ) *sk_list_ptr = sk_list_tmp; else sk_list_end->next = sk_list_tmp; } } else { /* Return the previous value */ if( bReturn ) hb_itemReturn( sk_list_tmp->pAction ); /* Free the previous values */ hb_itemRelease( sk_list_tmp->pAction ); if( sk_list_tmp->pIsActive ) { hb_itemRelease( sk_list_tmp->pIsActive ); } /* Set the new values or free the entry */ if( pAction ) { sk_list_tmp->pAction = hb_itemNew( pAction ); sk_list_tmp->pIsActive = pIsActive ? hb_itemNew( pIsActive ) : NULL; } else { /* if this is true, then the key found is the first key in the list */ if( sk_list_end == NULL ) { sk_list_tmp = *sk_list_ptr; *sk_list_ptr = sk_list_tmp->next; hb_xfree( sk_list_tmp ); } else { sk_list_end->next = sk_list_tmp->next; hb_xfree( sk_list_tmp ); } } } } }
static void sk_add( BOOL bReturn, SHORT iKeyCode, PHB_ITEM pAction, PHB_ITEM pIsActive ) { if( iKeyCode ) { PHB_SETKEY sk_list_tmp, sk_list_end; // Verify to allow only codeblock in pIsActive pIsActive = ( pIsActive && HB_IS_BLOCK( pIsActive ) ) ? pIsActive : NULL; sk_list_tmp = sk_findkey( iKeyCode, &sk_list_end ); if( sk_list_tmp == NULL ) { if( pAction ) { sk_list_tmp = ( PHB_SETKEY ) hb_xgrab( sizeof( HB_SETKEY ) ); sk_list_tmp->next = NULL; sk_list_tmp->iKeyCode = iKeyCode; sk_list_tmp->pAction = hb_itemNew( pAction ); sk_list_tmp->pIsActive = pIsActive ? hb_itemNew( pIsActive ) : NULL; if( sk_list_end == NULL ) { s_sk_list = sk_list_tmp; } else { sk_list_end->next = sk_list_tmp; } } } else { /* Return the previous value */ if( bReturn ) hb_itemReturn( sk_list_tmp->pAction ); /* Free the previous values */ hb_itemRelease( sk_list_tmp->pAction ); if( sk_list_tmp->pIsActive ) { hb_itemRelease( sk_list_tmp->pIsActive ); } /* Set the new values or free the entry */ if( pAction ) { sk_list_tmp->pAction = hb_itemNew( pAction ); sk_list_tmp->pIsActive = pIsActive ? hb_itemNew( pIsActive ) : NULL; } else { /* if this is true, then the key found is the first key in the list */ if( sk_list_end == NULL ) { sk_list_tmp = s_sk_list->next; hb_xfree( s_sk_list ); s_sk_list = sk_list_tmp; } else { sk_list_end->next = sk_list_tmp->next; hb_xfree( sk_list_tmp ); } } } } }
HB_BOOL hb_execFromArray( PHB_ITEM pParam ) { PHB_ITEM pArray = NULL; PHB_ITEM pSelf = NULL; HB_ULONG ulParamOffset = 0; if( pParam && HB_IS_ARRAY( pParam ) && ! HB_IS_OBJECT( pParam ) ) { pArray = pParam; pParam = hb_arrayGetItemPtr( pArray, 1 ); if( HB_IS_OBJECT( pParam ) ) { pSelf = pParam; pParam = hb_arrayGetItemPtr( pArray, 2 ); ulParamOffset = 2; } else ulParamOffset = 1; } if( pParam ) { PHB_SYMB pExecSym = NULL; if( HB_IS_SYMBOL( pParam ) ) pExecSym = hb_itemGetSymbol( pParam ); else if( HB_IS_STRING( pParam ) ) pExecSym = hb_dynsymGet( hb_itemGetCPtr( pParam ) )->pSymbol; else if( HB_IS_BLOCK( pParam ) && ! pSelf ) { pSelf = pParam; pExecSym = &hb_symEval; } if( pExecSym ) { int iPCount = 0; hb_vmPushSymbol( pExecSym ); if( pSelf ) hb_vmPush( pSelf ); else hb_vmPushNil(); if( pArray ) { pParam = hb_arrayGetItemPtr( pArray, ++ulParamOffset ); while( pParam && iPCount < 255 ) { hb_vmPush( pParam ); ++iPCount; pParam = hb_arrayGetItemPtr( pArray, ++ulParamOffset ); } } if( pSelf ) hb_vmSend( ( HB_USHORT ) iPCount ); else hb_vmProc( ( HB_USHORT ) iPCount ); return HB_TRUE; } } hb_errRT_BASE_SubstR( EG_ARG, 1099, NULL, HB_ERR_FUNCNAME, HB_ERR_ARGS_BASEPARAMS ); return HB_FALSE; }
PHB_ITEM hb_itemDo( PHB_ITEM pItem, HB_ULONG ulPCount, ... ) { PHB_ITEM pResult = NULL; HB_TRACE( HB_TR_DEBUG, ( "hb_itemDo(%p, %lu, ...)", pItem, ulPCount ) ); if( pItem ) { PHB_SYMB pSymbol = NULL; if( HB_IS_STRING( pItem ) ) { PHB_DYNS pDynSym = hb_dynsymFindName( pItem->item.asString.value ); if( pDynSym ) { pSymbol = pDynSym->pSymbol; pItem = NULL; } } else if( HB_IS_SYMBOL( pItem ) ) { pSymbol = pItem->item.asSymbol.value; pItem = NULL; } else if( HB_IS_BLOCK( pItem ) ) { pSymbol = &hb_symEval; } if( pSymbol ) { if( hb_vmRequestReenter() ) { hb_vmPushSymbol( pSymbol ); if( pItem ) hb_vmPush( pItem ); else hb_vmPushNil(); if( ulPCount ) { HB_ULONG ulParam; va_list va; va_start( va, ulPCount ); for( ulParam = 1; ulParam <= ulPCount; ulParam++ ) hb_vmPush( va_arg( va, PHB_ITEM ) ); va_end( va ); } if( pItem ) hb_vmSend( ( HB_USHORT ) ulPCount ); else hb_vmProc( ( HB_USHORT ) ulPCount ); pResult = hb_itemNew( hb_stackReturnItem() ); hb_vmRequestRestore(); } } } return pResult; }
/* Mark a passed item as used so it will be not released by the GC */ void hb_gcItemRef( PHB_ITEM pItem ) { while( HB_IS_BYREF( pItem ) ) { if( HB_IS_ENUM( pItem ) ) return; else if( HB_IS_EXTREF( pItem ) ) { pItem->item.asExtRef.func->mark( pItem->item.asExtRef.value ); return; } else if( ! HB_IS_MEMVAR( pItem ) && pItem->item.asRefer.offset == 0 && pItem->item.asRefer.value >= 0 ) { /* array item reference */ PHB_GARBAGE pAlloc = HB_GC_PTR( pItem->item.asRefer.BasePtr.array ); if( ( pAlloc->used & ~HB_GC_DELETE ) == s_uUsedFlag ) { /* mark this array as used */ pAlloc->used ^= HB_GC_USED_FLAG; /* mark also all array elements */ pAlloc->pFuncs->mark( HB_BLOCK_PTR( pAlloc ) ); } return; } pItem = hb_itemUnRefOnce( pItem ); } if( HB_IS_ARRAY( pItem ) ) { PHB_GARBAGE pAlloc = HB_GC_PTR( pItem->item.asArray.value ); /* Check this array only if it was not checked yet */ if( ( pAlloc->used & ~HB_GC_DELETE ) == s_uUsedFlag ) { /* mark this array as used so it will be no re-checked from * other references */ pAlloc->used ^= HB_GC_USED_FLAG; /* mark also all array elements */ pAlloc->pFuncs->mark( HB_BLOCK_PTR( pAlloc ) ); } } else if( HB_IS_HASH( pItem ) ) { PHB_GARBAGE pAlloc = HB_GC_PTR( pItem->item.asHash.value ); /* Check this hash table only if it was not checked yet */ if( ( pAlloc->used & ~HB_GC_DELETE ) == s_uUsedFlag ) { /* mark this hash table as used */ pAlloc->used ^= HB_GC_USED_FLAG; /* mark also all hash elements */ pAlloc->pFuncs->mark( HB_BLOCK_PTR( pAlloc ) ); } } else if( HB_IS_BLOCK( pItem ) ) { PHB_GARBAGE pAlloc = HB_GC_PTR( pItem->item.asBlock.value ); if( ( pAlloc->used & ~HB_GC_DELETE ) == s_uUsedFlag ) { /* mark this codeblock as used */ pAlloc->used ^= HB_GC_USED_FLAG; /* mark as used all detached variables in a codeblock */ pAlloc->pFuncs->mark( HB_BLOCK_PTR( pAlloc ) ); } } else if( HB_IS_POINTER( pItem ) ) { if( pItem->item.asPointer.collect ) { PHB_GARBAGE pAlloc = HB_GC_PTR( pItem->item.asPointer.value ); if( ( pAlloc->used & ~HB_GC_DELETE ) == s_uUsedFlag ) { /* mark this memory block as used */ pAlloc->used ^= HB_GC_USED_FLAG; /* mark also all internal user blocks attached to this block */ pAlloc->pFuncs->mark( HB_BLOCK_PTR( pAlloc ) ); } } } /* all other data types don't need the GC */ }
int hb_CmpTdSpanStd( char * szFile, char * szFiletoCompress, int iCompLevel, PHB_ITEM pBlock, BOOL bOverWrite, char * szPassWord, int iSpanSize, BOOL bPath, BOOL bDrive, PHB_ITEM pProgress ) { DWORD dwSize; BOOL bAdded = FALSE; BOOL bReturn = TRUE; BOOL bFileExist = hb_fsFile( szFile ); CZipArchive szZip; SpanCallbackc span; SpanActionCallbackc spanac; szZip.SetSpanCallback( &span ); if( iSpanSize == 0 ) { iSpanSize = 1457664; } try { if( ( bFileExist && bOverWrite ) || ! bFileExist ) { szZip.Open( szFile, CZipArchive::zipCreateSpan, iSpanSize ); } else { return ( int ) false; } } catch( CZipException ) { bReturn = FALSE; } catch( ... ) { } if( szPassWord != NULL ) { szZip.SetPassword( szPassWord ); } if( pZipI.szComment != NULL ) { szZip.SetGlobalComment( pZipI.szComment ); hb_xfree( pZipI.szComment ); } if( HB_IS_BLOCK( pProgress ) ) { pProgressInfo = pProgress; szZip.SetCallback( &spanac ); } if( bReturn ) { try { if( szPassWord != NULL ) { szZip.SetPassword( szPassWord ); } dwSize = GetCurrentFileSize( szFiletoCompress ); if( pBlock != NULL ) { PHB_ITEM FileName = hb_itemPutC( NULL, szFiletoCompress ); hb_vmEvalBlockV( pBlock, 1, FileName ); hb_itemRelease( FileName ); } #if defined( __WIN32__ ) || defined( __MINGW32__ ) if( bDrive && ! bAdded ) { if( ! szZip.AddNewFileDrv( szFiletoCompress, iCompLevel, true, CZipArchive::zipsmSafeSmart, 65536 ) ) { bReturn = FALSE; } else { bAdded = TRUE; } } #endif if( bPath && ! bAdded ) { if( ! szZip.AddNewFile( szFiletoCompress, iCompLevel, true, CZipArchive::zipsmSafeSmart, 65536 ) ) { bReturn = FALSE; } else { bAdded = TRUE; } } else if( ! bDrive && ! bPath && ! bAdded ) { if( ! szZip.AddNewFile( szFiletoCompress, iCompLevel, false, CZipArchive::zipsmSafeSmart, 65536 ) ) { bReturn = FALSE; } } } catch( ... ) { } } try { szZip.Close(); } catch( CZipException ) { bReturn = FALSE; } catch( ... ) { } if( pProgressInfo ) { hb_itemRelease( pProgressInfo ); } return ( int ) bReturn; }
PHB_ITEM hb_itemDo( PHB_ITEM pItem, HB_SIZE ulPCount, ... ) { HB_THREAD_STUB PHB_ITEM pResult = NULL; HB_TRACE( HB_TR_DEBUG, ( "hb_itemDo(%p, %hu, ...)", pItem, ulPCount ) ); if( pItem ) { PHB_SYMB pSymbol = NULL; if( HB_IS_STRING( pItem ) ) { PHB_DYNS pDynSym = hb_dynsymFindName( pItem->item.asString.value ); if( pDynSym ) pSymbol = pDynSym->pSymbol; } else if( HB_IS_POINTER( pItem ) ) pSymbol = ( PHB_SYMB ) pItem->item.asPointer.value; else if( HB_IS_SYMBOL( pItem ) ) pSymbol = pItem->item.asSymbol.value; if( pSymbol ) { hb_vmPushState(); hb_vmPushSymbol( pSymbol ); hb_vmPushNil(); if( ulPCount ) { register ULONG ulParam; va_list va; va_start( va, ulPCount ); for( ulParam = 1; ulParam <= ulPCount; ulParam++ ) hb_vmPush( va_arg( va, PHB_ITEM ) ); va_end( va ); } hb_vmDo( ( USHORT ) ulPCount ); pResult = hb_itemNew( NULL ); hb_itemForwardValue( pResult, &( HB_VM_STACK.Return ) ); hb_vmPopState(); } else if( HB_IS_BLOCK( pItem ) ) { hb_vmPushState(); hb_vmPushSymbol( &hb_symEval ); hb_vmPush( pItem ); if( ulPCount ) { register ULONG ulParam; va_list va; va_start( va, ulPCount ); for( ulParam = 1; ulParam <= ulPCount; ulParam++ ) hb_vmPush( va_arg( va, PHB_ITEM ) ); va_end( va ); } hb_vmSend( ( USHORT ) ulPCount ); pResult = hb_itemNew( NULL ); hb_itemForwardValue( pResult, &( HB_VM_STACK.Return ) ); hb_vmPopState(); } else if( HB_IS_ARRAY( pItem ) ) { hb_vmPushState(); if( hb_execFromArray( pItem ) ) { pResult = hb_itemNew( NULL ); hb_itemForwardValue( pResult, &( HB_VM_STACK.Return ) ); } hb_vmPopState(); } } return pResult; }
int hb_CompressFile( const char * szFile, PHB_ITEM pArray, int iCompLevel, PHB_ITEM pBlock, BOOL bOverWrite, const char * szPassWord, BOOL bPath, BOOL bDrive, PHB_ITEM pProgress ) { ULONG ulCount = 0; const char * szDummy; char * szDummyLower = NULL; char * szFileLower = hb_strdup( ( char * ) szFile ); BOOL bFileExist = hb_fsFile( szFile ); BOOL bAdded = FALSE; BOOL bReturn = TRUE; DWORD dwSize; CZipArchive szZip; SpanCallbackc span; SpanActionCallbackc spanac; szZip.SetSpanCallback( &span ); #ifdef HB_OS_WIN_32 hb_strLower( szFileLower, strlen( szFileLower ) ); #endif try { if( ( bFileExist && bOverWrite ) || ! bFileExist ) { szZip.Open( szFile, CZipArchive::zipCreate, 0 ); } else { szZip.Open( szFile, CZipArchive::zipOpen, 0 ); } } catch( CZipException ) { bReturn = FALSE; } catch( ... ) { } if( bReturn ) { if( szPassWord != NULL ) { szZip.SetPassword( szPassWord ); } if( pZipI.szComment != NULL ) { szZip.SetGlobalComment( pZipI.szComment ); hb_xfree( pZipI.szComment ); } if( HB_IS_BLOCK( pProgress ) ) { pProgressInfo = pProgress; szZip.SetCallback( &spanac ); } for( ulCount = 1; ( ulCount <= hb_arrayLen( pArray ) ); ulCount++ ) { szDummy = ( char * ) hb_arrayGetCPtr( pArray, ulCount ); dwSize = GetCurrentFileSize( szDummy ); bAdded = FALSE; szDummyLower = hb_strdup( ( char * ) szDummy ); #ifdef HB_OS_WIN_32 hb_strLower( szDummyLower, strlen( szDummyLower ) ); #endif // Prevent adding current archive file ! if( strstr( szFileLower, szDummyLower ) == NULL && strstr( szDummyLower, szFileLower ) == NULL ) { if( dwSize != ( DWORD ) -1 ) { if( pBlock != NULL ) { PHB_ITEM FileName = hb_itemPutC( NULL, hb_arrayGetCPtr( pArray, ulCount ) ), FilePos = hb_itemPutNI( NULL, ulCount ); hb_vmEvalBlockV( pBlock, 2, FileName, FilePos ); hb_itemRelease( FileName ); hb_itemRelease( FilePos ); } try { if( bPath && ! bAdded ) { szZip.AddNewFile( szDummy, iCompLevel, true, CZipArchive::zipsmSafeSmart, 65536 ); bAdded = TRUE; } else if( ! bDrive && ! bPath && ! bAdded ) { szZip.AddNewFile( szDummy, iCompLevel, false, CZipArchive::zipsmSafeSmart, 65536 ); } } catch( ... ) { } } } hb_xfree( szDummyLower ); } } hb_xfree( szFileLower ); try { szZip.Close(); } catch( CZipException ) { bReturn = FALSE; } catch( ... ) { } return ( int ) bReturn; }
/* Mark a passed item as used so it will be not released by the GC */ void hb_gcItemRef( HB_ITEM_PTR pItem ) { HB_THREAD_STUB ULONG ulSize; HB_ITEM FakedItem; PHB_ITEM pKey; PHB_ITEM pValue; HB_CODEBLOCK_PTR pCBlock; USHORT ui; #ifdef SIMULATE_ITEMREF_RECURSION PITEMREF_RESUMEINFO pResumeInfo = (PITEMREF_RESUMEINFO) hb_xgrab( sizeof( ITEMREF_RESUMEINFO ) ); int iResumeCounter = 0; #endif FakedItem.type = HB_IT_ARRAY; ItemRef_Top: while( HB_IS_BYREF( pItem ) ) { if( HB_IS_EXTREF( pItem ) ) { pItem->item.asExtRef.func->mark( pItem->item.asExtRef.value ); RETURN_OR_RESUME_ITEMREF(); } if( HB_IS_MEMVAR( pItem ) == FALSE ) { if( pItem->item.asRefer.offset == 0 ) { FakedItem.item.asArray.value = pItem->item.asRefer.BasePtr.pBaseArray; //hb_gcItemRef( &FakedItem ); NESTED_ITEMREF( &FakedItem, 1 ); ItemRef_ResumePoint_1: // return; RETURN_OR_RESUME_ITEMREF(); } } else { if( HB_VM_STACK.pPos == HB_VM_STACK.pItems ) { //return; RETURN_OR_RESUME_ITEMREF(); } } pItem = hb_itemUnRefOnce( pItem ); } if( HB_IS_ARRAY( pItem ) ) { HB_GARBAGE_PTR pAlloc = ( HB_GARBAGE_PTR ) pItem->item.asArray.value; //printf( "Array %p\n", pItem->item.asArray.value ); --pAlloc; /* Check this array only if it was not checked yet */ if( pAlloc->used == s_uUsedFlag ) { ulSize = pItem->item.asArray.value->ulLen; /* mark this block as used so it will be no re-checked from * other references */ pAlloc->used ^= HB_GC_USED_FLAG; /* mark also all array elements */ pItem = pItem->item.asArray.value->pItems; //printf( "Items %p\n", pItem ); while( ulSize ) { //printf( "Item %p\n", pItem ); //hb_gcItemRef( pItem ); NESTED_ITEMREF( pItem, 2 ); ItemRef_ResumePoint_2: ++pItem; --ulSize; } } } else if( HB_IS_HASH( pItem ) ) { HB_GARBAGE_PTR pAlloc = ( HB_GARBAGE_PTR ) pItem->item.asHash.value; --pAlloc; /* Check this hash only if it was not checked yet */ if( pAlloc->used == s_uUsedFlag ) { ulSize = pItem->item.asHash.value->ulLen; pKey = pItem->item.asHash.value->pKeys; pValue = pItem->item.asHash.value->pValues; /* mark this block as used so it will be no re-checked from * other references */ pAlloc->used ^= HB_GC_USED_FLAG; /* mark also all hash elements */ while( ulSize ) { //printf( "Kry %p Value: %p\n", pKey, pValue ); //hb_gcItemRef( pKey ); NESTED_ITEMREF( pKey, 3 ); ItemRef_ResumePoint_3: //hb_gcItemRef( pValue ); NESTED_ITEMREF( pValue, 4 ); ItemRef_ResumePoint_4: ++pKey; ++pValue; --ulSize; } } } else if( HB_IS_BLOCK( pItem ) ) { HB_GARBAGE_PTR pAlloc = ( HB_GARBAGE_PTR ) pItem->item.asBlock.value; --pAlloc; /* Check this block only if it was not checked yet */ if( pAlloc->used == s_uUsedFlag ) { pCBlock = pItem->item.asBlock.value; ui = 1; pAlloc->used ^= HB_GC_USED_FLAG; /* mark this codeblock as used */ /* mark as used all detached variables in a codeblock */ while( ui <= pCBlock->uiLocals ) { //hb_gcItemRef( &pCBlock->pLocals[ ui ] ); NESTED_ITEMREF( &pCBlock->pLocals[ ui ] , 5 ); ItemRef_ResumePoint_5: ++ui; } } } else if( HB_IS_POINTER( pItem ) ) { /* check if this memory was allocated by a hb_gcAlloc() */ if ( pItem->item.asPointer.collect ) { HB_GARBAGE_PTR pAlloc = ( HB_GARBAGE_PTR ) pItem->item.asPointer.value; --pAlloc; /* Check this memory only if it was not checked yet */ if( pAlloc->used == s_uUsedFlag ) { /* mark this memory as used so it will be no re-checked from * other references */ pAlloc->used ^= HB_GC_USED_FLAG; } } } /* all other data types don't need the GC */ RETURN_OR_RESUME_ITEMREF(); }