Ejemplo n.º 1
0
/*
    wxSocketBase_ReadBase
    Teo. Mexico 2009
*/
void wxSocketBase_ReadBase( HB_BYTE type )
{
    PHB_ITEM pSelf = hb_stackSelfItem();
    wx_SocketBase* socketBase = (wx_SocketBase*) xho_itemListGet_XHO( pSelf );

    PHB_ITEM pBuffer = hb_param( 1, HB_IT_STRING );

    if( pBuffer == NULL || !HB_ISBYREF( 1 ) )
    {
        hb_errRT_BASE_SubstR( EG_ARG, WXH_ERRBASE + 10, NULL, HB_ERR_FUNCNAME, HB_ERR_ARGS_BASEPARAMS );
        return;
    }

    if( socketBase )
    {
        pBuffer = hb_itemUnShareString( pBuffer );

        wxUint32 nbytes = HB_ISNIL( 2 ) ?  hb_itemGetCLen( pBuffer ) : hb_parnl( 2 );

        if( nbytes > 0 )
        {
            if( nbytes > hb_itemGetCLen( pBuffer ) )
                hb_itemReSizeString( pBuffer, nbytes );

            if( type == '0' )
                socketBase->Read( (char *) hb_itemGetCPtr( pBuffer ), nbytes );
            else
                socketBase->ReadMsg( (char *) hb_itemGetCPtr( pBuffer ), nbytes );

            wxUint32 uiLastCount = socketBase->LastCount();

            if( uiLastCount < hb_itemGetCLen( pBuffer ) )
//         hb_itemGetCLen( pBuffer ) = uiLastCount;
                hb_itemReSizeString( pBuffer, uiLastCount );

        }else
            hb_errRT_BASE_SubstR( EG_ARG, WXH_ERRBASE + 10, NULL, HB_ERR_FUNCNAME, HB_ERR_ARGS_BASEPARAMS );

        hb_itemReturn( pSelf );
    }
}
Ejemplo n.º 2
0
/* 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;
}