static PHB_SOCKEX s_sockexNew( HB_SOCKET sd, PHB_ITEM pParams ) { PHB_SOCKEX pSock; HB_BOOL fServer = HB_FALSE; HB_MAXINT timeout = -1; SSL * ssl = NULL; if( pParams && HB_IS_HASH( pParams ) ) { PHB_ITEM pItem; if( ssl == NULL && ( pItem = hb_hashGetCItemPtr( pParams, "ssl" ) ) != NULL ) ssl = hb_SSL_itemGet( pItem ); if( ssl == NULL && ( pItem = hb_hashGetCItemPtr( pParams, "ctx" ) ) != NULL ) ssl = hb_SSL_itemGet( pItem ); if( ssl == NULL && ( pItem = hb_hashGetCItemPtr( pParams, "key" ) ) != NULL ) ssl = hb_SSL_itemGet( pItem ); if( ( pItem = hb_hashGetCItemPtr( pParams, "timeout" ) ) != NULL && HB_IS_NUMERIC( pItem ) ) timeout = hb_itemGetNInt( pItem ); if( ( pItem = hb_hashGetCItemPtr( pParams, "server" ) ) != NULL && HB_IS_LOGICAL( pItem ) ) fServer = hb_itemGetL( pItem ); else if( ( pItem = hb_hashGetCItemPtr( pParams, "client" ) ) != NULL && HB_IS_LOGICAL( pItem ) ) fServer = ! hb_itemGetL( pItem ); } pSock = hb_sockexNewSSL( sd, ssl, fServer, timeout ); if( pSock ) hb_socekxParamsInit( pSock, pParams ); return pSock; }
RECT * hbwapi_par_RECT( RECT * p, int iParam, HB_BOOL bMandatory ) { PHB_ITEM pStru = hb_param( iParam, HB_IT_ANY ); memset( p, 0, sizeof( RECT ) ); if( pStru && HB_IS_HASH( pStru ) ) { p->left = ( LONG ) hb_itemGetNL( hb_hashGetCItemPtr( pStru, "left" ) ); p->top = ( LONG ) hb_itemGetNL( hb_hashGetCItemPtr( pStru, "top" ) ); p->right = ( LONG ) hb_itemGetNL( hb_hashGetCItemPtr( pStru, "right" ) ); p->bottom = ( LONG ) hb_itemGetNL( hb_hashGetCItemPtr( pStru, "bottom" ) ); return p; } else if( pStru && HB_IS_ARRAY( pStru ) && hb_arrayLen( pStru ) >= 4 ) { p->left = ( LONG ) hb_arrayGetNL( pStru, 1 ); p->top = ( LONG ) hb_arrayGetNL( pStru, 2 ); p->right = ( LONG ) hb_arrayGetNL( pStru, 3 ); p->bottom = ( LONG ) hb_arrayGetNL( pStru, 4 ); return p; } else if( bMandatory ) return p; return NULL; }
POINT * hbwapi_par_POINT( POINT * p, int iParam, HB_BOOL bMandatory ) { PHB_ITEM pStru = hb_param( iParam, HB_IT_ANY ); memset( p, 0, sizeof( POINT ) ); if( pStru && HB_IS_HASH( pStru ) ) { p->x = ( LONG ) hb_itemGetNL( hb_hashGetCItemPtr( pStru, "x" ) ); p->y = ( LONG ) hb_itemGetNL( hb_hashGetCItemPtr( pStru, "y" ) ); return p; } else if( pStru && HB_IS_ARRAY( pStru ) && hb_arrayLen( pStru ) >= 2 ) { p->x = ( LONG ) hb_arrayGetNL( pStru, 1 ); p->y = ( LONG ) hb_arrayGetNL( pStru, 2 ); return p; } else if( bMandatory ) return p; return NULL; }
DOCINFO * hbwapi_par_DOCINFO( DOCINFO * p, int iParam, HB_BOOL bMandatory, void *** ph ) { PHB_ITEM pStru = hb_param( iParam, HB_IT_ANY ); void ** h = ( void ** ) hb_xgrabz( 3 * sizeof( void * ) ); *ph = h; memset( p, 0, sizeof( DOCINFO ) ); p->cbSize = sizeof( DOCINFO ); if( pStru && HB_IS_HASH( pStru ) ) { p->lpszDocName = HB_ITEMGETSTR( hb_hashGetCItemPtr( pStru, "lpszDocName" ), &h[ 0 ], NULL ); p->lpszOutput = HB_ITEMGETSTR( hb_hashGetCItemPtr( pStru, "lpszOutput" ), &h[ 1 ], NULL ); p->lpszDatatype = HB_ITEMGETSTR( hb_hashGetCItemPtr( pStru, "lpszDatatype" ), &h[ 2 ], NULL ); p->fwType = ( DWORD ) hb_itemGetNL( hb_hashGetCItemPtr( pStru, "fwType" ) ); return p; } else if( bMandatory ) return p; hb_xfree( h ); *ph = NULL; return NULL; }
static PHB_I18N_TRANS hb_i18n_initialize( PHB_ITEM pTable ) { PHB_I18N_TRANS pI18N = NULL; if( HB_IS_HASH( pTable ) ) { PHB_ITEM pKey, pContext, pDefContext = NULL, pValue; pKey = hb_itemPutCConst( NULL, "CONTEXT" ); pContext = hb_hashGetItemPtr( pTable, pKey, 0 ); if( pContext ) { pKey = hb_itemPutC( pKey, NULL ); pDefContext = hb_hashGetItemPtr( pContext, pKey, 0 ); } if( pContext && pDefContext ) { pI18N = ( PHB_I18N_TRANS ) hb_xgrabz( sizeof( HB_I18N_TRANS ) ); hb_atomic_set( &pI18N->iUsers, 1 ); pI18N->table = pTable; pI18N->context_table = hb_itemNew( pContext ); pI18N->default_context = hb_itemNew( pDefContext ); pKey = hb_itemPutCConst( pKey, "BASE_CODEPAGE" ); pValue = hb_hashGetItemPtr( pTable, pKey, 0 ); if( pValue ) pI18N->base_cdpage = hb_cdpFind( hb_itemGetCPtr( pValue ) ); pKey = hb_itemPutCConst( pKey, "CODEPAGE" ); pValue = hb_hashGetItemPtr( pTable, pKey, 0 ); if( pValue ) pI18N->cdpage = hb_cdpFind( hb_itemGetCPtr( pValue ) ); pKey = hb_itemPutCConst( pKey, "BASE_LANG" ); pValue = hb_hashGetItemPtr( pTable, pKey, 0 ); if( pValue ) pI18N->base_plural_form = hb_i18n_pluralformfind( hb_itemGetCPtr( pValue ) ); pKey = hb_itemPutCConst( pKey, "LANG" ); pValue = hb_hashGetItemPtr( pTable, pKey, 0 ); if( pValue ) pI18N->plural_form = hb_i18n_pluralformfind( hb_itemGetCPtr( pValue ) ); pKey = hb_itemPutCConst( pKey, "BASE_PLURAL_EXP" ); pValue = hb_hashGetItemPtr( pTable, pKey, 0 ); if( pValue ) pI18N->base_plural_block = hb_i18n_pluralexp_compile( pValue ); pKey = hb_itemPutCConst( pKey, "PLURAL_EXP" ); pValue = hb_hashGetItemPtr( pTable, pKey, 0 ); if( pValue ) pI18N->plural_block = hb_i18n_pluralexp_compile( pValue ); } hb_itemRelease( pKey ); } return pI18N; }
void hbwapi_stor_POINT( POINT * p, int iParam ) { PHB_ITEM pStru = hb_param( iParam, HB_IT_ANY ); if( pStru && HB_IS_HASH( pStru ) ) { s_hb_hashSetCItemNL( pStru, "x", p->x ); s_hb_hashSetCItemNL( pStru, "y", p->y ); } else if( pStru && HB_IS_ARRAY( pStru ) && hb_arrayLen( pStru ) >= 2 ) { hb_arraySetNL( pStru, 1, p->x ); hb_arraySetNL( pStru, 2, p->y ); } }
void hbwapi_stor_RECT( RECT * p, int iParam ) { PHB_ITEM pStru = hb_param( iParam, HB_IT_ANY ); if( pStru && HB_IS_HASH( pStru ) ) { s_hb_hashSetCItemNL( pStru, "left" , p->left ); s_hb_hashSetCItemNL( pStru, "top" , p->top ); s_hb_hashSetCItemNL( pStru, "right" , p->right ); s_hb_hashSetCItemNL( pStru, "bottom", p->bottom ); } else if( pStru && HB_IS_ARRAY( pStru ) && hb_arrayLen( pStru ) >= 4 ) { hb_arraySetNL( pStru, 1, p->left ); hb_arraySetNL( pStru, 2, p->top ); hb_arraySetNL( pStru, 3, p->right ); hb_arraySetNL( pStru, 4, p->bottom ); } }
static HRESULT STDMETHODCALLTYPE classCreateInstance( IClassFactory * lpThis, IUnknown * punkOuter, REFIID riid, void ** ppvObj ) { HRESULT hr; HB_SYMBOL_UNUSED( lpThis ); *ppvObj = NULL; if( punkOuter ) hr = CLASS_E_NOAGGREGATION; else { PHB_ITEM pAction = NULL; HB_BOOL fGuids = HB_FALSE; if( s_pAction ) { if( HB_IS_EVALITEM( s_pAction ) ) { if( hb_vmRequestReenter() ) { hb_vmPushEvalSym(); hb_vmPush( s_pAction ); hb_vmProc( 0 ); pAction = hb_itemNew( hb_stackReturnItem() ); hb_vmRequestRestore(); } } else if( HB_IS_HASH( s_pAction ) ) { if( s_fHashClone ) pAction = hb_itemClone( s_pAction ); else if( ! s_pMsgHash && s_hashWithNumKeys( s_pAction ) ) fGuids = HB_TRUE; } } hr = s_createHbOleObject( riid, ppvObj, pAction, fGuids ); } return hr; }
void hb_socekxParamsInit( PHB_SOCKEX pSock, PHB_ITEM pParams ) { if( pParams && HB_IS_HASH( pParams ) ) { PHB_ITEM pItem; if( ( pItem = hb_hashGetCItemPtr( pParams, "readahead" ) ) != NULL && HB_IS_NUMERIC( pItem ) ) { if( pSock->buffer == NULL ) pSock->readahead = hb_itemGetNL( pItem ); } if( ( pItem = hb_hashGetCItemPtr( pParams, "flush" ) ) != NULL && HB_IS_NUMERIC( pItem ) ) pSock->iAutoFlush = hb_itemGetNI( pItem ); if( ( pItem = hb_hashGetCItemPtr( pParams, "redir" ) ) != NULL && HB_IS_LOGICAL( pItem ) ) pSock->fRedirAll = hb_itemGetL( pItem ); } }
void hb_socekxParamsGetStd( PHB_ITEM pParams, const void ** pKeydata, int * pKeylen, const void ** pIV, int * pIVlen, int * pLevel, int * pStrategy ) { if( pParams && HB_IS_HASH( pParams ) ) { PHB_ITEM pItem; if( pKeydata && pKeylen && ( pItem = hb_hashGetCItemPtr( pParams, "key" ) ) != NULL && HB_IS_STRING( pItem ) ) { *pKeydata = hb_itemGetCPtr( pItem ); *pKeylen = ( int ) hb_itemGetCLen( pItem ); } else if( pKeydata && pKeylen && ( pItem = hb_hashGetCItemPtr( pParams, "pass" ) ) != NULL && HB_IS_STRING( pItem ) ) { *pKeydata = hb_itemGetCPtr( pItem ); *pKeylen = ( int ) hb_itemGetCLen( pItem ); } if( pIV && pIVlen && ( pItem = hb_hashGetCItemPtr( pParams, "iv" ) ) != NULL && HB_IS_STRING( pItem ) ) { *pIV = hb_itemGetCPtr( pItem ); *pIVlen = ( int ) hb_itemGetCLen( pItem ); } if( pLevel && ( pItem = hb_hashGetCItemPtr( pParams, "zlib" ) ) != NULL && HB_IS_NUMERIC( pItem ) ) *pLevel = hb_itemGetNI( pItem ); if( pStrategy && ( pItem = hb_hashGetCItemPtr( pParams, "zs" ) ) != NULL && HB_IS_NUMERIC( pItem ) ) *pStrategy = hb_itemGetNI( pItem ); } }
static int s_pp_openFile( void * cargo, char * szFileName, HB_BOOL fBefore, HB_BOOL fSysFile, HB_BOOL fBinary, HB_PATHNAMES * pIncludePaths, HB_BOOL * pfNested, FILE ** file_ptr, const char ** pBufPtr, HB_SIZE * pnLen, HB_BOOL * pfFree ) { HB_SYMBOL_UNUSED( fSysFile ); HB_SYMBOL_UNUSED( fBinary ); HB_SYMBOL_UNUSED( pIncludePaths ); HB_SYMBOL_UNUSED( pfNested ); HB_SYMBOL_UNUSED( file_ptr ); if( ! fBefore ) { HB_COMP_DECL = ( PHB_COMP ) cargo; PHB_ITEM pIncItem = ( PHB_ITEM ) HB_COMP_PARAM->cargo; if( pIncItem ) { if( HB_IS_HASH( pIncItem ) ) { PHB_ITEM pFileItem = hb_hashGetCItemPtr( pIncItem, szFileName ); if( pFileItem ) { HB_SIZE nLen = hb_itemGetCLen( pFileItem ); if( nLen ) { *pBufPtr = hb_itemGetCPtr( pFileItem ); *pnLen = nLen; *pfFree = HB_FALSE; return HB_PP_OPEN_OK; } } } } } return HB_PP_OPEN_FILE; }
static HRESULT STDMETHODCALLTYPE Invoke( IDispatch * lpThis, DISPID dispid, REFIID riid, LCID lcid, WORD wFlags, DISPPARAMS * pParams, VARIANT * pVarResult, EXCEPINFO * pExcepInfo, UINT * puArgErr ) { PHB_ITEM pAction; HRESULT hr; HB_SYMBOL_UNUSED( lcid ); HB_SYMBOL_UNUSED( wFlags ); HB_SYMBOL_UNUSED( pExcepInfo ); HB_SYMBOL_UNUSED( puArgErr ); if( ! IsEqualIID( riid, HB_ID_REF( IID_NULL ) ) ) return DISP_E_UNKNOWNINTERFACE; hr = DISP_E_MEMBERNOTFOUND; pAction = ( ( ISink * ) lpThis )->pItemHandler; if( pAction ) { PHB_ITEM pKey = hb_itemPutNL( hb_stackAllocItem(), ( long ) dispid ); if( pAction && HB_IS_HASH( pAction ) ) { pAction = hb_hashGetItemPtr( pAction, pKey, 0 ); pKey = NULL; } if( pAction && hb_oleDispInvoke( NULL, pAction, pKey, pParams, pVarResult, NULL, ( ( ISink * ) lpThis )->uiClass ) ) hr = S_OK; hb_stackPop(); } return hr; }
LOGFONT * hbwapi_par_LOGFONT( LOGFONT * p, int iParam, HB_BOOL bMandatory ) { PHB_ITEM pStru = hb_param( iParam, HB_IT_ANY ); void * hfFaceName; LPCTSTR pfFaceName; HB_SIZE nLen; memset( p, 0, sizeof( LOGFONT ) ); if( pStru && HB_IS_HASH( pStru ) ) { p->lfHeight = ( LONG ) hb_itemGetNL( hb_hashGetCItemPtr( pStru, "lfHeight" ) ); p->lfWidth = ( LONG ) hb_itemGetNL( hb_hashGetCItemPtr( pStru, "lfWidth" ) ); p->lfEscapement = ( LONG ) hb_itemGetNL( hb_hashGetCItemPtr( pStru, "lfEscapement" ) ); p->lfOrientation = ( LONG ) hb_itemGetNL( hb_hashGetCItemPtr( pStru, "lfOrientation" ) ); p->lfWeight = ( LONG ) hb_itemGetNL( hb_hashGetCItemPtr( pStru, "lfWeight" ) ); p->lfItalic = ( BYTE ) hb_itemGetNI( hb_hashGetCItemPtr( pStru, "lfItalic" ) ); p->lfUnderline = ( BYTE ) hb_itemGetNI( hb_hashGetCItemPtr( pStru, "lfUnderline" ) ); p->lfStrikeOut = ( BYTE ) hb_itemGetNI( hb_hashGetCItemPtr( pStru, "lfStrikeOut" ) ); p->lfCharSet = ( BYTE ) hb_itemGetNI( hb_hashGetCItemPtr( pStru, "lfCharSet" ) ); p->lfOutPrecision = ( BYTE ) hb_itemGetNI( hb_hashGetCItemPtr( pStru, "lfOutPrecision" ) ); p->lfClipPrecision = ( BYTE ) hb_itemGetNI( hb_hashGetCItemPtr( pStru, "lfClipPrecision" ) ); p->lfQuality = ( BYTE ) hb_itemGetNI( hb_hashGetCItemPtr( pStru, "lfQuality" ) ); p->lfPitchAndFamily = ( BYTE ) hb_itemGetNI( hb_hashGetCItemPtr( pStru, "lfPitchAndFamily" ) ); pfFaceName = HB_ITEMGETSTR( hb_hashGetCItemPtr( pStru, "lfFaceName" ), &hfFaceName, &nLen ); if( nLen > ( LF_FACESIZE - 1 ) ) nLen = LF_FACESIZE - 1; memcpy( p->lfFaceName, pfFaceName, nLen * sizeof( TCHAR ) ); p->lfFaceName[ nLen ] = TEXT( '\0' ); hb_strfree( hfFaceName ); return p; } else if( pStru && HB_IS_ARRAY( pStru ) && hb_arrayLen( pStru ) >= 14 ) { p->lfHeight = ( LONG ) hb_arrayGetNL( pStru, 1 ); p->lfWidth = ( LONG ) hb_arrayGetNL( pStru, 2 ); p->lfEscapement = ( LONG ) hb_arrayGetNL( pStru, 3 ); p->lfOrientation = ( LONG ) hb_arrayGetNL( pStru, 4 ); p->lfWeight = ( LONG ) hb_arrayGetNL( pStru, 5 ); p->lfItalic = ( BYTE ) hb_arrayGetNI( pStru, 6 ); p->lfUnderline = ( BYTE ) hb_arrayGetNI( pStru, 7 ); p->lfStrikeOut = ( BYTE ) hb_arrayGetNI( pStru, 8 ); p->lfCharSet = ( BYTE ) hb_arrayGetNI( pStru, 9 ); p->lfOutPrecision = ( BYTE ) hb_arrayGetNI( pStru, 10 ); p->lfClipPrecision = ( BYTE ) hb_arrayGetNI( pStru, 11 ); p->lfQuality = ( BYTE ) hb_arrayGetNI( pStru, 12 ); p->lfPitchAndFamily = ( BYTE ) hb_arrayGetNI( pStru, 13 ); pfFaceName = HB_ARRAYGETSTR( pStru, 14, &hfFaceName, &nLen ); if( nLen > ( LF_FACESIZE - 1 ) ) nLen = LF_FACESIZE - 1; memcpy( p->lfFaceName, pfFaceName, nLen * sizeof( TCHAR ) ); p->lfFaceName[ nLen ] = TEXT( '\0' ); hb_strfree( hfFaceName ); return p; } else if( bMandatory ) return p; return NULL; }
static HRESULT STDMETHODCALLTYPE Invoke( IDispatch * lpThis, DISPID dispid, REFIID riid, LCID lcid, WORD wFlags, DISPPARAMS * pParams, VARIANT * pVarResult, EXCEPINFO * pExcepInfo, UINT * puArgErr ) { PHB_DYNS pDynSym; PHB_ITEM pAction; HB_USHORT uiClass = 0; HB_SYMBOL_UNUSED( lcid ); HB_SYMBOL_UNUSED( pExcepInfo ); HB_SYMBOL_UNUSED( puArgErr ); if( ! IsEqualIID( riid, HB_ID_REF( IID_NULL ) ) ) return DISP_E_UNKNOWNINTERFACE; pAction = ( ( IHbOleServer * ) lpThis )->pAction; if( ! pAction ) pAction = s_pAction; if( pAction ) { HB_BOOL fResult = HB_FALSE; if( s_pMsgHash ) { if( ( wFlags & DISPATCH_METHOD ) != 0 || ( ( wFlags & DISPATCH_PROPERTYGET ) != 0 && pParams->cArgs == 0 ) || ( ( wFlags & DISPATCH_PROPERTYPUT ) != 0 && pParams->cArgs == 1 ) ) { fResult = hb_oleDispInvoke( NULL, pAction, hb_hashGetKeyAt( s_pMsgHash, ( HB_SIZE ) dispid ), pParams, pVarResult, s_objItemToVariant, uiClass ); } } else if( HB_IS_HASH( pAction ) ) { PHB_ITEM pItem; if( ( ( IHbOleServer * ) lpThis )->fGuids ) { PHB_ITEM pKey = hb_itemPutNL( hb_stackAllocItem(), ( long ) dispid ); pItem = hb_hashGetItemPtr( pAction, pKey, 0 ); hb_stackPop(); } else pItem = hb_hashGetValueAt( pAction, ( HB_SIZE ) dispid ); if( pItem ) { if( HB_IS_EVALITEM( pItem ) ) { if( ( wFlags & DISPATCH_METHOD ) != 0 ) { PHB_SYMB pSym = hb_itemGetSymbol( pItem ); fResult = hb_oleDispInvoke( pSym, pSym ? pAction : pItem, NULL, pParams, pVarResult, s_objItemToVariant, uiClass ); } } else if( ( wFlags & DISPATCH_PROPERTYGET ) != 0 && pParams->cArgs == 0 ) { if( pVarResult ) hb_oleItemToVariantEx( pVarResult, pItem, s_objItemToVariant ); fResult = HB_TRUE; } else if( ( wFlags & DISPATCH_PROPERTYPUT ) != 0 && pParams->cArgs == 1 ) { hb_oleVariantToItemEx( pItem, &pParams->rgvarg[ 0 ], uiClass ); fResult = HB_TRUE; } } } else if( HB_IS_OBJECT( pAction ) ) { pDynSym = hb_dispIdToDynsym( dispid ); if( pDynSym && ( wFlags & DISPATCH_PROPERTYPUT ) != 0 ) { if( pParams->cArgs == 1 ) { char szName[ HB_SYMBOL_NAME_LEN + 1 ]; szName[ 0 ] = '_'; hb_strncpy( szName + 1, hb_dynsymName( pDynSym ), sizeof( szName ) - 2 ); pDynSym = hb_dynsymFindName( szName ); } else pDynSym = NULL; } if( pDynSym && hb_objHasMessage( pAction, pDynSym ) ) { fResult = hb_oleDispInvoke( hb_dynsymSymbol( pDynSym ), pAction, NULL, pParams, pVarResult, s_objItemToVariant, uiClass ); } } if( ! fResult ) return DISP_E_MEMBERNOTFOUND; } else { pDynSym = hb_dispIdToDynsym( dispid ); if( ! pDynSym ) return DISP_E_MEMBERNOTFOUND; if( wFlags & DISPATCH_PROPERTYPUT ) { if( pParams->cArgs == 1 && hb_dynsymIsMemvar( pDynSym ) ) { PHB_ITEM pItem = hb_stackAllocItem(); hb_oleVariantToItemEx( pItem, &pParams->rgvarg[ 0 ], uiClass ); hb_memvarSetValue( hb_dynsymSymbol( pDynSym ), pItem ); hb_stackPop(); return S_OK; } else return DISP_E_MEMBERNOTFOUND; } else if( ( wFlags & DISPATCH_PROPERTYGET ) && pParams->cArgs == 0 && hb_dynsymIsMemvar( pDynSym ) ) { if( pVarResult ) { PHB_ITEM pItem = hb_stackAllocItem(); hb_memvarGet( pItem, hb_dynsymSymbol( pDynSym ) ); hb_oleItemToVariantEx( pVarResult, pItem, s_objItemToVariant ); hb_stackPop(); } return S_OK; } else if( ( wFlags & DISPATCH_METHOD ) == 0 || ! hb_dynsymIsFunction( pDynSym ) ) return DISP_E_MEMBERNOTFOUND; else if( ! hb_oleDispInvoke( hb_dynsymSymbol( pDynSym ), NULL, NULL, pParams, pVarResult, s_objItemToVariant, uiClass ) ) return DISP_E_MEMBERNOTFOUND; } return S_OK; }
static HRESULT STDMETHODCALLTYPE GetIDsOfNames( IDispatch * lpThis, REFIID riid, LPOLESTR * rgszNames, UINT cNames, LCID lcid, DISPID * rgDispId ) { HRESULT hr = S_OK; HB_SYMBOL_UNUSED( lcid ); if( ! IsEqualIID( riid, HB_ID_REF( IID_NULL ) ) ) hr = DISP_E_UNKNOWNINTERFACE; else if( ( ( IHbOleServer * ) lpThis )->fGuids ) return E_NOTIMPL; else if( cNames > 0 ) { char szName[ HB_SYMBOL_NAME_LEN + 1 ]; DISPID dispid = 0; UINT ui; if( s_WideToAnsiBuffer( rgszNames[ 0 ], szName, ( int ) sizeof( szName ) ) != 0 ) { PHB_ITEM pAction; pAction = ( ( IHbOleServer * ) lpThis )->pAction; if( ! pAction ) pAction = s_pAction; if( pAction ) { if( s_pMsgHash ) { HB_SIZE nPos = hb_hashGetCItemPos( s_pMsgHash, szName ); if( nPos == 0 ) { PHB_ITEM pKey = hb_itemPutC( hb_stackAllocItem(), szName ); if( hb_hashAdd( s_pMsgHash, pKey, NULL ) ) hb_hashScan( s_pMsgHash, pKey, &nPos ); hb_stackPop(); } dispid = ( DISPID ) nPos; } else if( HB_IS_HASH( pAction ) ) { HB_SIZE nPos = hb_hashGetCItemPos( pAction, szName ); if( nPos ) dispid = ( DISPID ) nPos; } else if( HB_IS_OBJECT( pAction ) ) { PHB_DYNS pDynSym = hb_dynsymFindName( szName ); if( pDynSym && hb_objHasMessage( pAction, pDynSym ) ) dispid = hb_dynsymToDispId( pDynSym ); } } else { PHB_DYNS pDynSym = hb_dynsymFindName( szName ); if( pDynSym && ( hb_dynsymIsFunction( pDynSym ) || hb_dynsymIsMemvar( pDynSym ) ) ) dispid = hb_dynsymToDispId( pDynSym ); } } for( ui = 0; ui < cNames; ++ui ) rgDispId[ ui ] = DISPID_UNKNOWN; hr = DISP_E_UNKNOWNNAME; if( dispid ) { rgDispId[ 0 ] = dispid; if( cNames == 1 ) hr = S_OK; } } return hr; }
static void _hb_jsonEncode( PHB_ITEM pValue, PHB_JSON_ENCODE_CTX pCtx, HB_SIZE nLevel, HB_BOOL fEOL, PHB_CODEPAGE cdp ) { /* Protection against recursive structures */ if( ( HB_IS_ARRAY( pValue ) || HB_IS_HASH( pValue ) ) && hb_itemSize( pValue ) > 0 ) { void * id = HB_IS_HASH( pValue ) ? hb_hashId( pValue ) : hb_arrayId( pValue ); HB_SIZE nIndex; for( nIndex = 0; nIndex < nLevel; nIndex++ ) { if( pCtx->pId[ nIndex ] == id ) { if( ! fEOL && pCtx->fHuman ) _hb_jsonCtxAddIndent( pCtx, nLevel * INDENT_SIZE ); _hb_jsonCtxAdd( pCtx, "null", 4 ); return; } } if( nLevel >= pCtx->nAllocId ) { pCtx->nAllocId += 8; pCtx->pId = ( void ** ) hb_xrealloc( pCtx->pId, sizeof( void * ) * pCtx->nAllocId ); } pCtx->pId[ nLevel ] = id; } if( fEOL ) { --pCtx->pHead; _hb_jsonCtxAdd( pCtx, pCtx->szEol, pCtx->iEolLen ); } if( HB_IS_STRING( pValue ) ) { HB_SIZE nPos, nLen = hb_itemGetCLen( pValue ); const char * szString = hb_itemGetCPtr( pValue ); char buf[ 8 ]; _hb_jsonCtxAdd( pCtx, "\"", 1 ); if( cdp ) { HB_WCHAR wc; nPos = 0; while( HB_CDPCHAR_GET( cdp, szString, nLen, &nPos, &wc ) ) { if( wc >= ' ' && wc < 0x7F && wc != '\\' && wc != '\"' ) { buf[ 0 ] = ( char ) wc; _hb_jsonCtxAdd( pCtx, buf, 1 ); continue; } switch( wc ) { case '\\': _hb_jsonCtxAdd( pCtx, "\\\\", 2 ); break; case '\"': _hb_jsonCtxAdd( pCtx, "\\\"", 2 ); break; case '\b': _hb_jsonCtxAdd( pCtx, "\\b", 2 ); break; case '\f': _hb_jsonCtxAdd( pCtx, "\\f", 2 ); break; case '\n': _hb_jsonCtxAdd( pCtx, "\\n", 2 ); break; case '\r': _hb_jsonCtxAdd( pCtx, "\\r", 2 ); break; case '\t': _hb_jsonCtxAdd( pCtx, "\\t", 2 ); break; default: hb_snprintf( buf, sizeof( buf ), "\\u%04X", wc ); _hb_jsonCtxAdd( pCtx, buf, 6 ); break; } } } else { nPos = 0; while( nPos < nLen ) { unsigned char uch = szString[ nPos ]; HB_SIZE nPos2 = nPos; while( uch >= ' ' && uch != '\\' && uch != '\"' ) uch = szString[ ++nPos2 ]; if( nPos2 > nPos ) { _hb_jsonCtxAdd( pCtx, szString + nPos, nPos2 - nPos ); if( nPos2 >= nLen ) break; nPos = nPos2; } switch( uch ) { case '\\': _hb_jsonCtxAdd( pCtx, "\\\\", 2 ); break; case '\"': _hb_jsonCtxAdd( pCtx, "\\\"", 2 ); break; case '\b': _hb_jsonCtxAdd( pCtx, "\\b", 2 ); break; case '\f': _hb_jsonCtxAdd( pCtx, "\\f", 2 ); break; case '\n': _hb_jsonCtxAdd( pCtx, "\\n", 2 ); break; case '\r': _hb_jsonCtxAdd( pCtx, "\\r", 2 ); break; case '\t': _hb_jsonCtxAdd( pCtx, "\\t", 2 ); break; default: hb_snprintf( buf, sizeof( buf ), "\\u00%02X", uch ); _hb_jsonCtxAdd( pCtx, buf, 6 ); break; } nPos++; } } _hb_jsonCtxAdd( pCtx, "\"", 1 ); } else if( HB_IS_NUMINT( pValue ) ) { char buf[ 24 ]; HB_MAXINT nVal = hb_itemGetNInt( pValue ); HB_BOOL fNeg = nVal < 0; int i = 0; if( fNeg ) nVal = -nVal; do buf[ sizeof( buf ) - ++i ] = ( nVal % 10 ) + '0'; while( ( nVal /= 10 ) != 0 ); if( fNeg ) buf[ sizeof( buf ) - ++i ] = '-'; _hb_jsonCtxAdd( pCtx, &buf[ sizeof( buf ) - i ], i ); } else if( HB_IS_NUMERIC( pValue ) ) { char buf[ 64 ]; int iDec; double dblValue = hb_itemGetNDDec( pValue, &iDec ); hb_snprintf( buf, sizeof( buf ), "%.*f", iDec, dblValue ); _hb_jsonCtxAdd( pCtx, buf, strlen( buf ) ); } else if( HB_IS_NIL( pValue ) ) { _hb_jsonCtxAdd( pCtx, "null", 4 ); } else if( HB_IS_LOGICAL( pValue ) ) { if( hb_itemGetL( pValue ) ) _hb_jsonCtxAdd( pCtx, "true", 4 ); else _hb_jsonCtxAdd( pCtx, "false", 5 ); } else if( HB_IS_DATE( pValue ) ) { char szBuffer[ 10 ]; hb_itemGetDS( pValue, szBuffer + 1 ); szBuffer[ 0 ] = '\"'; szBuffer[ 9 ] = '\"'; _hb_jsonCtxAdd( pCtx, szBuffer, 10 ); } else if( HB_IS_TIMESTAMP( pValue ) ) { char szBuffer[ 19 ]; hb_itemGetTS( pValue, szBuffer + 1 ); szBuffer[ 0 ] = '\"'; szBuffer[ 18 ] = '\"'; _hb_jsonCtxAdd( pCtx, szBuffer, 19 ); } else if( HB_IS_ARRAY( pValue ) ) { HB_SIZE nLen = hb_itemSize( pValue ); if( nLen ) { HB_SIZE nIndex; if( pCtx->fHuman ) _hb_jsonCtxAddIndent( pCtx, nLevel * INDENT_SIZE ); _hb_jsonCtxAdd( pCtx, "[", 1 ); for( nIndex = 1; nIndex <= nLen; nIndex++ ) { PHB_ITEM pItem = hb_arrayGetItemPtr( pValue, nIndex ); if( nIndex > 1 ) _hb_jsonCtxAdd( pCtx, ",", 1 ); if( pCtx->fHuman ) _hb_jsonCtxAdd( pCtx, pCtx->szEol, pCtx->iEolLen ); if( pCtx->fHuman && ! ( ( HB_IS_ARRAY( pItem ) || HB_IS_HASH( pItem ) ) && hb_itemSize( pItem ) > 0 ) ) _hb_jsonCtxAddIndent( pCtx, ( nLevel + 1 ) * INDENT_SIZE ); _hb_jsonEncode( pItem, pCtx, nLevel + 1, HB_FALSE, cdp ); } if( pCtx->fHuman ) { _hb_jsonCtxAdd( pCtx, pCtx->szEol, pCtx->iEolLen ); _hb_jsonCtxAddIndent( pCtx, nLevel * INDENT_SIZE ); } _hb_jsonCtxAdd( pCtx, "]", 1 ); } else _hb_jsonCtxAdd( pCtx, "[]", 2 ); } else if( HB_IS_HASH( pValue ) ) { HB_SIZE nLen = hb_hashLen( pValue ); if( nLen ) { HB_SIZE nIndex; if( pCtx->fHuman ) _hb_jsonCtxAddIndent( pCtx, nLevel * INDENT_SIZE ); _hb_jsonCtxAdd( pCtx, "{", 1 ); for( nIndex = 1; nIndex <= nLen; nIndex++ ) { PHB_ITEM pKey = hb_hashGetKeyAt( pValue, nIndex ); if( HB_IS_STRING( pKey ) ) { PHB_ITEM pItem = hb_hashGetValueAt( pValue, nIndex ); if( nIndex > 1 ) _hb_jsonCtxAdd( pCtx, ",", 1 ); if( pCtx->fHuman ) { _hb_jsonCtxAdd( pCtx, pCtx->szEol, pCtx->iEolLen ); _hb_jsonCtxAddIndent( pCtx, ( nLevel + 1 ) * INDENT_SIZE ); } _hb_jsonEncode( pKey, pCtx, nLevel + 1, HB_FALSE, cdp ); if( pCtx->fHuman ) { _hb_jsonCtxAdd( pCtx, ": ", 2 ); fEOL = ( HB_IS_ARRAY( pItem ) || HB_IS_HASH( pItem ) ) && hb_itemSize( pItem ) > 0; } else { _hb_jsonCtxAdd( pCtx, ":", 1 ); fEOL = HB_FALSE; } _hb_jsonEncode( pItem, pCtx, nLevel + 1, fEOL, cdp ); } } if( pCtx->fHuman ) { _hb_jsonCtxAdd( pCtx, pCtx->szEol, pCtx->iEolLen ); _hb_jsonCtxAddIndent( pCtx, nLevel * INDENT_SIZE ); } _hb_jsonCtxAdd( pCtx, "}", 1 ); } else _hb_jsonCtxAdd( pCtx, "{}", 2 ); } else { /* All unsupported types are replacd by null */ _hb_jsonCtxAdd( pCtx, "null", 4 ); } }
static PHB_SOCKEX s_sockexNext( PHB_SOCKEX pSock, PHB_ITEM pParams ) { PHB_SOCKEX pSockNew = NULL; if( pSock ) { HB_BOOL fDecompressIn = HB_TRUE, fCompressOut = HB_TRUE; int level = HB_ZLIB_COMPRESSION_DEFAULT, strategy = HB_ZLIB_STRATEGY_DEFAULT, windowBitsIn = MAX_WBITS, windowBitsOut = MAX_WBITS; if( pParams && HB_IS_HASH( pParams ) ) { PHB_ITEM pItem; if( ( pItem = hb_hashGetCItemPtr( pParams, "zlib" ) ) != NULL && HB_IS_NUMERIC( pItem ) ) level = hb_itemGetNI( pItem ); if( ( pItem = hb_hashGetCItemPtr( pParams, "zs" ) ) != NULL && HB_IS_NUMERIC( pItem ) ) strategy = hb_itemGetNI( pItem ); if( ( pItem = hb_hashGetCItemPtr( pParams, "gzin" ) ) != NULL && HB_IS_LOGICAL( pItem ) ) { fDecompressIn = hb_itemGetL( pItem ); if( fDecompressIn ) windowBitsIn += 16; } if( ( pItem = hb_hashGetCItemPtr( pParams, "zin" ) ) != NULL && HB_IS_LOGICAL( pItem ) ) { if( windowBitsIn == MAX_WBITS ) fDecompressIn = hb_itemGetL( pItem ); else if( hb_itemGetL( pItem ) ) windowBitsIn += 16; } if( ( pItem = hb_hashGetCItemPtr( pParams, "gzout" ) ) != NULL && HB_IS_LOGICAL( pItem ) ) { fCompressOut = hb_itemGetL( pItem ); if( fCompressOut ) windowBitsOut += 16; } if( ( pItem = hb_hashGetCItemPtr( pParams, "zout" ) ) != NULL && HB_IS_LOGICAL( pItem ) && windowBitsOut == MAX_WBITS ) fCompressOut = hb_itemGetL( pItem ); } if( level != HB_ZLIB_COMPRESSION_DISABLE && ( fDecompressIn || fCompressOut ) ) { PHB_SOCKEX_Z pZ = ( PHB_SOCKEX_Z ) hb_xgrabz( sizeof( HB_SOCKEX_Z ) ); pSockNew = ( PHB_SOCKEX ) hb_xgrabz( sizeof( HB_SOCKEX ) ); pSockNew->sd = HB_NO_SOCKET; pSockNew->fRedirAll = HB_TRUE; pSockNew->pFilter = &s_sockFilter; pSockNew->cargo = ( void * ) pZ; pZ->z_read.zalloc = s_zsock_zalloc; pZ->z_read.zfree = s_zsock_zfree; pZ->z_read.opaque = Z_NULL; pZ->z_write.zalloc = s_zsock_zalloc; pZ->z_write.zfree = s_zsock_zfree; pZ->z_write.opaque = Z_NULL; pZ->z_read.next_in = NULL; pZ->z_read.avail_in = 0; if( level != Z_DEFAULT_COMPRESSION && !( level >= Z_NO_COMPRESSION && level <= Z_BEST_COMPRESSION ) ) level = Z_DEFAULT_COMPRESSION; if( strategy != Z_FILTERED && #if defined( Z_RLE ) strategy != Z_RLE && #endif #if defined( Z_FIXED ) strategy != Z_FIXED && #endif strategy != Z_HUFFMAN_ONLY ) strategy = Z_DEFAULT_STRATEGY; if( fDecompressIn && level != HB_ZLIB_COMPRESSION_DISABLE ) { /* MAX_WBITS=15, decompression - support for formats: * -15: raw, 15: ZLIB, 31: GZIP, 47: ZLIB+GZIP */ if( inflateInit2( &pZ->z_read, windowBitsIn ) == Z_OK ) { pZ->fDecompressIn = HB_TRUE; pZ->rdbuf = ( HB_BYTE * ) hb_xgrab( HB_ZSOCK_RDBUFSIZE ); } else level = HB_ZLIB_COMPRESSION_DISABLE; } if( fCompressOut && level != HB_ZLIB_COMPRESSION_DISABLE ) { /* MAX_WBITS=15, compression format: * -15: raw, 15: ZLIB (+6 bytes), 31: GZIP(+18 bytes) */ if( deflateInit2( &pZ->z_write, level, Z_DEFLATED, windowBitsOut, HB_ZSOCK_MEM_LEVEL, strategy ) == Z_OK ) { pZ->fCompressOut = HB_TRUE; pZ->wrbuf = ( HB_BYTE * ) hb_xgrab( HB_ZSOCK_WRBUFSIZE ); pZ->z_write.next_out = ( Bytef * ) pZ->wrbuf; pZ->z_write.avail_out = HB_ZSOCK_WRBUFSIZE; } else level = HB_ZLIB_COMPRESSION_DISABLE; } if( level != HB_ZLIB_COMPRESSION_DISABLE ) { pSockNew->sd = pSock->sd; pSockNew->fShutDown = pSock->fShutDown; pSockNew->iAutoFlush = pSock->iAutoFlush; pZ->sock = pSock; hb_socekxParamsInit( pSockNew, pParams ); } else { s_sockexClose( pSockNew, HB_FALSE ); pSockNew = NULL; } } } return pSockNew; }
static void _hb_jsonEncode( PHB_ITEM pValue, PHB_JSON_ENCODE_CTX pCtx, HB_SIZE nLevel, HB_BOOL fEOL ) { /* Protection against recursive structures */ if( ( HB_IS_ARRAY( pValue ) || HB_IS_HASH( pValue ) ) && hb_itemSize( pValue ) > 0 ) { void * id = HB_IS_HASH( pValue ) ? hb_hashId( pValue ) : hb_arrayId( pValue ); HB_SIZE nIndex; for( nIndex = 0; nIndex < nLevel; nIndex++ ) { if( pCtx->pId[ nIndex ] == id ) { if( ! fEOL && pCtx->fHuman ) _hb_jsonCtxAddIndent( pCtx, nLevel * INDENT_SIZE ); _hb_jsonCtxAdd( pCtx, "null", 4 ); return; } } if( nLevel >= pCtx->nAllocId ) { pCtx->nAllocId += 8; pCtx->pId = ( void ** ) hb_xrealloc( pCtx->pId, sizeof( void * ) * pCtx->nAllocId ); } pCtx->pId[ nLevel ] = id; } if( fEOL ) { --pCtx->pHead; _hb_jsonCtxAdd( pCtx, pCtx->szEol, pCtx->iEolLen ); } if( HB_IS_STRING( pValue ) ) { const char * szString = hb_itemGetCPtr( pValue ); HB_SIZE nPos, nPos2, nLen = hb_itemGetCLen( pValue ); _hb_jsonCtxAdd( pCtx, "\"", 1 ); nPos = 0; while( nPos < nLen ) { nPos2 = nPos; while( *( ( const unsigned char * ) szString + nPos2 ) >= ' ' && szString[ nPos2 ] != '\\' && szString[ nPos2 ] != '\"' ) nPos2++; if( nPos2 > nPos ) { _hb_jsonCtxAdd( pCtx, szString + nPos, nPos2 - nPos ); nPos = nPos2; continue; } switch( szString[ nPos ] ) { case '\\': _hb_jsonCtxAdd( pCtx, "\\\\", 2 ); break; case '\"': _hb_jsonCtxAdd( pCtx, "\\\"", 2 ); break; case '\b': _hb_jsonCtxAdd( pCtx, "\\b", 2 ); break; case '\f': _hb_jsonCtxAdd( pCtx, "\\f", 2 ); break; case '\n': _hb_jsonCtxAdd( pCtx, "\\n", 2 ); break; case '\r': _hb_jsonCtxAdd( pCtx, "\\r", 2 ); break; case '\t': _hb_jsonCtxAdd( pCtx, "\\t", 2 ); break; default: { char buf[ 8 ]; hb_snprintf( buf, sizeof( buf ), "\\u00%02X", ( unsigned char ) szString[ nPos ] ); _hb_jsonCtxAdd( pCtx, buf, 6 ); break; } } nPos++; } _hb_jsonCtxAdd( pCtx, "\"", 1 ); } else if( HB_IS_NUMINT( pValue ) ) { char buf[ 32 ]; hb_snprintf( buf, sizeof( buf ), "%" PFHL "d", hb_itemGetNInt( pValue ) ); _hb_jsonCtxAdd( pCtx, buf, strlen( buf ) ); } else if( HB_IS_NUMERIC( pValue ) ) { char buf[ 64 ]; int iDec; double dblValue = hb_itemGetNDDec( pValue, &iDec ); hb_snprintf( buf, sizeof( buf ), "%.*f", iDec, dblValue ); _hb_jsonCtxAdd( pCtx, buf, strlen( buf ) ); } else if( HB_IS_NIL( pValue ) ) { _hb_jsonCtxAdd( pCtx, "null", 4 ); } else if( HB_IS_LOGICAL( pValue ) ) { if( hb_itemGetL( pValue ) ) _hb_jsonCtxAdd( pCtx, "true", 4 ); else _hb_jsonCtxAdd( pCtx, "false", 5 ); } else if( HB_IS_DATE( pValue ) ) { char szBuffer[ 10 ]; hb_itemGetDS( pValue, szBuffer + 1 ); szBuffer[ 0 ] = '\"'; szBuffer[ 9 ] = '\"'; _hb_jsonCtxAdd( pCtx, szBuffer, 10 ); } else if( HB_IS_TIMESTAMP( pValue ) ) { char szBuffer[ 19 ]; hb_itemGetTS( pValue, szBuffer + 1 ); szBuffer[ 0 ] = '\"'; szBuffer[ 18 ] = '\"'; _hb_jsonCtxAdd( pCtx, szBuffer, 19 ); } else if( HB_IS_ARRAY( pValue ) ) { HB_SIZE nLen = hb_itemSize( pValue ); if( nLen ) { HB_SIZE nIndex; if( pCtx->fHuman ) _hb_jsonCtxAddIndent( pCtx, nLevel * INDENT_SIZE ); _hb_jsonCtxAdd( pCtx, "[", 1 ); for( nIndex = 1; nIndex <= nLen; nIndex++ ) { PHB_ITEM pItem = hb_arrayGetItemPtr( pValue, nIndex ); if( nIndex > 1 ) _hb_jsonCtxAdd( pCtx, ",", 1 ); if( pCtx->fHuman ) _hb_jsonCtxAdd( pCtx, pCtx->szEol, pCtx->iEolLen ); if( pCtx->fHuman && ! ( ( HB_IS_ARRAY( pItem ) || HB_IS_HASH( pItem ) ) && hb_itemSize( pItem ) > 0 ) ) _hb_jsonCtxAddIndent( pCtx, ( nLevel + 1 ) * INDENT_SIZE ); _hb_jsonEncode( pItem, pCtx, nLevel + 1, HB_FALSE ); } if( pCtx->fHuman ) { _hb_jsonCtxAdd( pCtx, pCtx->szEol, pCtx->iEolLen ); _hb_jsonCtxAddIndent( pCtx, nLevel * INDENT_SIZE ); } _hb_jsonCtxAdd( pCtx, "]", 1 ); } else _hb_jsonCtxAdd( pCtx, "[]", 2 ); } else if( HB_IS_HASH( pValue ) ) { HB_SIZE nLen = hb_hashLen( pValue ); if( nLen ) { HB_SIZE nIndex; if( pCtx->fHuman ) _hb_jsonCtxAddIndent( pCtx, nLevel * INDENT_SIZE ); _hb_jsonCtxAdd( pCtx, "{", 1 ); for( nIndex = 1; nIndex <= nLen; nIndex++ ) { PHB_ITEM pKey = hb_hashGetKeyAt( pValue, nIndex ); if( HB_IS_STRING( pKey ) ) { PHB_ITEM pItem = hb_hashGetValueAt( pValue, nIndex ); HB_BOOL fEOL = HB_FALSE; if( nIndex > 1 ) _hb_jsonCtxAdd( pCtx, ",", 1 ); if( pCtx->fHuman ) { _hb_jsonCtxAdd( pCtx, pCtx->szEol, pCtx->iEolLen ); _hb_jsonCtxAddIndent( pCtx, ( nLevel + 1 ) * INDENT_SIZE ); } _hb_jsonEncode( pKey, pCtx, nLevel + 1, HB_FALSE ); if( pCtx->fHuman ) { _hb_jsonCtxAdd( pCtx, ": ", 2 ); fEOL = ( HB_IS_ARRAY( pItem ) || HB_IS_HASH( pItem ) ) && hb_itemSize( pItem ) > 0; } else _hb_jsonCtxAdd( pCtx, ":", 1 ); _hb_jsonEncode( pItem, pCtx, nLevel + 1, fEOL ); } } if( pCtx->fHuman ) { _hb_jsonCtxAdd( pCtx, pCtx->szEol, pCtx->iEolLen ); _hb_jsonCtxAddIndent( pCtx, nLevel * INDENT_SIZE ); } _hb_jsonCtxAdd( pCtx, "}", 1 ); } else _hb_jsonCtxAdd( pCtx, "{}", 2 ); } else { /* All unsupported types are replacd by null */ _hb_jsonCtxAdd( pCtx, "null", 4 ); } }
/* 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 */ }
/* 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(); }