Exemple #1
0
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;
}
Exemple #2
0
char * hb_memvarGetStrValuePtr( char * szVarName, HB_SIZE * pnLen )
{
   PHB_DYNS pDynVar;
   char * szValue = NULL;

   HB_TRACE( HB_TR_DEBUG, ( "hb_memvarGetStrValuePtr(%s, %p)", szVarName, pnLen ) );

   pDynVar = hb_memvarFindSymbol( szVarName, *pnLen );

   if( pDynVar )
   {
      /* there is dynamic symbol with the requested name - check if it is
       * a memvar variable
       */
      PHB_ITEM pMemvar = hb_dynsymGetMemvar( pDynVar );

      if( pMemvar )
      {
         /* variable contains some data
          */
         if( HB_IS_BYREF( pMemvar ) )
            pMemvar = hb_itemUnRef( pMemvar );

         if( HB_IS_STRING( pMemvar ) )
         {
            szValue = pMemvar->item.asString.value;
            *pnLen = pMemvar->item.asString.length;
         }
      }
   }

   return szValue;
}
Exemple #3
0
HB_ERRCODE hb_memvarGet( PHB_ITEM pItem, PHB_SYMB pMemvarSymb )
{
   PHB_DYNS pDyn;
   HB_ERRCODE bSuccess = HB_FAILURE;

   HB_TRACE( HB_TR_DEBUG, ( "hb_memvarGet(%p, %p)", pItem, pMemvarSymb ) );

   pDyn = pMemvarSymb->pDynSym;
   if( pDyn )
   {
      PHB_ITEM pMemvar;

      pMemvar = hb_dynsymGetMemvar( pDyn );

      HB_TRACE( HB_TR_INFO, ( "Memvar item (%p)(%s) queried", pMemvar, pMemvarSymb->szName ) );

      if( pMemvar )
      {
         /* value is already created
          */
         if( HB_IS_BYREF( pMemvar ) )
            hb_itemCopy( pItem, hb_itemUnRef( pMemvar ) );
         else
            hb_itemCopy( pItem, pMemvar );
         bSuccess = HB_SUCCESS;
      }
   }
   else
      hb_errInternal( HB_EI_MVBADSYMBOL, NULL, pMemvarSymb->szName, NULL );

   return bSuccess;
}
Exemple #4
0
/* Get local variable referenced in a codeblock */
PHB_ITEM hb_codeblockGetVar( PHB_ITEM pItem, int iItemPos )
{
   PHB_CODEBLOCK pCBlock = pItem->item.asBlock.value;

   HB_TRACE( HB_TR_DEBUG, ( "hb_codeblockGetVar(%p, %d)", pItem, iItemPos ) );

   /* local variables accessed in a codeblock are always stored as reference */
   return hb_itemUnRef( pCBlock->pLocals - iItemPos );
}
Exemple #5
0
/*
 * Altera o valor de uma variavel de memoria em nivel xBase. Retorna 1 se for 
 * bem sucedido ou 0 em caso de erro.
 * 01/07/2008 - 17:12:17
 */
int wxMemvarPut( char * szVarName, PHB_ITEM pValue )
{
   HB_DYNS_PTR pDyn;
   int result = 0;

   #ifdef HB_THREAD_SUPPORT
      HB_THREAD_STUB
      pDyn = s_memvarThFindName( szVarName, (HB_STACK *) &HB_VM_STACK );
   #else
      pDyn = hb_dynsymFindName( szVarName );
   #endif

   /*
    * Se a variavel não existir ... criamos ela aqui como pública!
    */
   if( !pDyn )
   {
      PHB_ITEM pMemvar = hb_itemNew( NULL );
      hb_itemPutC( pMemvar, szVarName );
      hb_memvarCreateFromItem( pMemvar, VS_PUBLIC, NULL );
      hb_itemRelease( pMemvar );

   #ifdef HB_THREAD_SUPPORT
      pDyn = s_memvarThFindName( szVarName, &HB_VM_STACK );
   #else
      pDyn = hb_dynsymFindName( szVarName );
   #endif
   }

   if( pDyn )
   {
      /* there is dynamic symbol with the requested name - check if it is
       * a memvar variable
       */
      if( pDyn->hMemvar )
      {
         /* value is already created */
         HB_ITEM_PTR pSetItem = hb_memvarGetValueByHandle( pDyn->hMemvar );

         // JC1: the variable we have now can't be destroyed in the meanwhile.
         // It could be changed, but this is a race condition that must be
         // prevented at prg level.
         if( HB_IS_BYREF( pSetItem ) )
         {
            pSetItem = hb_itemUnRef( pSetItem );
         }
         hb_itemCopy( pSetItem, pValue );
         result = 1;

         // Count this new value.
         /* s_globalTable[ pDyn->hMemvar ].counter = 1; */
      }
   }
   return result;
}
Exemple #6
0
/*
 * Detach local variable (swap current value with a memvar handle)
 */
PHB_ITEM hb_memvarDetachLocal( PHB_ITEM pLocal )
{
   HB_TRACE( HB_TR_DEBUG, ( "hb_memvarDetachLocal(%p)", pLocal ) );

   if( HB_IS_BYREF( pLocal ) )
   {
      do
      {
         if( HB_IS_MEMVAR( pLocal ) || HB_IS_EXTREF( pLocal ) )
            break;
         else if( HB_IS_ENUM( pLocal ) )
         {
            if( ! pLocal->item.asEnum.valuePtr )
            {
               PHB_ITEM pBase = HB_IS_BYREF( pLocal->item.asEnum.basePtr ) ?
                               hb_itemUnRef( pLocal->item.asEnum.basePtr ) :
                                             pLocal->item.asEnum.basePtr;
               if( HB_IS_ARRAY( pBase ) )
               {
                  PHB_ITEM pItem = hb_itemNew( NULL );
                  hb_arrayGetItemRef( pBase, pLocal->item.asEnum.offset, pItem );
                  pLocal->item.asEnum.valuePtr = pItem;
                  pLocal = pItem;
                  break;
               }
            }
         }
         else if( pLocal->item.asRefer.value >= 0 &&
                  pLocal->item.asRefer.offset == 0 )
            break;
         pLocal = hb_itemUnRefOnce( pLocal );
      }
      while( HB_IS_BYREF( pLocal ) );
   }

   /* Change the value only if this variable is not referenced
    * by another codeblock yet.
    * In this case we have to copy the current value to a global memory
    * pool so it can be shared by codeblocks
    */
   if( ! HB_IS_MEMVAR( pLocal ) )
   {
      PHB_ITEM pMemvar = hb_memvarValueNew();

      hb_itemRawCpy( pMemvar, pLocal );
      pMemvar->type &= ~HB_IT_DEFAULT;

      pLocal->type = HB_IT_BYREF | HB_IT_MEMVAR;
      pLocal->item.asMemvar.value = pMemvar;
   }

   return pLocal;
}
Exemple #7
0
PHB_ITEM hb_memvarGetItem( PHB_SYMB pMemvarSymb )
{
   HB_TRACE( HB_TR_DEBUG, ( "hb_memvarGetItem(%p)", pMemvarSymb ) );

   if( pMemvarSymb->pDynSym )
   {
      PHB_ITEM pMemvar = hb_dynsymGetMemvar( pMemvarSymb->pDynSym );

      if( pMemvar )
      {
         if( HB_IS_BYREF( pMemvar ) )
            return hb_itemUnRef( pMemvar );
         else
            return pMemvar;
      }
   }
   return NULL;
}
Exemple #8
0
/*
 * Retorna uma STRING de uma variavel caracter do xHarbour, criada via .PRG! Ela 
 * retorna em pulLen o tamanho da string encontrada.
 * 01/07/2008 - 08:40:47
 */
char *wxMemvarGetCPtr( char * szVarName, ULONG *pulLen )
{
   HB_THREAD_STUB
   HB_DYNS_PTR pDynVar;
   char *szValue = NULL;

   HB_TRACE(HB_TR_DEBUG, ("hb_memvarGetStrValuePtr(%s, %p)", szVarName, pulLen));

   #ifdef HB_THREAD_SUPPORT
      pDynVar = s_memvarThFindName( szVarName, &HB_VM_STACK );
   #else
      pDynVar = hb_dynsymFindName( szVarName );
   #endif

   if( pDynVar )
   {
      /* there is dynamic symbol with the requested name - check if it is
       * a memvar variable
       */
      if( pDynVar->hMemvar )
      {
         /* variable contains some data
          */
         HB_ITEM_PTR pItem = hb_memvarGetValueByHandle( pDynVar->hMemvar );

         if( HB_IS_BYREF( pItem ) )
         {
            pItem = hb_itemUnRef( pItem );   /* it is a PARAMETER variable */
         }

         if( HB_IS_STRING( pItem ) )
         {
            szValue = pItem->item.asString.value;
            *pulLen = pItem->item.asString.length;
         }
      }
   }
   return szValue;
}
Exemple #9
0
/*
 * Retorna o valor LONG de uma variavel numérica do xHarbour, criada via .PRG
 * 01/07/2008 - 08:40:47
 */
LONG wxMemvarGetNL( char * szVarName )
{
   HB_THREAD_STUB   
   HB_DYNS_PTR pDynVar;
   LONG result = 0;

   HB_TRACE(HB_TR_DEBUG, ("hb_memvarGetStrValuePtr(%s, %p)", szVarName, pulLen));

   #ifdef HB_THREAD_SUPPORT
      pDynVar = s_memvarThFindName( szVarName, &HB_VM_STACK );
   #else
      pDynVar = hb_dynsymFindName( szVarName );
   #endif

   if( pDynVar )
   {
      /* there is dynamic symbol with the requested name - check if it is
       * a memvar variable
       */
      if( pDynVar->hMemvar )
      {
         /* variable contains some data
          */
         HB_ITEM_PTR pItem = hb_memvarGetValueByHandle( pDynVar->hMemvar );

         if( HB_IS_BYREF( pItem ) )
         {
            pItem = hb_itemUnRef( pItem );   /* it is a PARAMETER variable */
         }

         if( HB_IS_NUMERIC( pItem ) )
         {
            result = hb_itemGetNL( pItem );
         }
      }
   }
   return result;
}
Exemple #10
0
PHB_ITEM hb_dbg_vmVarLGet( int iLevel, int iLocal )
{
   PHB_ITEM pLocal = NULL;
   HB_ISIZ nBaseOffset;

   nBaseOffset = hb_stackBaseOffset();
   while( iLevel-- > 0 && nBaseOffset > 1 )
      nBaseOffset = hb_stackItem( nBaseOffset - 1 )->item.asSymbol.stackstate->nBaseItem + 1;

   if( iLevel < 0 )
   {
      if( iLocal > SHRT_MAX )
      {
         iLocal -= USHRT_MAX;
         iLocal--;
      }

      if( iLocal >= 0 )
      {
         PHB_ITEM pBase = hb_stackItem( nBaseOffset - 1 );

         if( pBase->item.asSymbol.paramcnt > pBase->item.asSymbol.paramdeclcnt &&
             iLocal > pBase->item.asSymbol.paramdeclcnt )
            iLocal += pBase->item.asSymbol.paramcnt - pBase->item.asSymbol.paramdeclcnt;

         pLocal = hb_stackItem( nBaseOffset + iLocal );
      }
      else
         pLocal = hb_codeblockGetRef( hb_stackItem( nBaseOffset )->item.asBlock.value, iLocal );

      if( HB_IS_BYREF( pLocal ) )
         pLocal = hb_itemUnRef( pLocal );
   }

   return pLocal;
}