bool BaseExecutionContext::onFatalError(const Exception &e) {
  recordLastError(e);
  const char *file = NULL;
  int line = 0;
  if (RuntimeOption::InjectedStackTrace) {
    const ExtendedException *ee = dynamic_cast<const ExtendedException *>(&e);
    if (ee) {
      ArrayPtr bt = ee->getBackTrace();
      if (!bt->empty()) {
        Array top = bt->rvalAt(0).toArray();
        if (top.exists("file")) file = top.rvalAt("file").toString();
        if (top.exists("line")) line = top.rvalAt("line");
      }
    }
  }
  if (RuntimeOption::AlwaysLogUnhandledExceptions) {
    Logger::Log(Logger::LogError, "HipHop Fatal error: ", e, file, line);
  }
  bool handled = false;
  if (RuntimeOption::CallUserHandlerOnFatals) {
    int errnum = ErrorConstants::FATAL_ERROR;
    handled = callUserErrorHandler(e, errnum, true);
  }
  if (!handled && !RuntimeOption::AlwaysLogUnhandledExceptions) {
    Logger::Log(Logger::LogError, "HipHop Fatal error: ", e, file, line);
  }
  return handled;
}
Example #2
0
// YOU must free the returned string
char * getSpecialFolder (int nFolder, HWND hWnd)
{
    LPMALLOC pMalloc;
    LPITEMIDLIST pidl;

    ArrayPtr<char> str = new char [MAX_PATH + 30];
    if (str == 0)
	throw AppException (WHERE, ERR_OUT_OF_MEMORY);

    if (FAILED (SHGetMalloc (&pMalloc)))
	return NULL;

    if (FAILED (SHGetSpecialFolderLocation (hWnd, nFolder, &pidl))) {
	pMalloc->Release ();
	return NULL;
    }

    if (SHGetPathFromIDList (pidl, str) != TRUE) {
	pMalloc->Free (pidl);
	pMalloc->Release ();
	return NULL;
    }

    pMalloc->Free (pidl);
    pMalloc->Release ();

    return str.detach ();
}
void RecordHandler::handle(StationData* stationData, Record* record) {
	RecordPtr recordAutoPtr(record);

	if ( stationData->gmGain == 0 ) return;
	if ( !record->data() ) return;

	int dataSize = record->data()->size();
	if ( dataSize <= 0 ) return;

	ArrayPtr array = record->data()->copy(Array::DOUBLE);
	double* data = static_cast<double*>(const_cast<void*>(array->data()));
	if ( !data ) return;

	stationData->gmFilter->setSamplingFrequency(record->samplingFrequency());
	stationData->gmFilter->apply(dataSize, data);

	double* begin = data;
	double* maximumSample = std::max_element(begin, data + dataSize,
	                                         std::ptr_fun(RecordHandlerCompare));

	*maximumSample = fabs(*maximumSample);

	if ( stationData->gmMaximumSample < *maximumSample ||
			Core::Time::GMT() - stationData->gmSampleReceiveTime > _sampleLifespan ) {
		stationData->gmSampleReceiveTime = Core::Time::GMT();
		stationData->gmMaximumSample= *maximumSample;
	}

	try { stationData->gmRecordReceiveTime = record->endTime(); }
	catch ( Core::ValueException& ) { stationData->gmRecordReceiveTime = Core::Time::GMT(); }

	double velocity = stationData->gmMaximumSample / stationData->gmGain * 1E9;

	stationData->gmColor = calculateColorFromVelocity(velocity);
}
Example #4
0
 //-----------------------------------------------------------------------------
 // Tools::displayArray
 //-----------------------------------------------------------------------------
 std::string Tools::displayArray( const ArrayPtr& arr, int maxCell )
 {
   ArrayIterator begin = arr->begin();
   ArrayIterator end   = arr->end();
   
   return Tools::scanValues( begin, end, maxCell );
 }
Example #5
0
static Variable as_push(AVM &avm){
	ArrayPtr array = avm.getRegister(1).as<Array>();
	if (!array)
		throw Common::Exception("Array::pop this is not an Array object");
	array->push(avm.getRegister(2));
	return Variable();
}
Example #6
0
		Value toValue( const math::Vec3f &vec )
		{
			Value v = Value::createArray();
			ArrayPtr a = v.asArray();
			for( int i=0;i<3;++i )
				a->append( Value::create<float>(vec[i]) );
			return v;
		}
Example #7
0
		Value toValue( const math::Matrix44f &matrix )
		{
			Value v = Value::createArray();
			ArrayPtr a = v.asArray();

			for( int i=0;i<16;++i )
				a->append( Value::create<float>(matrix.ma[i]) );

			return v;
		}
Example #8
0
 //-----------------------------------------------------------------------------
 // Tools::displayValues
 //-----------------------------------------------------------------------------
 std::string Tools::displayValues(const ArrayPtr& array) 
 {
   std::cout<<"Entering Tools::displayValues"<<std::endl;
   std::string str;
   ArrayIterator begin = array->begin();
   ArrayIterator end = array->end();
   str = scanValues(begin, end, 15);
   std::cout<<"Leaving Tools::displayValues"<<std::endl;
   return str;
 }
void BaseExecutionContext::handleError(const std::string &msg,
                                       int errnum,
                                       bool callUserHandler,
                                       ErrorThrowMode mode,
                                       const std::string &prefix) {
  SYNC_VM_REGS_SCOPED();

  int newErrorState = ErrorRaised;
  switch (getErrorState()) {
  case ErrorRaised:
  case ErrorRaisedByUserHandler:
    return;
  case ExecutingUserHandler:
    newErrorState = ErrorRaisedByUserHandler;
    break;
  default:
    break;
  }
  ErrorStateHelper esh(this, newErrorState);
  ExtendedException ee(msg);
  recordLastError(ee, errnum);
  bool handled = false;
  if (callUserHandler) {
    handled = callUserErrorHandler(ee, errnum, false);
  }
  if (mode == AlwaysThrow || (mode == ThrowIfUnhandled && !handled)) {
    try {
      if (!Eval::Debugger::InterruptException(String(msg))) return;
    } catch (const Eval::DebuggerClientExitException &e) {}
    throw FatalErrorException(msg.c_str());
  }
  if (!handled &&
      (RuntimeOption::NoSilencer ||
       (getErrorReportingLevel() & errnum) != 0)) {
    try {
      if (!Eval::Debugger::InterruptException(String(msg))) return;
    } catch (const Eval::DebuggerClientExitException &e) {}

    const char *file = NULL;
    int line = 0;
    if (RuntimeOption::InjectedStackTrace) {
      ArrayPtr bt = ee.getBackTrace();
      if (!bt->empty()) {
        Array top = bt->rvalAt(0).toArray();
        if (top.exists("file")) file = top.rvalAt("file").toString();
        if (top.exists("line")) line = top.rvalAt("line");
      }
    }

    Logger::Log(Logger::LogError, prefix.c_str(), ee, file, line);
  }
}
Example #10
0
File: arena.cpp Project: QingYun/kj
Arena::Arena(ArrayPtr<byte> scratch)
    : nextChunkSize(kj::max(sizeof(ChunkHeader), scratch.size())) {
  if (scratch.size() > sizeof(ChunkHeader)) {
    ChunkHeader* chunk = reinterpret_cast<ChunkHeader*>(scratch.begin());
    chunk->end = scratch.end();
    chunk->pos = reinterpret_cast<byte*>(chunk + 1);
    chunk->next = nullptr;  // Never actually observed.

    // Don't place the chunk in the chunk list because it's not ours to delete.  Just make it the
    // current chunk so that we'll allocate from it until it is empty.
    currentChunk = chunk;
  }
}
void GeometryManager::flushUnusedGeometry()
{
  ArrayPtr <GeometryInfo> validGeometry;
  
  for (size_t i = 0; i < geometryCollection.length(); i++)
    if (geometryCollection(i)->getUserCount() > 0)
      validGeometry.append(geometryCollection(i));
    else
    {
      deleteObject(geometryCollection(i)->getMedia());
      deleteObject(geometryCollection(i));
    }
    
  geometryCollection = validGeometry;
}
int ArrayPtr::operator - ( ArrayPtr _ptr ) const
{
	assert( isValid() );
	assert( _ptr.isValid() );
	assert( sameArray( _ptr ) );
	return m_currentPosition - _ptr.m_currentPosition;
}
void TexturesManager::flushUnusedTextures()
{
  ArrayPtr <TextureInfo> validTextures;
  size_t i;
  unsigned int textureID;
  
  for (i = 0; i < textureCollection.length(); i++)
    if (textureCollection(i)->getUserCount() > 0)
      validTextures.append(textureCollection(i));
    else
    {
      textureID = textureCollection(i)->getMedia();
      glDeleteTextures(1, &textureID);
      deleteObject(textureCollection(i));
    }
    
  textureCollection.clear();
  textureCollection = validTextures;
}
Example #14
0
// >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
GenericRecord *Decimation::convert(Record *rec) {
	if ( rec->data() == NULL ) return NULL;

	GenericRecord *out;
	switch ( rec->dataType() ) {
		case Array::CHAR:
		case Array::INT:
		case Array::FLOAT:
		case Array::DOUBLE:
			out = createDecimatedRecord(rec);
			break;
		default:
			return NULL;
	}

	ArrayPtr data = rec->data()->copy(_dataType);
	out->setData(data.get());

	return out;
}
Example #15
0
/* ------------------------------------------------------- */
void SphereVolume::computeFromData(const Ptr<VertexData>& vdata)
{
	m_radius = 0.0f;
	m_center = Vector3(0.0f, 0.0f, 0.0f);
	float curDistance = 0.0f;
	
	ArrayPtr<GeometryVertex> vertices = vdata->getGeometryData();

	for (int i = 0; i < vertices.size(); i++)
	{
		m_center += vertices[i].position;
	}
	m_center /= vertices.size();

	for (int i = 0; i < vertices.size(); i++)
	{
		curDistance = (vertices[i].position-m_center).squaredLength();
		if (curDistance > m_radius)
		{
			m_radius = curDistance;
		}
	}
	m_radius = Math<float>::Sqrt(m_radius);
}
Example #16
0
	void array_reserve(ArrayPtr array, uint32_t new_size) {
		array->reserve(new_size);
	}
Example #17
0
    //-----------------------------------------------------------------
    void
    IniFile::load(const std::string filename)
    {
        _sections.clear();

        if (filename.empty()) {
            return;
        }

        FILE* file = fopen(filename.c_str(), "rb");
        if (!file) {
            return;
        }

        static ArrayPtr<char> s_Buffer;
        static int s_BufferSize = 0;
        if (s_BufferSize == 0) { // one-time initialization
            try {
                s_Buffer.reset(new char[1024]);
                s_BufferSize = 1024;
            } catch (const std::bad_alloc&) {
                return;
            }
        }

        int num_keys_read = 0;
        std::string section;
        std::string key;
        std::string value;
        char* ptr;
        int avail;
        int state = 'A';
        int input;
        int chr;

    fetch:
        // fill buffer with data from the stream
        int num_fetched = fread(s_Buffer.get(), 1, s_BufferSize, file);
        if (num_fetched == 0) {
            goto finish;
        } else {
            avail = num_fetched;
            ptr = s_Buffer.get();
        }

    parse:
        // parse the data in the buffer
        chr = *ptr;
        if (chr == '\n' || chr == '\r') {
            input = 'n';
        } else if (chr == '[') {
            input = 'l';
        } else if (chr == ']') {
            input = 'r';
        } else if (chr == '=') {
            input = 'z';
        } else if (chr == ' ') {
            input = 's';
        } else if (chr > 31 && chr < 127) {
            input = 'g';
        } else {
            input = 'u';
        }

        switch (state) {
        case 'A':
            switch (input) {
            case 'n':
            case 's':
                break;
            case 'l':
                state = 'B';
                break;
            case 'r':
            case 'z':
            case 'g':
            case 'u':
                state = 'C';
                break;
            }
            break;
        case 'B':
            switch (input) {
            case 'n':
                state = 'A';
                break;
            case 'g':
                state = 'D';
                section = chr;
                break;
            case 's':
                break;
            case 'l':
            case 'r':
            case 'z':
            case 'u':
                state = 'C';
                break;
            }
            break;
        case 'C':
            switch (input) {
            case 'n':
                state = 'A';
                break;
            case 'l':
            case 'r':
            case 'z':
            case 's':
            case 'g':
            case 'u':
                break;
            }
            break;
        case 'D':
            switch (input) {
            case 'n':
                state = 'A';
                break;
            case 's':
            case 'g':
                section += chr;
                break;
            case 'r':
                state = 'E';
                break;
            case 'l':
            case 'z':
            case 'u':
                state = 'C';
                break;
            }
            break;
        case 'E':
            switch (input) {
            case 'n':
                state = 'F';
                break;
            case 'l':
            case 'r':
            case 'z':
            case 's':
            case 'g':
            case 'u':
                break;
            }
            break;
        case 'F':
            switch (input) {
            case 'n':
            case 's':
                break;
            case 'g':
                state = 'G';
                key = chr;
                break;
            case 'l':
                state = 'B';
                break;
            case 'r':
            case 'z':
            case 'u':
                state = 'H';
                break;
            }
            break;
        case 'G':
            switch (input) {
            case 'n':
                state = 'F';
                break;
            case 's':
            case 'g':
                key += chr;
                break;
            case 'z':
                state = 'I';
                break;
            case 'l':
            case 'r':
            case 'u':
                state = 'H';
                break;
            }
            break;
        case 'H':
            switch (input) {
            case 'n':
                state = 'F';
                break;
            case 'l':
            case 'r':
            case 'z':
            case 's':
            case 'g':
            case 'u':
                break;
            }
            break;
        case 'I':
            switch (input) {
            case 'n':
                state = 'F';
                break;
            case 's':
                break;
            case 'l':
            case 'r':
            case 'g':
                state = 'J';
                value = chr;
                break;
            case 'z':
            case 'u':
                state = 'H';
                break;
            }
            break;
        case 'J':
            switch (input) {
            case 'n':
                state = 'F';
                _sections[strip_whitespace(section)]._keys[strip_whitespace(key)] = strip_whitespace(value);
                num_keys_read++;
                break;
            case 'l':
            case 'r':
            case 's':
            case 'g':
                value += chr;
                break;
            case 'z':
            case 'u':
                state = 'H';
                _sections[strip_whitespace(section)]._keys[strip_whitespace(key)] = strip_whitespace(value);
                num_keys_read++;
                break;
            }
            break;
        }

        --avail;
        ++ptr;

        if (avail > 0) {
            goto parse;
        } else {
            goto fetch;
        }

    finish:
        if (state == 'J') { // we still have a valid key-value pair
            _sections[strip_whitespace(section)]._keys[strip_whitespace(key)] = strip_whitespace(value);
            num_keys_read++;
        }
        return;
    }
Example #18
0
	void array_push(ArrayPtr array, Value val) {
		array->push_back(val);
	}