Пример #1
0
OP_STATUS
TempBuffer::AppendVFormat(const uni_char* format, va_list args)
{
	CHECK_INVARIANTS();

#ifdef va_copy
	// One cannot assume (according to manual) that args will
	// remain unchanged after the call to OpPrintf::Format()

	va_list args_copy;
	va_copy(args_copy, args);

	OpPrintf printer(OpPrintf::PRINTF_UNICODE);
	int len = printer.Format(NULL, 0, format, args_copy);
	int current_length = Length();

	va_end(args_copy);
#else // va_copy
	OpPrintf printer(OpPrintf::PRINTF_UNICODE);
	int len = printer.Format(NULL, 0, format, args);
	int current_length = Length();
#endif // va_copy

	RETURN_IF_ERROR(Expand(current_length + len + 1));
	uni_char* buf = GetStorage() + current_length;
	uni_vsnprintf(buf, len+1, format, args);

	cached_length = current_length + len;

	CHECK_INVARIANTS();

	return OpStatus::OK;
}
Пример #2
0
OP_STATUS TempBuffer::Append( const char *s, size_t n )
{
	CHECK_INVARIANTS();

	if (s == NULL || n == 0)
	{
		return OpStatus::OK;
	}

	size_t len = 0;

	const char* q = s;
	while (len < n && *q)
	{
		++q; ++len;
	}

	size_t used = Length()+1;
	size_t orig_len = len;

	RETURN_IF_ERROR( EnsureConstructed( used+len ) );

	uni_char *p;
	for ( p=storage+used-1 ; len ; len-- )
		*p++ = (uni_char)*s++;
	*p = 0;
	cached_length += orig_len;

	CHECK_INVARIANTS();
	return OpStatus::OK;
}
Пример #3
0
void TempBuffer::Clear()
{
	CHECK_INVARIANTS();

	if (storage)
		storage[0] = 0;
	cached_length = 0;

	CHECK_INVARIANTS();
}
Пример #4
0
OP_STATUS TempBuffer::Expand( size_t capacity )
{
	CHECK_INVARIANTS();

	if (capacity == 0)
		capacity = 1;

	RETURN_IF_ERROR( EnsureConstructed( capacity ) );

	CHECK_INVARIANTS();
	return OpStatus::OK;
}
Пример #5
0
errval_t
mdb_remove(struct cte *target)
{
    MDB_TRACE_ENTER(mdb_root, "%p", target);
    CHECK_INVARIANTS(mdb_root, target, true);
#ifdef IN_KERNEL
#ifdef MDB_TRACE_NO_RECURSIVE
    char prefix[50];
    snprintf(prefix, 50, "mdb_remove.%d: ", my_core_id);
    print_cte(target, prefix);
#endif
#endif
    errval_t err = mdb_subtree_remove(target, &mdb_root, NULL);
    CHECK_INVARIANTS(mdb_root, target, false);
    MDB_TRACE_LEAVE_SUB_RET("%"PRIuPTR, err, mdb_root);
}
Пример #6
0
TempBuffer* TempBuffer::Delete( size_t startp, size_t n )
{
	size_t len = Length();

	if (startp >= len || n == 0)
		(void)0; //nop
	else if (startp + n >= len)
	{
		storage[startp] = 0;

		if (flags.cached_length_policy == TRUSTED)
			cached_length = startp;
	}
	else
	{
		uni_char *p = storage + startp;
		uni_char  *q = p + n;
		size_t nmov = len - (startp + n);
		do
			*p++ = *q++;
		while (--nmov);
		*p = 0;

		if (flags.cached_length_policy == TRUSTED)
			cached_length = len - n;
	}

	CHECK_INVARIANTS();

	return this;
}
Пример #7
0
OP_STATUS TempBuffer::Append( const uni_char s )
{
	CHECK_INVARIANTS();

	size_t used = Length()+1;

	RETURN_IF_ERROR( EnsureConstructed( used+1 ) );

	uni_char *p;
	p=storage+used-1;
	*p++ = s;
	*p = 0;
	cached_length++;

	CHECK_INVARIANTS();
	return OpStatus::OK;
}
Пример #8
0
TempBuffer::TempBuffer()
{
	cached_length = 0;
	storage = 0;
	allocated = 0;
	flags.expansion_policy = AGGRESSIVE;
	flags.cached_length_policy = TRUSTED;
	CHECK_INVARIANTS();
}
Пример #9
0
void TempBuffer::FreeStorage()
{
	OP_DELETEA(storage);

	cached_length = 0;
	storage = 0;
	allocated = 0;
	flags.expansion_policy = AGGRESSIVE;
	flags.cached_length_policy = TRUSTED;

	CHECK_INVARIANTS();
}
Пример #10
0
OP_STATUS TempBuffer::EnsureConstructed( size_t capacity )
{
	OP_ASSERT(capacity > 0);

	if (storage && allocated >= capacity)
		return OpStatus::OK;

	if (GetExpansionPolicy() == AGGRESSIVE)
		capacity = MAX( capacity, allocated*2 );

	size_t nallocated = (capacity + (alignment-1)) & ~(alignment-1);
	uni_char *nstorage = OP_NEWA( uni_char, nallocated );
	CHECK_ALLOCATION( nstorage );

#ifdef _DEBUG
	// In debug mode, fill up the new space with the pattern "BUG!BUG!..." to
	// make printing of uninitialized memory easy to detect

	const uni_char *const bug = UNI_L("BUG!");

	for (size_t i = 0; i < nallocated; ++i)
		nstorage[i] = bug[i % 4];

#ifdef VALGRIND
	// Even though the buffer has been "initialized" to "BUG!BUG!...", we still
	// want Valgrind to treat it as undefined
	op_valgrind_set_undefined(nstorage, sizeof(uni_char) * nallocated);
#endif // VALGRIND

#endif // _DEBUG

	if (storage)
	{
		OP_ASSERT(uni_strlen(storage) >= Length());
		OP_ASSERT(uni_strlen(storage) < allocated);
		uni_strcpy( nstorage, storage );
		OP_DELETEA(storage);
	}
	else
		nstorage[0] = 0;
	storage = nstorage;
	allocated = nallocated;

	// As a precaution, write a null terminator to the end of the newly
	// allocated memory. This could save us from running off the end in case
	// buggy code forgets to null-terminate the buffer.
	storage[nallocated - 1] = 0;

	CHECK_INVARIANTS();
	return OpStatus::OK;
}
Пример #11
0
errval_t
mdb_insert(struct cte *new_node)
{
    MDB_TRACE_ENTER(mdb_root, "%p", new_node);
#ifdef IN_KERNEL
#ifdef MDB_TRACE_NO_RECURSIVE
    char prefix[50];
    snprintf(prefix, 50, "mdb_insert.%d: ", my_core_id);
    print_cte(new_node, prefix);
#endif
#endif
    errval_t ret = mdb_sub_insert(new_node, &mdb_root);
    CHECK_INVARIANTS(mdb_root, new_node, true);
    MDB_TRACE_LEAVE_SUB_RET("%"PRIuPTR, ret, mdb_root);
}