/*
*	Extract Destination to operand2
*	
*	Operation:
*		To Catch No Argument and Empty Argument Value,extract value
*
*	Data:
*		Make operand2 to default value 0x1;
*
*  Return:
*		operand2 value
*
*/
int extract1BitsDestination(String *arguments){
	ErrorCode error;
	int operand2;
	
	Try{
		operand2 = extractDestination(arguments);
	}Catch(error){
		if(error == ERR_NO_ARGUMENT){
				operand2 = 0x1;
		}else if(error != ERR_EMPTY_ARGUMENT){
			if(error == ERR_ILLEGAL_ARGUMENT){
					Throw(error);
			}
		}
	}
	
	return operand2;
}
Example #2
0
void throwError(ErrorCode errCode,char *msg , ...){
  ErrorObject *errorObj=malloc(sizeof(ErrorObject));

  char *msgBuffer;
  int strLength;

  va_list args;
  va_start(args,msg);
  strLength=vsnprintf(msgBuffer,0,msg,args);
  msgBuffer=malloc(strLength + 1);
  vsprintf(msgBuffer, msg, args);

  errorObj->errorMsg=msgBuffer;
  errorObj->errorCode=errCode;

  va_end(args);
  Throw(errorObj);
}
Example #3
0
    void GetSubMatrix::Inject(const GeneralMatrix& gmx) {
	REPORT
	    Tracer tr("SubMatrix(inject)");
	SetUpLHS();
	if (row_number != gmx.Nrows() || col_number != gmx.Ncols())
	    Throw(IncompatibleDimensionsException());
	MatrixRow mrx((GeneralMatrix*)(&gmx), LoadOnEntry);
	MatrixRow mr(gm, LoadOnEntry+StoreOnExit+DirectPart, row_skip);
	// do need LoadOnEntry
	MatrixRowCol sub; int i = row_number;
	while (i--) {
	    mr.SubRowCol(sub, col_skip, col_number);    // put values in sub
	    sub.Inject(mrx); mr.Next(); mrx.Next();
	}
#ifdef TEMPS_DESTROYED_QUICKLY
	delete this;
#endif
    }
Example #4
0
    GetSubMatrix& BaseMatrix::Rows(int first_row, int last_row) const
#else
	GetSubMatrix BaseMatrix::Rows(int first_row, int last_row) const
#endif
    {
	REPORT
	    Tracer tr("SubMatrix(rows)");
	int a = first_row - 1; int b = last_row - first_row + 1;
	if (a<0 || b<0) Throw(SubMatrixDimensionException());
	// allow zero rows or columns
#ifdef TEMPS_DESTROYED_QUICKLY
	GetSubMatrix* x = new GetSubMatrix(this, a, b, 0, -1, false);
	MatrixErrorNoSpace(x);
	return *x;
#else
	return GetSubMatrix(this, a, b, 0, -1, false);
#endif
    }
void UnitTests::runTest (UnitTest& test)
{
    try
    {
        ScopedPointer <UnitTest::Suite> suite (test.run (this).release ());

        m_results->cases += suite->cases.size ();
        m_results->tests += suite->tests;
        m_results->failures += suite->failures;

        m_results->suites.add (suite.release ());
    }
    catch (...)
    {
        // Should never get here.
        Throw (std::runtime_error ("unhandled exception during unit tests"));
    }
}
Example #6
0
    GetSubMatrix& BaseMatrix::Columns(int first_col, int last_col) const
#else
	GetSubMatrix BaseMatrix::Columns(int first_col, int last_col) const
#endif
    {
	REPORT
	    Tracer tr("SubMatrix(columns)");
	int c = first_col - 1; int d = last_col - first_col + 1;
	if (c<0 || d<0) Throw(SubMatrixDimensionException());
	// allow zero rows or columns
#ifdef TEMPS_DESTROYED_QUICKLY
	GetSubMatrix* x = new GetSubMatrix(this, 0, -1, c, d, false);
	MatrixErrorNoSpace(x);
	return *x;
#else
	return GetSubMatrix(this, 0, -1, c, d, false);
#endif
    }
Example #7
0
void FPUFlags::setCurrent (const FPUFlags& flags)
{
  unsigned int newControl = 0;
  unsigned int mask = 0;

  setControl (flags.getMaskNaNs(), newControl, mask,        _EM_INVALID);
  setControl (flags.getMaskDenormals(), newControl, mask,   _EM_DENORMAL);
  setControl (flags.getMaskZeroDivides(), newControl, mask, _EM_ZERODIVIDE);
  setControl (flags.getMaskOverflows(), newControl, mask,   _EM_OVERFLOW);
  setControl (flags.getMaskUnderflows(), newControl, mask,  _EM_UNDERFLOW);
//setControl (flags.getMaskInexacts(), newControl, mask,    _EM_INEXACT);
  setControl (flags.getFlushDenormals(), newControl, mask,  _DN_FLUSH);
  setControl (flags.getInfinitySigned(), newControl, mask,  _IC_AFFINE);

  if (flags.getRounding().is_set ())
  {
    Rounding rounding = flags.getRounding().value ();

    switch (rounding)
    {
    case roundChop: mask |= _MCW_RC; newControl |= _RC_CHOP; break;
    case roundUp:   mask |= _MCW_RC; newControl |= _RC_UP;   break;
    case roundDown: mask |= _MCW_RC; newControl |= _RC_DOWN; break;
    case roundNear: mask |= _MCW_RC; newControl |= _RC_NEAR; break;
    }
  }

  if (flags.getPrecision().is_set ())
  {
    switch (flags.getPrecision().value ())
    {
    case bits64: mask |= _MCW_PC; newControl |= _PC_64; break;
    case bits53: mask |= _MCW_PC; newControl |= _PC_53; break;
    case bits24: mask |= _MCW_PC; newControl |= _PC_24; break;
    }
  }

  unsigned int currentControl;

  errno_t result = _controlfp_s (&currentControl, newControl, mask);

  if (result != 0)
    Throw (std::runtime_error ("error in _controlfp_s"));
}
Example #8
0
void client_negotiate( Transport *tpt )
{
  struct exception e;
  char header[ 8 ];
  int x = 1;

  // default client configuration
  tpt->loc_little = ( char )*( char * )&x;
  tpt->lnum_bytes = ( char )sizeof( lua_Number );
  tpt->loc_intnum = ( char )( ( ( lua_Number )0.5 ) == 0 );
  transport_write_uint8_t( tpt, RPC_CMD_CON );

  // write the protocol header 
  header[0] = 'L';
  header[1] = 'R';
  header[2] = 'P';
  header[3] = 'C';
  header[4] = RPC_PROTOCOL_VERSION;
  header[5] = tpt->loc_little;
  header[6] = tpt->lnum_bytes;
  header[7] = tpt->loc_intnum;
  //  printf("write version\n");
  transport_write_string( tpt, header, sizeof( header ) );
  transport_flush(tpt);
  //  printf("write version ok\n");
  
  // read server's response
  //  printf("read version\n");
  transport_read_string( tpt, header, sizeof( header ) );
  if( header[0] != 'L' ||
      header[1] != 'R' ||
      header[2] != 'P' ||
      header[3] != 'C' ||
      header[4] != RPC_PROTOCOL_VERSION )
  {
    e.errnum = ERR_HEADER;
    e.type = nonfatal;
    Throw( e );
  }
  // write configuration from response
  tpt->net_little = header[5];
  tpt->lnum_bytes = header[6];
  tpt->net_intnum = header[7];
}
Example #9
0
String Environment::GetMachineVersion() {
#if UCFG_USE_POSIX
	utsname u;
	CCheck(::uname(&u));
	return u.machine;
#elif defined(WIN32)
	String s;	
	SYSTEM_INFO si;
	GetSystemInfo(&si);
	switch (si.wProcessorArchitecture) {
	case PROCESSOR_ARCHITECTURE_INTEL:
		switch (si.dwProcessorType)
		{
		case 586:
			switch (si.wProcessorRevision)
			{
			case 5895:
				s = "Core 2 Quad";
				break;
			default:
				s = "586";
			}
			break;
		default:
			s = "Intel";
		};
		break;
#if UCFG_WIN32_FULL
	case PROCESSOR_ARCHITECTURE_AMD64:
		s = "AMD64";
		break;
#endif
	case PROCESSOR_ARCHITECTURE_ARM:
		s = "ARM";
		break;
	default:
		s = "Unknown CPU";
		break;
	}
	return s;
#else
	Throw(E_NOTIMPL);
#endif
}
Example #10
0
bool statement_imp::fetch (Error& error)
{
  int result = sqlite3_step (m_stmt);

  if (result == SQLITE_ROW ||
      result == SQLITE_DONE)
  {
    if (m_bFirstTime)
    {
      m_last_insert_rowid = m_session.last_insert_rowid();
      m_bFirstTime = false;
    }

    if (result == SQLITE_ROW)
    {
      m_bGotData = true;
      m_session.set_got_data (m_bGotData);

      do_intos();
    }
    else
    {
      m_bGotData = false;
      m_session.set_got_data (m_bGotData);

      if (result == SQLITE_DONE)
      {
        m_bReady = false;
      }
    }
  }
  else if (result != SQLITE_OK)
  {
    m_bGotData = false;
    error = detail::sqliteError (__FILE__, __LINE__, result);
  }
  else
  {
    // should never get SQLITE_OK here
    Throw (Error().fail (__FILE__, __LINE__, Error::assertFailed));
  }

  return m_bGotData;
}
void test_BasicThrowAndCatch_WithMiniSyntax(void)
{
  CEXCEPTION_T e;

  //Mini Throw and Catch
  Try
    Throw(0xEF);
  Catch(e)
    TEST_ASSERT_EQUAL(0xEF, e);
  TEST_ASSERT_EQUAL(0xEF, e);
  
  //Mini Passthrough
  Try
    e = 0;
  Catch(e)
    TEST_FAIL_MESSAGE("I shouldn't be caught because there was no throw");

  TEST_ASSERT_EQUAL(0, e);
}
Example #12
0
void FFolderPackage::LoadAsset( FStringConst& Path )
{
	guard;

	//Get asset
	FAsset* Asset = FindAsset( Path );
	if(!Asset)
	{
		FString Err = FString( L"Asset '" ) + Path.Data + FString( L"' could not be read." );
		Throw( (wchar_t*)Err.Data, false );
	}

	Open( Path.Data );
	Asset->Ptr = (uint8*)GMemory->Malloc( Asset->Size );
	Read( Asset->Ptr, Asset->Size );
	Close();

	unguard;
}
Example #13
0
void mcu_div(uint8_t *reg)
{
  if( A == 0){
    C = 1;
    Throw(ERR_DIVIDER_IS_0);
  }
 
  uint16_t regXY      = getBigEndianWord(reg);
  uint16_t quotient   = regXY / A;
  uint8_t  remainder  = regXY % A;
  
  N = 0;
  Z = (quotient == 0 ? 1 : 0);
  H = 0;
  V = 0;
  
  A = remainder;
  setBigEndianWord(reg, quotient);
}
Example #14
0
void Rotate(RectMatrixCol& U, RectMatrixCol& V, Real tau, Real s)
{
   REPORT
   int n = U.n;
   if (n != V.n)
   {
      Tracer tr("newmatrm");
      Throw(InternalException("Dimensions differ in Rotate"));
   }
   Real* u = U.store; Real* v = V.store;
   int su = U.spacing; int sv = V.spacing;
   if (n) for(;;)
   {
      Real zu = *u; Real zv = *v;
      *u -= s * (zv + zu * tau); *v += s * (zu - zv * tau);
      if (!(--n)) break;
      u += su;  v += sv;
   }
}
/*
 * circularBufferAdd
 *
 * Input
 *		cb			is a pointer to CircularBuffer
 *		value2Add	value to be added to the Circular Buffer
 *
 * Function
 *		to add value to Circular Buffer and set the cb->head to be
 *		the last added value and cb->tail to be the first added value
 *		and raise an exception if Circular Buffer is full
 */
void circularBufferAdd(CircularBuffer *cb, int value2Add)
{
	if(cb->length == cb->size)
		Throw(ERR_BUFFER_IS_FULL);
	
	
	*cb->buffer = value2Add;
	
	if(cb->size == 0)
		*cb->tail = value2Add;
	
	if((cb->length - 1) != cb->size)
		cb->head++;
	else
		*cb->head = value2Add;

	cb->buffer++;
	cb->size++;
}
Example #16
0
void GetSubMatrix::operator<<(const Real* r)
{
   REPORT
   Tracer tr("SubMatrix(<<Real*)");
   SetUpLHS();
   if (row_skip+row_number > gm->Nrows() || col_skip+col_number > gm->Ncols())
      Throw(SubMatrixDimensionException());
   MatrixRow mr(gm, LoadOnEntry+StoreOnExit+DirectPart, row_skip);
                                  // do need LoadOnEntry
   MatrixRowCol sub; int i = row_number;
   while (i--)
   {
      mr.SubRowCol(sub, col_skip, col_number);   // put values in sub
      sub.Copy(r); mr.Next();
   }
#ifdef TEMPS_DESTROYED_QUICKLY
   delete this;
#endif
}
void updateQRZ(UpperTriangularMatrix& X, UpperTriangularMatrix& U)
{
   REPORT
   Tracer et("updateQRZ(3)");
   int s = X.Ncols();
   if (s != U.Ncols())
      Throw(ProgramException("Incompatible dimensions",X,U));
   if (s == 0) return; 
   Real* xi0 = X.data(); Real* u = U.data();
   for (int i=1; i<=s; ++i)
   {
		  Real r = *u; Real sum = 0.0;
			{
         Real* xi=xi0; int k=i; int l=s;
			   while(k--) { sum += square(*xi); xi+= --l;}
			}
      sum = sqrt(sum + square(r));
      if (sum == 0.0) { REPORT X.column(i) = 0.0; *u = 0.0; }
      else
      {
         Real frs = fabs(r) + sum;
         Real a0 = sqrt(frs / sum); Real alpha = a0 / frs;
         if (r <= 0) { REPORT *u = sum; alpha = -alpha; }
         else { REPORT *u = -sum; }
         {
            Real* xj0=xi0; int k=i; int l=s;
            while(k--) { *xj0 *= alpha; --l; xj0 += l;}
         }
         Real* xj0=xi0; Real* uj=u;
         for (int j=i+1; j<=s; ++j)
         {
            Real sum = 0.0; ++xj0; ++uj;
            Real* xi=xi0; Real* xj=xj0; int k=i; int l=s; 
            while(k--) { sum += *xi * *xj; --l; xi += l; xj += l; }
            sum += a0 * *uj;
            xi=xi0; xj=xj0; k=i; l=s;
            while(k--) { *xj -= sum * *xi; --l; xi += l; xj += l; }
            *uj -= sum * a0;
         }
      }
			++xi0; u += s-i+1;
   }
}
Example #18
0
void FFT(const ColumnVector& U, const ColumnVector& V,
   ColumnVector& X, ColumnVector& Y)
{
   // from Carl de Boor (1980), Siam J Sci Stat Comput, 1 173-8
   // but first try Sande and Gentleman
   Tracer trace("FFT");
   REPORT
   const int n = U.Nrows();                     // length of arrays
   if (n != V.Nrows() || n == 0)
      Throw(ProgramException("Vector lengths unequal or zero", U, V));
   if (n == 1) { REPORT X = U; Y = V; return; }

   // see if we can use the newfft routine
   if (!FFT_Controller::OnlyOldFFT && FFT_Controller::CanFactor(n))
   {
      REPORT
      X = U; Y = V;
      if ( FFT_Controller::ar_1d_ft(n,X.Store(),Y.Store()) ) return;
   }

   ColumnVector B = V;
   ColumnVector A = U;
   X.resize(n); Y.resize(n);
   const int nextmx = 8;
   int prime[8] = { 2,3,5,7,11,13,17,19 };
   int after = 1; int before = n; int next = 0; bool inzee = true;
   int now = 0; int b1;             // initialised to keep gnu happy

   do
   {
      for (;;)
      {
	 if (next < nextmx) { REPORT now = prime[next]; }
	 b1 = before / now;  if (b1 * now == before) { REPORT break; }
	 next++; now += 2;
      }
      before = b1;

      if (inzee) { REPORT fftstep(A, B, X, Y, after, now, before); }
      else { REPORT fftstep(X, Y, A, B, after, now, before); }

      inzee = !inzee; after *= now;
   }
Example #19
0
void nx_exception_rethrow(nx_exception_t	*e,
			   const char		*file,
			   int			line,
			   const char		*func,
			   const char		*fmt,
			   ...)
{
    va_list ap;

    ASSERT(e != NULL);

    va_start(ap, fmt);
    nx_exception_add_message(e, file, line, func, fmt, ap);
    va_end(ap);

    nx_exception_check_uncaught(e, NX_LOGMODULE);
    
    Throw(*e);
}
Example #20
0
// Check if data is available on connection without reading:
//    - 1 = data available, 0 = no data available
int transport_readable (Transport *tpt)
{
  struct exception e;
  int ret;

  if (tpt->fd == INVALID_TRANSPORT)
    return 0;
  
  ret = ser_readable( tpt->fd );
  
  if ( ret < 0 )
  {
    e.errnum = transport_errno;
    e.type = fatal;
    Throw( e );
  }
  
  return ( ret > 0 );
}
Example #21
0
void MEField<_FIELD>::Addfield(_FIELD *f, UInt nval) {
  // Store as a hash of fields by nval;
  std::vector<UInt>::iterator i = 
    std::lower_bound(fidx_table.begin(), fidx_table.end(), nval);
  
  // Error if already there
  if (i == fidx_table.end() || *i != nval) {
    i = fidx_table.insert(i, nval);
  } else Throw() << "Field:" << fname << ", already added nval:" << nval;
  
  // Insert field at same spot.
  UInt pos = std::distance(fidx_table.begin(), i);
  typename std::vector<_FIELD*>::iterator fi = fields.begin() + pos;
  UInt cursize = fields.size();
  if (cursize == 0) primaryfield = f;
  // if nval is larger, resize.  Keeps old fields, assigns null elsewhere
  ThrowAssert(fields.size() <= pos);
  fields.insert(fi, f);
}
int operandExtract1BitsValue(String *arguments){
	ErrorCode e;
	int operand1;
	
	Try{
		operand1 = extractValue(arguments);
	}Catch(e){ 
        if(e == ERR_NO_ARGUMENT || e == ERR_EMPTY_ARGUMENT){
			operand1 = 0;
			return operand1;
		}else if(e == ERR_ILLEGAL_ARGUMENT){
			Throw(e);
		}
	}
	
	operand1 = operand1 & 0x01;
	
	return operand1;
}
Example #23
0
//TODO: Multi-thread this
void FZipPackage::LoadAsset( FStringConst& Path )
{
	guard;

	//Check that the asset exists
	FZipAsset* Asset = (FZipAsset*)FindAsset( Path );
	if(!Asset)
	{
		FString Err = FString( L"Asset '" ) + Path.Data + FString( L"' could not be read." );
		Throw( (wchar_t*)Err.Data, false );
	}
	
	Seek( Asset->Location, Begin );
	Asset->Ptr = new uint8[Asset->Size];
	switch (Asset->CompressType)
	{
		case 0:
		{
			//No compression
			Read( Asset->Ptr, Asset->Size );
			break;
		}
		case 8:
		{
			//Deflate
			uint8* CompressData = new uint8[Asset->CompressSize];
			Read( CompressData, Asset->CompressSize );
			Inflate( CompressData, Asset->Ptr, Asset->CompressSize, Asset->Size );
			if(Asset->Type == AT_Text || Asset->Type == AT_Script)
			{
				//Null terminate the data if it has formatted text
				Asset->Ptr[Asset->Size] = 0;
			}
			break;
		}
		default:
		{
			Logf( LOG_ERR, L"Asset '%s' is compressed with an unknown method.", Asset->Name );
		}
	}

	unguard;
}
Example #24
0
File: Map.c Project: soofatt/Map
/*Function to store an element in the map(Separate chaining method)
 *
 *Input : *map : The map
 *        *element : The element to be stored
 *        (*compare)(void *, void *) : Compare function
 *        (*hash)(void *) : Hash function
 *
 */
void mapStore(Map *map, void *element, int (*compare)(void *, void *), unsigned int (*hash)(void *)){
  int index;
  
  index = hash(element);
 
  if(map->bucket[index] != NULL){
    if(compare(((List *)map->bucket[index])->data, element) == 1){
      Throw(ERR_SAME_ELEMENT);
    }
		else{
			List *list = listNew(element, (List *)map->bucket[index]);
			map->bucket[index] = list;
		}
  }
	else{
		List *list = listNew(element, NULL);
		map->bucket[index] = list;
	}
}
Example #25
0
void CSatchel::PrimaryAttack()
{
	switch (m_chargeReady)
	{
	case 0:
		{
		Throw( );
		}
		break;
	case 1:
		{
		SendWeaponAnim( SATCHEL_RADIO_FIRE );

		edict_t *pPlayer = m_pPlayer->edict( );

		CBaseEntity *pSatchel = NULL;

		while ((pSatchel = UTIL_FindEntityInSphere( pSatchel, m_pPlayer->pev->origin, 4096 )) != NULL)
		{
			if (FClassnameIs( pSatchel->pev, "monster_satchel"))
			{
				if (pSatchel->pev->owner == pPlayer)
				{
					pSatchel->Use( m_pPlayer, m_pPlayer, USE_ON, 0 );
					m_chargeReady = 2;
				}
			}
		}

		m_chargeReady = 2;
		m_flNextPrimaryAttack = UTIL_WeaponTimeBase() + 0.5;
		m_flNextSecondaryAttack = UTIL_WeaponTimeBase() + 0.5;
		m_flTimeWeaponIdle = UTIL_WeaponTimeBase() + 0.5;
		break;
		}

	case 2:
		// we're reloading, don't allow fire
		{
		}
		break;
	}
}
Example #26
0
int Socket::GetRemotePort() const
{
	int port = 0;
	struct sockaddr_in addr;
	int socklen;

	bzero(&addr, sizeof(addr));
	socklen = sizeof(addr);

	// 获取远程主机端口号
	if(getpeername(this->sock_fd,(struct sockaddr *)&addr,(socklen_t*)&socklen))
	{
		Throw("getpeername failed.", errno);
	}

	port = ntohs(addr.sin_port);

	return port;
}
Example #27
0
int Socket::GetLocalPort() const
{
	int port = 0;
	struct sockaddr_in addr;
	int socklen;

	bzero(&addr, sizeof(addr));
	socklen = sizeof(addr);

	// 获取绑定在socket上的端口号
	if(getsockname(this->sock_fd,(struct sockaddr *)&addr,(socklen_t*)&socklen))
	{
		Throw("Get remote address failed", errno);
	}

	port = ntohs(addr.sin_port);

	return port;
}
Example #28
0
File: Map.c Project: jwchong93/Map
void mapLinearStore(Map *map, void *element, int (*copmpare)(void*,void*),unsigned int (*hash)(void*))
{
    int location;
    List *newList;
    location = hash(element);
    if(map->bucket[location]!=NULL)
    {
        while(map->bucket[location]!=NULL)
        {
            location++;
        }
        if(location>=map->length)
        {
            Throw(ERR_OUT_OF_BOUND);
        }

    }
    map->bucket[location]=element;
    map->size++;
}
Example #29
0
/* ---------------------------------------------------------------------------------
*  _LEdgeInfo_DeleteItemAt
*  ---------------------------------------------------------------------------------
*  Delete the info of a specified Edge*/
void _LEdgeInfo_DeleteItemAt(LEdgeInfo* This, LGraph_TEdge* inEdge) 
{
	LException* theException;
	ui4 theIndex;

    if (This == NULL) Throw(LEdgeInfo_OBJECT_NULL_POINTER);

	/* if installed, calls the destructor handler */
	if (This->mDealloc)
		(*(This->mDealloc))(This, inEdge);

	theIndex = inEdge->mIndex;
    LMemory_Copy(LArray_LastItem(This->mData),
                  LArray_ItemAt(This->mData, theIndex),
                  LArray_GetItemSize(This->mData));
	Try
		LArray_ResizeBy(This->mData, -1);
	Catch(theException)
		LException_Dump(theException);
}
Example #30
0
bool CMultiXL3::OnSendReq(CMultiXL3SendDataReq &Req)
{
	CMultiXL3Link	*Link	=	Req.L3LinkID().GetObject();

	if(Link	==	NULL)
	{
		Throw();
		/*
		CMultiXL3Event	*Event;
		Event	=	new	CMultiXL3Event(CMultiXEvent::L3SendDataFailed,this,NULL);
		Event->OpenerID()	=	Req.LinkID();
		Event->IoError()	=	L3ErrLinkNotFound;
		Event->Buf()			=	Req.Buf();
		MultiX().QueueEvent(Event);
		*/
		return	false;
	}

	return	Link->SendData(*Req.Buffer());
}