Example #1
0
Exec_stat MCVariableValue::lookup_index(MCExecPoint& ep, uint32_t index, bool p_add, MCVariableValue*& r_value)
{
	if (is_array())
		;
	else
	{
		if (!p_add)
		{
			r_value = nil;
			return ES_NORMAL;
		}
		assign_new_array(TABLE_SIZE);
	}
	
	MCHashentry *t_hashentry = array . lookupindex(index, p_add ? True : False);
	if (t_hashentry != nil)
		r_value = &(t_hashentry->value);
	else
		r_value = nil;

	if (p_add)
		set_dbg_mutated(true);
	
	return ES_NORMAL;
}
Example #2
0
Exec_stat MCVariableValue::transpose(MCVariableValue& v)
{
	if (!v . is_array())
	{
		assign_empty();
		return ES_NORMAL;
	}

	// MW-2009-01-22: [[ Bug 7240 ]] Probably a good idea to attempt to transpose 'v'
	//   rather than this's array (which is undefined!).
	MCVariableArray vt;
	Exec_stat stat;
	stat = vt . transpose(v . array);
	if (stat != ES_NORMAL)
		return stat;

	destroy();

	set_type(VF_ARRAY);
	array . taketable(&vt);
	
	set_dbg_mutated(true);

	return ES_NORMAL;
}
Example #3
0
IO_stat MCVariableValue::loadarray(MCObjectInputStream& p_stream, bool p_merge)
{
	if (!p_merge)
		destroy();
	
	set_type(VF_ARRAY);
    // MW-2014-08-12: [[ Bug 13154 ]] If we aren't merging reset the array.
    if (!p_merge)
        array . clear();

	IO_stat t_stat;
	t_stat = array . load(p_stream, p_merge);
	if (!p_merge && array . getnfilled() == 0)
	{
        // MW-2014-08-14: [[ Bug 13154 ]] Free the hash at this point otherwise we get a memory leak.
        array . freehash();
        
		set_type(VF_UNDEFINED);

		strnum . buffer . data = NULL;
		strnum . buffer . size = 0;
	}
	else
		set_dbg_mutated(true);

	return t_stat;
}
Example #4
0
bool MCVariableValue::copy(const MCVariableValue& v)
{
	set_type(v . get_type());
	set_dbg_changed(true);

	if (!v . is_array())
	{
		strnum . buffer . data = NULL;
		strnum . buffer . size = 0;

		if (v . is_number())
			strnum . nvalue = v . strnum . nvalue;

		if (v . is_string())
		{
			if (v . strnum . svalue . length > 0)
			{
				// MW-2008-08-26: [[ Bug 6981 ]] Make sure we don't do anything if memory is exhausted
				char *t_new_buffer;
				t_new_buffer = (char *)malloc(v . strnum . svalue . length);
				if (t_new_buffer != NULL)
				{
					strnum . buffer . data = t_new_buffer;
					strnum . buffer . size = v . strnum . svalue . length;

					memcpy(strnum . buffer . data, v . strnum . svalue . string, v . strnum . svalue . length);

					strnum . svalue . string = strnum . buffer . data;
					strnum . svalue . length = strnum . buffer . size;
				}
				else
				{
					strnum . svalue . string = MCnullstring;
					strnum . svalue . length = 0;
					return false;
				}
			}
			else
			{
				strnum . svalue . string = MCnullstring;
				strnum . svalue . length = 0;
			}
		}

		return true;
	}
	
	if (array . copytable(v . array))
	{
		set_dbg_mutated(true);
		return true;
	}
	
	clear();

	return false;
}
Example #5
0
void MCVariableValue::remove_hash(MCHashentry *p_entry)
{
	if (is_array())
	{
		array . removehash(p_entry);
		if (array . getnfilled() == 0)
			assign_empty();
		else
			set_dbg_mutated(true);
	}
}
Example #6
0
Exec_stat MCVariableValue::remove_element(MCExecPoint& ep, const MCString& key)
{
	if (is_array())
	{
		array . removehash(key, ep . getcasesensitive());
		if (array . getnfilled() == 0)
			assign_empty();
		else
			set_dbg_mutated(true);
	}

	return ES_NORMAL;
}
Example #7
0
// MERG-2013-08-26: [[ RecursiveArrayOp ]] Support nested arrays in union and intersect
Exec_stat MCVariableValue::intersectarray(MCVariableValue& v, bool p_recursive)
{
	if (!is_array() || !v . is_array())
	{
		assign_empty();
		return ES_NORMAL;
	}
	
	uint4 t_nfilled;
	t_nfilled = array . getnfilled();
	
	if (array . intersectarray(v . array, p_recursive) != ES_NORMAL)
		return ES_ERROR;
	
	set_dbg_mutated(t_nfilled != array . getnfilled());
	
	return ES_NORMAL;
}
Example #8
0
// MW-2012-09-04: [[ Bug 10284 ]] If the key shares the string buffer with the
//   variable then make a temporary copy of it, otherwise data gets overwritten
//   causing keys to be created with corrupted names.
Exec_stat MCVariableValue::lookup_hash(MCExecPoint& ep, const MCString& p_key, bool p_add, MCHashentry*& r_value)
{
	MCString t_key;
	bool t_free;
	t_free = false;
	if (is_array())
	{
		t_key = p_key;
		t_free = false;
	}
	else
	{
		if (!p_add)
		{
			r_value = NULL;
			return ES_NORMAL;
		}

		if (is_string() && (p_key . getstring() < strnum . buffer . data + strnum . buffer . size && p_key . getstring() + p_key . getlength() >= strnum . buffer . data))
		{
			t_key . set((char *)malloc(p_key . getlength()), p_key . getlength());
			memcpy((char *)t_key . getstring(), p_key . getstring(), p_key . getlength());
		}
		else
		{
			t_free = false;
			t_key = p_key;
		}

		assign_new_array(TABLE_SIZE);
	}
	
	r_value = array . lookuphash(t_key, ep . getcasesensitive(), p_add);
	
	if (t_free)
		free((void *)t_key . getstring());
	
	if (p_add)
		set_dbg_mutated(true);

	return ES_NORMAL;
}
Example #9
0
Exec_stat MCVariableValue::lookup_element(MCExecPoint& ep, const MCString& key, MCVariableValue*& r_value)
{
	if (is_array())
		;
	else
		assign_new_array(TABLE_SIZE);
	
	// MW-2012-09-04: [[ Bug 10284 ]] Use common 'lookup_hash' method.
	MCHashentry *t_value;
	Exec_stat t_stat;
	t_stat = lookup_hash(ep, key, True, t_value);
	if (t_stat == ES_ERROR)
		return t_stat;
	
	r_value = &(t_value -> value);

	set_dbg_mutated(true);
	
	return ES_NORMAL;
}
Example #10
0
IO_stat MCVariableValue::loadkeys(IO_header *stream, bool p_merge)
{
	if (!p_merge)
		destroy();

	IO_stat t_stat;

	set_type(VF_ARRAY);

	t_stat = array . loadkeys(stream, p_merge);
	if (!p_merge && array . getnfilled() == 0)
	{
		set_type(VF_UNDEFINED);
		strnum . buffer . data = NULL;
		strnum . buffer . size = 0;
	}

	set_dbg_mutated(true);
	
	return t_stat;
}
Example #11
0
IO_stat MCVariableValue::loadarray(MCObjectInputStream& p_stream, bool p_merge)
{
	if (!p_merge)
		destroy();
	
	set_type(VF_ARRAY);

	IO_stat t_stat;
	t_stat = array . load(p_stream, p_merge);
	if (!p_merge && array . getnfilled() == 0)
	{
		set_type(VF_UNDEFINED);

		strnum . buffer . data = NULL;
		strnum . buffer . size = 0;
	}
	else
		set_dbg_mutated(true);

	return t_stat;
}
Example #12
0
Exec_stat MCVariableValue::matrixmultiply(MCExecPoint& ep, MCVariableValue& va, MCVariableValue& vb)
{
	if (!va . is_array() || !vb . is_array())
	{
		assign_empty();
		return ES_NORMAL;
	}

	MCVariableArray vc;
	Exec_stat stat;
	stat = vc . matrixmultiply(ep, va . array, vb . array);
	if (stat != ES_NORMAL)
		return stat;

	destroy();

	set_type(VF_ARRAY);
	array . taketable(&vc);
	
	set_dbg_mutated(true);

	return ES_NORMAL;
}
Example #13
0
Exec_stat MCVariableValue::unionarray(MCVariableValue& v)
{
	if (!is_array())
		assign_empty();

	if (!v . is_array())
		return ES_NORMAL;

	if (is_empty())
	{
		assign(v);
		return ES_NORMAL;
	}

	uint4 t_nfilled;
	t_nfilled = array . getnfilled();
	
	if (array . unionarray(v . array) != ES_NORMAL)
		return ES_ERROR;
	
	set_dbg_mutated(t_nfilled != array . getnfilled());
	
	return ES_NORMAL;
}