Example #1
0
	bool ByteArray::Grow(uint32_t minimumCapacity)
	{
		if (minimumCapacity > m_capacity)
		{
			uint32_t newCapacity = m_capacity << 1;			
			if (newCapacity < minimumCapacity)
			{
				newCapacity = minimumCapacity;
			}
			if (newCapacity < kGrowthIncr) 
			{
				newCapacity = kGrowthIncr;
			}
			U8 *newArray = mmfx_new_array(uint8_t, newCapacity);
			if (!newArray)
			{
				return false;
			}
			if (m_array)
			{
				VMPI_memcpy(newArray, m_array, m_length);
				mmfx_delete_array(m_array);
			}
			VMPI_memset(newArray+m_length, 0, newCapacity-m_capacity);
			m_array = newArray;
			m_capacity = newCapacity;
			NotifySubscribers();
		}
		return true;
	}
Example #2
0
	void ByteArray::Push(const U8 *data, uint32_t count)
	{
		Grow(m_length + count);
		VMPI_memcpy(m_array + m_length, data, count);
		m_length += count;
		NotifySubscribers();
	}
Example #3
0
 void FrameState::init(FrameState* other)
 {
     AvmAssert(other->verifier == this->verifier);
     scopeDepth = other->scopeDepth;
     stackDepth = other->stackDepth;
     withBase = other->withBase;
     VMPI_memcpy(locals, other->locals, verifier->frameSize*sizeof(Value));
 }
Example #4
0
void BigInteger::setFromBigInteger(const BigInteger* from, int32 offset, int32 amount)
{
    numWords = amount;
    AvmAssert(numWords <= kMaxBigIntegerBufferSize);
    VMPI_memcpy( (byte*)wordBuffer,
            (byte*)&(from->wordBuffer[offset]),
            amount*sizeof(uint32));
}
Example #5
0
	void ByteArrayFile::Write(const void *buffer, uint32_t count)
	{
		if (m_filePointer+count >= m_length) {
			Grow(m_filePointer+count);
			m_length = m_filePointer+count;
		}
		VMPI_memcpy(m_array+m_filePointer, buffer, count);
		m_filePointer += count;
	}
Example #6
0
	void ByteArrayFile::Read(void *buffer, uint32_t count)
	{
		CheckEOF(count);

		if (count > 0)
		{
			VMPI_memcpy(buffer, m_array+m_filePointer, count);
			m_filePointer += count;
		}
	}
Example #7
0
void SocketFile::WriteOutCache(const void *data, uint32_t count)
{
	if (m_outWritePos + count >= m_outCache.GetLength())
	{
		m_outCache.SetLength(m_outWritePos + count);
//		m_outCache.Grow(m_outCache.GetLength());
	}

	VMPI_memcpy(m_outCache.GetBuffer() + m_outWritePos, data, count);
	m_outWritePos += count;
}
Example #8
0
void SocketFile::WriteInCache(const void *data, uint32_t length)
{
	if (m_inWritePos + length >= m_inCache.GetLength())
	{
		m_inCache.SetLength(m_inWritePos + length);
		//		m_outCache.Grow(m_outCache.GetLength());
	}

	VMPI_memcpy(m_inCache.GetBuffer() + m_inWritePos, data, length);
	m_inWritePos += length;
}
Example #9
0
        wchar* StringBuilder::copyInto(wchar* buf, SBChunk* c)
        {
            if (c == NULL)
                return buf;

            wchar *p = buf;
            if (c->next != NULL)
                p = copyInto(buf, c->next);
            VMPI_memcpy(p, c->data, SBChunk::chunksize*sizeof(wchar));
            return p+SBChunk::chunksize;
        }
Example #10
0
 const wchar* AvmplusHostContext::readFileForEval(const wchar* basename, const wchar* filename, uint32_t* inputlen)
 {
     // FIXME: the mismatch between what eval needs and what the core API delivers is just stunning.
     if (nextstring == sizeof(strings)/sizeof(strings[0]))
         throwInternalError("includes too deeply nested");
     StUTF16String str(core->readFileForEval(core->newStringUTF16(basename), core->newStringUTF16(filename)));   // return value is already NUL-terminated
     wchar *s = new wchar[str.length()];
     VMPI_memcpy(s, str.c_str(), str.length()*sizeof(wchar));
     *inputlen = str.length();
     strings[nextstring++] = s;
     return s;
 }
Example #11
0
        Str* StringBuilder::str()
        {
            if (chunk->next == NULL)
                return allocator->compiler->intern(chunk->data, len);

            wchar* buf = new wchar[len];
            wchar* p = copyInto(buf, chunk->next);
            VMPI_memcpy(p, chunk->data, nextchar*sizeof(wchar));
            Str* result = allocator->compiler->intern(buf, len);
            delete [] buf;
            return result;
        }
Example #12
0
void SocketFile::ReadOutCache(void *data, uint32_t length)
{
	CheckEOF(length);

	if (length > 0)
	{
		VMPI_memcpy(data, m_outCache.GetBuffer() + m_outReadPos, length);
		m_outReadPos += length;
	}

	//if (0 == OutCacheBytesAvailable())
	//{
	//	m_outReadPos = m_outWritePos = 0;
	//}
}
Example #13
0
void SocketFile::ReadInCache(void *data, uint32_t count)
{
	CheckEOF(count);

	if (count > 0)
	{
		AvmAssert(m_inReadPos+count<=m_inCache.GetLength());
		VMPI_memcpy(data, m_inCache.GetBuffer() + m_inReadPos, count);
		m_inReadPos += count;
	}

	//if (0 == InCacheBytesAvailable())
	//{
	//	m_inReadPos = m_inWritePos = 0;
	//}
}
Example #14
0
 // The cache structure is expected to be small in the normal case, so use a
 // linear list.  For some programs, notably classical JS programs, it may however
 // be larger, and we may need a more sophisticated structure.
 uint32_t LookupCacheBuilder::allocateCacheSlot(uint32_t imm30)
 {
     for ( int i=0 ; i < next_cache ; i++ )
         if (caches[i] == imm30)
             return i;
     if (next_cache == num_caches) {
         uint32_t newcap = num_caches + num_caches/2 + 5; // 0 5 12 23 39 66 ...
         uint32_t* new_cache = mmfx_new_array(uint32_t, newcap);
         if (num_caches > 0) {
             VMPI_memcpy(new_cache, caches, sizeof(uint32_t)*num_caches);
             mmfx_delete_array(caches);
         }
         caches = new_cache;
         num_caches = newcap;
     }
     caches[next_cache] = imm30;
     return next_cache++;
 }
Example #15
0
	ByteArray::ByteArray(const ByteArray &lhs) 
        // GCC will warn if we don't explicitly init GlobalMemoryProvider, 
        // even though it has no fields or ctor... sigh
        : GlobalMemoryProvider()
	{
		m_subscriberRoot = NULL;
		m_array    = mmfx_new_array(uint8_t, lhs.m_length);
		if (!m_array)
		{
			ThrowMemoryError();
			return;
		}

		m_capacity = lhs.m_length;
		m_length   = lhs.m_length;

		VMPI_memcpy(m_array, lhs.m_array, m_length);
	}
	Atom DomainObject::loadBytes(ByteArrayObject *b)
	{
		AvmCore* core = this->core();
		if (!b)
			toplevel()->throwTypeError(kNullArgumentError, core->toErrorString("bytes"));

		ShellCodeContext* codeContext = new (core->GetGC()) ShellCodeContext();
		codeContext->m_domainEnv = domainEnv;

		// parse new bytecode
		size_t len = b->get_length();
		ScriptBuffer code = core->newScriptBuffer(len);
		VMPI_memcpy(code.getBuffer(), &b->GetByteArray()[0], len);
		Toplevel *toplevel = domainToplevel;
		return core->handleActionBlock(code, 0,
								  domainEnv,
								  toplevel,
								  NULL, codeContext);
	}
Example #17
0
 void StringBuilder::append(const wchar* ptr, const wchar* lim)
 {
     if (lim == NULL) {
         lim = ptr;
         while (*lim != 0)
             lim++;
     }
     while (ptr < lim) {
         uint32_t avail = SBChunk::chunksize - nextchar;
         uint32_t need = uint32_t(lim - ptr);
         uint32_t k = min(need, avail);
         VMPI_memcpy(chunk->data + nextchar, ptr, k*sizeof(wchar));
         ptr += k;
         nextchar += k;
         len += k;
         if (ptr < lim) {
             pushChunk();
             nextchar = 0;
         }
     }
 }