Esempio n. 1
0
PyPackedRow* InventoryItem::GetItemRow() const
{
    PyList *keywords = new PyList();
    keywords->AddItem(new_tuple(new PyString("stacksize"), new PyToken("util.StackSize")));
    keywords->AddItem(new_tuple(new PyString("singleton"), new PyToken("util.Singleton")));

    DBRowDescriptor* header = new DBRowDescriptor(keywords);
    header->AddColumn( "itemID",     DBTYPE_I8 );
    header->AddColumn( "typeID",     DBTYPE_I4 );
    header->AddColumn( "ownerID",    DBTYPE_I4 );
    header->AddColumn( "locationID", DBTYPE_I8 );
    header->AddColumn( "flagID",     DBTYPE_I2 );
    header->AddColumn( "quantity",   DBTYPE_I4 );
    header->AddColumn( "groupID",    DBTYPE_I2 );
    header->AddColumn( "categoryID", DBTYPE_I4 );
    header->AddColumn( "customInfo", DBTYPE_STR );

    //header->AddColumn( "singleton",  DBTYPE_BOOL );
    //header->AddColumn( "stacksize" , DBTYPE_I4 );

    PyPackedRow* row = new PyPackedRow( header );
    GetItemRow( row );

    return row;
}
/*
 *	generate the quad operand
 */
TUPLE	*generate_quad_operand( int type, int index)
{
	TUPLE	*tuple;
	SYMBOL_TABLE *st;
	char	buffer[ 16];
	int	value;
/*
 *	switch on the operand type
 */
	switch( type)
	{
	case TYPE_IDENTIFIER:
/*
 *	find this index in the symbol table
 */
	     st = find_symbol_table_index( index);
	     sprintf( buffer, "%s_", st->string);
	     value = strlen( buffer) + 1;
	     tuple = new_tuple( I_MOV, 0, 0, MASK_LABEL | MASK_W_REG, buffer, value);
	     break;
	case TYPE_TEMPORARY:
	     sprintf( buffer, "t%d_", index);
	     value = strlen( buffer) + 1;
	     tuple = new_tuple( I_MOV, 0, 0, MASK_LABEL | MASK_W_REG, buffer, value);
	     break;
	case TYPE_LABEL:
	     sprintf( buffer, "label%d", index);
	     value = strlen( buffer) + 1;
	     tuple = new_tuple( I_LABEL, 0, 0, MASK_LABEL, buffer, value);
	     break;
	case TYPE_CONSTANT:
/*
 *	find this index in the symbol table
 */
	     st = find_symbol_table_index( index);
	     switch( st->format)
	     {
	     case FORMAT_HEX:
	     case FORMAT_OCTAL:
	     case FORMAT_DECIMAL:
	     	  value = st->ivalue;
	     	  break;
	     case FORMAT_FLOAT:
	     	  data.errors++;
	     	  fprintf( stderr, "error: PIC does not support floating point values: %s\n", st->string);
	     	  value = 0;
	     	  break;
	     }
	     tuple = new_tuple( I_MOV, value, 0, MASK_VALUE, 0, 0);
	     break;
	}
	return tuple;
}
   void KernelHandle::insertOrUpdateVirtualStigmergy(unsigned int id, std::string key_std, std::string value_std, time_t time_now, unsigned int robot_id)
   {
       std::string robot_id_string=boost::lexical_cast<std::string>(KernelInitializer::unique_robot_id_);
       std::string shm_object_name="KernelData"+robot_id_string;
       std::string mutex_name="named_kernel_mtx"+robot_id_string;
       boost::interprocess::named_mutex named_kernel_mtx(boost::interprocess::open_or_create, mutex_name.data()); 
       boost::interprocess::managed_shared_memory segment(boost::interprocess::open_or_create ,shm_object_name.data(), 102400);
   
       VoidAllocator alloc_inst (segment.get_segment_manager());
       
       micros_swarm_framework::shm_string  key(key_std.data(), alloc_inst);
       micros_swarm_framework::shm_string  value(value_std.data(), alloc_inst);
   
       std::pair<shm_virtual_stigmergy_type*, std::size_t> virtual_stigmergy = segment.find<shm_virtual_stigmergy_type>("shm_virtual_stigmergy_"); 
       if(virtual_stigmergy.first==0)
       {
           return;
       }
 
       shm_virtual_stigmergy_type *vst_pointer=virtual_stigmergy.first;
       shm_virtual_stigmergy_type::iterator vst_it;
       vst_it=vst_pointer->find(id);
   
       if(vst_it!=vst_pointer->end())
       {
           shm_virtual_stigmergy_tuple_type::iterator svstt_it=vst_it->second.find(key);
       
           if(svstt_it!=vst_it->second.end())
           {
               ShmVirtualStigmergyTuple new_tuple(value, time_now, robot_id, alloc_inst);
               
               named_kernel_mtx.lock();
               svstt_it->second = new_tuple;
               named_kernel_mtx.unlock();
           }
           else
           {
               ShmVirtualStigmergyTuple new_tuple(value, time_now, robot_id, alloc_inst);
               ShmVirtualStigmergyTupleType new_tuple_type(key,new_tuple);
               
               named_kernel_mtx.lock();
               vst_it->second.insert(new_tuple_type);
               named_kernel_mtx.unlock();
           }
       }
       else
       {       
           std::cout<<"ID "<<id<<" VirtualStigmergy is not exist."<<std::endl;
           return;
       }
   }
Esempio n. 4
0
	inline Tuple *remove_tuple(const Tuple *t, size_t pos)
	{
		Tuple *ret = new_tuple(t->m_count - 1);
		std::copy(t->begin(), t->begin() + pos, ret->m_data);
		std::copy(t->begin() + pos + 1, t->end(), ret->m_data + pos);
		return ret;
	}
Esempio n. 5
0
	inline Tuple *join_tuple(const Tuple *l, const Value &r)
	{
		Tuple *ret = new_tuple(l->m_count + 1);
		ret->m_data[l->m_count] = r;
		std::copy(l->begin(), l->end(), ret->m_data);
		return ret;
	}
Esempio n. 6
0
	inline Tuple *join_tuple(const Value &l, const Tuple *r)
	{
		Tuple *ret = new_tuple(1 + r->m_count);
		ret->m_data[0] = l;
		std::copy(r->begin(), r->end(), ret->m_data + 1);
		return ret;
	}
Esempio n. 7
0
	inline Tuple *join_tuple(const Tuple *l, const Tuple *r)
	{
		Tuple *ret = new_tuple(l->m_count + r->m_count);
		std::copy(l->begin(), l->end(), ret->m_data);
		std::copy(r->begin(), r->end(), ret->m_data + l->m_count);
		return ret;
	}
/*
 *	create a symbol table entry unless one already exists 
 */
void	create_symbol( int type, unsigned char value, char *buffer, int length)
{
	TUPLE	*tuple;
/*
 *	first search for same identifier string
 */
	tuple = find_symbol( data.level, buffer, length);
/*
 *	update symbol type entry or make new symbol table entry
 */
	if( tuple)
	{
		if( 0 < type)
			tuple->token = type;
		if( 0 < value)
			tuple->value = value;
		return;
	}
	tuple = new_tuple( type, value, get_address( 1), 0, buffer, length);
	tuple->level = data.level;
/*
 *	attach it to the head of the symbol table list (LIFO)
 */
	tuple->next = data.symbol_table;
	data.symbol_table = tuple;
	return;
}
/*
 *	convert postfix expression into tuple
		$$.tuple = tuple_postfix_expr( $1.tuple, 0);
		$$.tuple = tuple_postfix_expr( $1.tuple, $3.tuple);
 */
TUPLE	*tuple_postfix_expr( TUPLE *postfix_expr, TUPLE *argument_expr_list)
{
	TUPLE	*lists;
	TUPLE	*tuple_next;
/*
 *	special case is printf, after each argument insert call to printf
 */
	if( ! strcmp( postfix_expr->buffer, "printf"))
	{
		for( lists = argument_expr_list; lists; )
		{
			if( lists->mask & MASK_W_REG)
			{
				tuple_next = lists->next;
				lists->next = new_tuple( I_CALL, 0, 0, MASK_LABEL, "printf", sizeof( "printf") + 1); /* call printf */
				lists->next->next = tuple_next;
				lists = lists->next->next;
			}
			else
			{
				lists = lists->next;
			}
		}
		free_tuple_list( postfix_expr);
		return( argument_expr_list);
	}
	postfix_expr->token = I_CALL;
	postfix_expr->mask = MASK_LABEL;
	tuple_tail_to_head( postfix_expr, argument_expr_list);
	return( postfix_expr);
}
/*
 *	post process the instruction list
 *	insert RETURNs for subroutines without returns
 */
TUPLE	*code_post_process_return( TUPLE *tuple_list)
{
	TUPLE *lists;
	TUPLE *tuple_next;
/*
 *	check if return, function body
 */
	for( lists = tuple_list; lists; lists = lists->next)
	{
		switch( lists->token)
		{
		case I_RETURN:
		case I_RETFIE:
		case I_RETLW:
			break;
		default:
			if( lists->next && lists->next->token == I_LABEL && ! lists->next->value)	/* start of function body */
			{
				tuple_next = lists->next;
				lists->next = new_tuple( I_RETURN, 0, 0, MASK_INSTR, 0, 0);
				lists->next->next = tuple_next;
			}
		}
	}
	return( tuple_list);
}
Esempio n. 11
0
  void test_copy_from_length_exceeds_destination() {
    Tuple* tuple = new_tuple();
    Tuple* dest = Tuple::create(state, 2);
    TS_ASSERT_THROWS_ASSERT(dest->copy_from(state, tuple, Fixnum::from(0), Fixnum::from(3),
					    Fixnum::from(0)),
			    const RubyException &e,
			    TS_ASSERT(Exception::object_bounds_exceeded_error_p(state, e.exception)));
  }
Esempio n. 12
0
 void test_copy_from_other_empty() {
   Tuple* tuple = Tuple::create(state, 0);
   Tuple* dest = new_tuple();
   dest->copy_from(state, tuple, Fixnum::from(0), Fixnum::from(0), Fixnum::from(0));
   TS_ASSERT_EQUALS(Fixnum::from(1), as<Fixnum>(dest->at(state, 0)));
   TS_ASSERT_EQUALS(Fixnum::from(4), as<Fixnum>(dest->at(state, 1)));
   TS_ASSERT_EQUALS(Fixnum::from(9), as<Fixnum>(dest->at(state, 2)));
 }
Esempio n. 13
0
	inline Tuple *replace_tuple(const Tuple *t, size_t pos, const Value &val)
	{
		Tuple *ret = new_tuple(std::max(t->m_count, pos+1));
		std::copy(t->begin(), t->begin() + std::min(pos, t->m_count), ret->m_data);
		if (pos < t->m_count)
			std::copy(t->begin() + pos + 1, t->end(), ret->m_data + pos + 1);
		std::fill(ret->begin() + t->m_count, ret->end(), Nil);
		ret->m_data[pos] = val;
		return ret;
	}
void PythonPartitionerDelegator::Setup(const std::string& config) {
    try {
        boost::python::object partitioner = CPickleSerde().loads(config);
        _partition = partitioner.attr("partition");
        _args = new_tuple(2);
        _first_round = true;
    } catch (boost::python::error_already_set) {
        BIGFLOW_HANDLE_PYTHON_EXCEPTION();
    }
}
/*
 *	convert jump statement into tuple
		$$.tuple = tuple_jump_statement( $2.tuple);
 */
TUPLE	*tuple_jump_statement( TUPLE *return_expr)
{
	TUPLE	*tuple;

	tuple = end_tuple_list( return_expr);
	if( tuple->token == I_MOV && tuple->mask == MASK_VALUE)
		tuple->token = I_RETLW;
	else
		tuple->next = new_tuple( I_RETURN, 0, 0, MASK_INSTR, 0, 0);
	return( return_expr);
}
Esempio n. 16
0
  void test_delete_inplace() {
    Tuple *tuple = new_tuple();

    tuple->put(state, 1, Qnil);
    Integer *count = tuple->delete_inplace(state, Fixnum::from(0), Fixnum::from(3), Qnil);

    TS_ASSERT_EQUALS(1, count->to_native());
    TS_ASSERT_EQUALS(Fixnum::from(1), as<Fixnum>(tuple->at(state, 0)));
    TS_ASSERT_EQUALS(Fixnum::from(9), as<Fixnum>(tuple->at(state, 1)));
    TS_ASSERT_EQUALS(Qnil, tuple->at(state, 2));
  }
Esempio n. 17
0
	inline Tuple *split_string(const String *s, const String *by)
	{
		std::vector<Value> strings;
		String::const_iterator first = s->begin(), next;
		while (first <= s->end())
		{
			next = std::search(first, s->end(), by->begin(), by->end());
			strings.push_back(value(new_string(first, next)));
			first = next + by->m_count;
		}
		return new_tuple(strings.begin(), strings.end());
	}
Esempio n. 18
0
  void test_copy_from_dest_out_of_range() {
    Tuple* tuple = new_tuple();
    Tuple* dest = Tuple::create(state, 2);
    TS_ASSERT_THROWS_ASSERT(dest->copy_from(state, tuple, Fixnum::from(0), Fixnum::from(1),
					    Fixnum::from(2)),
			    const RubyException &e,
			    TS_ASSERT(Exception::object_bounds_exceeded_error_p(state, e.exception)));
    TS_ASSERT_THROWS_ASSERT(dest->copy_from(state, tuple, Fixnum::from(0), Fixnum::from(1),
					    Fixnum::from(-1)),
			    const RubyException &e,
			    TS_ASSERT(Exception::object_bounds_exceeded_error_p(state, e.exception)));
  }
/*
 *	convert selection statement into tuple
		$$.tuple = tuple_selection_statement( $3.tuple, $5.tuple, 0);
		$$.tuple = tuple_selection_statement( $3.tuple, $5.tuple, $7.tuple);
 */
TUPLE	*tuple_selection_statement( TUPLE *expr, TUPLE *statement1, TUPLE *statement2)
{
	char	buffer1[ 32];
	int	length1;
	char	buffer2[ 32];
	int	length2;
	TUPLE	*tuple;

	length1 = next_label( buffer1);
	tuple = end_tuple_list( expr);
	tuple->next = new_tuple( I_BTFSC, 0x02, 0x03, MASK_ADDRESS | MASK_VALUE, 0, 0);
	tuple->next->next = new_tuple( I_GOTO, 0, 0, MASK_LABEL, buffer1, length1);
	tuple_tail_to_head( tuple, statement1);
	tuple = end_tuple_list( statement1);
	if( ! statement2)
		tuple->next = new_tuple( I_LABEL, length1, 0, MASK_LABEL, buffer1, length1);
	else
	{
		length2 = next_label( buffer2);
		tuple->next = new_tuple( I_GOTO, 0, 0, MASK_LABEL, buffer2, length2);
		tuple->next->next = new_tuple( I_LABEL, length1, 0, MASK_LABEL, buffer1, length1);
		tuple_tail_to_head( tuple, statement2);
		tuple = end_tuple_list( statement2);
		tuple->next = new_tuple( I_LABEL, length2, 0, MASK_LABEL, buffer2, length2);
	}
	return( expr);
}
/*
 *	post process the instruction list
 *	insert post initialization code (goto mloop)
 */
TUPLE	*code_post_process_initialize( TUPLE *tuple_list)
{
	TUPLE *tuple = 0;
	TUPLE *lists;
	TUPLE *tuple_next;
/*
 *	create the instructions based on the main flag
 */
	if( IS_FLAGS_MAIN( data.flags))
	{
		tuple = new_tuple( I_MOV, 0, 0, MASK_LABEL | MASK_W_REG, "PORTA", sizeof( "PORTA") + 1);	/* read from stdin */
		tuple->next = new_tuple( I_CALL, 0, 0, MASK_LABEL, "main", sizeof( "main") + 1);		/* call main */
	}
	lists = new_tuple( I_GOTO, 0, 0, MASK_LABEL, "mloop", sizeof( "mloop") + 1);			/* goto mloop */
	tuple = tuple_tail_to_head( tuple, lists);
/*
 *	check if no declaration or just function body
 */
	if( ! tuple_list || tuple_list->token == I_LABEL)
	{
		tuple = tuple_tail_to_head( tuple, tuple_list);
		return( tuple);
	}
/*
 *	check if declaration list [ function body ]
 */
	for( lists = tuple_list; lists; lists = lists->next)
	{
		if( ! lists->next || lists->next->token == I_LABEL)	/* start of function body */
		{
			tuple_next = lists->next;
			lists->next = tuple;
			tuple_list = tuple_tail_to_head( tuple_list, tuple_next);
			return( tuple_list);
		}
	}
	return( tuple_list);
}
/*
 *	generate the quad destination
 */
TUPLE	*generate_quad_destination( int type, int index)
{
	TUPLE	*tuple;
	SYMBOL_TABLE *st;
	char	buffer[ 16];
	int	value;
/*
 *	switch on the operand type
 */
	switch( type)
	{
	case TYPE_IDENTIFIER:
/*
 *	find this index in the symbol table
 */
	     st = find_symbol_table_index( index);
	     sprintf( buffer, "%s_", st->string);
	     value = strlen( buffer) + 1;
	     tuple = new_tuple( I_MOV, 0, 0, MASK_LABEL, buffer, value);
	     break;
	case TYPE_TEMPORARY:
	     sprintf( buffer, "t%d_", index);
	     value = strlen( buffer) + 1;
	     tuple = new_tuple( I_MOV, 0, 0, MASK_LABEL, buffer, value);
	     break;
	case TYPE_LABEL:
	     sprintf( buffer, "label%d", index);
	     value = strlen( buffer) + 1;
	     tuple = new_tuple( I_LABEL, 0, 0, MASK_LABEL, buffer, value);
	     break;
	case TYPE_CONSTANT:
	     tuple = 0;
	     break;
	}
	return tuple;
}
/*
 *	iteration selection statement into tuple
		$$.tuple = tuple_iteration_statement( $3.tuple, $5.tuple);
 */
TUPLE	*tuple_iteration_statement( TUPLE *expr, TUPLE *statement)
{
	char	buffer1[ 32];
	int	length1;
	char	buffer2[ 32];
	int	length2;
	TUPLE	*tuple;
	TUPLE	*tuple2;
/*
 *	create the next temporary label
 */
	length1 = next_label( buffer1);
	length2 = next_label( buffer2);
	tuple = new_tuple( I_LABEL, length1, 0, MASK_LABEL, buffer1, length1);
	tuple->next = expr;
	tuple2 = end_tuple_list( expr);
	tuple2->next = new_tuple( I_BTFSC, 0x02, 0x03, MASK_ADDRESS | MASK_VALUE, 0, 0);
	tuple2->next->next = new_tuple( I_GOTO, 0, 0, MASK_LABEL, buffer2, length2);
	tuple_tail_to_head( tuple2, statement);
	tuple2 = end_tuple_list( statement);
	tuple2->next = new_tuple( I_GOTO, 0, 0, MASK_LABEL, buffer1, length1);
	tuple2->next->next = new_tuple( I_LABEL, length2, 0, MASK_LABEL, buffer2, length2);
	return( tuple);
}
/*
 *	generate initialize code for this list of identifiers
		$$.tuple = tuple_declaration( $1.token, $$.tuple);
 */
TUPLE	*tuple_declaration( int declaration_specifiers, TUPLE *init_declarator_list)
{
	TUPLE	*lists;
	TUPLE	*symbol;
	TUPLE	*tuple;
	TUPLE	*tuple_head = 0;
/*
 *	can be a list of identifiers
 */
	for( lists = init_declarator_list; lists; lists = lists->next)
	{
/*
 *	find the identifier in the symbol table (shall already be there!)
 */
		symbol = find_symbol( 0, lists->buffer, lists->length);
/*
 *	generate the intermediate code to initialize the variables
 */
		if( symbol)
		{
			if( symbol->level == 0 || symbol->value)
			{
				tuple = new_tuple( I_MOV, symbol->value, 0, MASK_VALUE, 0, 0);
				tuple_head = tuple_tail_to_head( tuple_head, tuple);
			}
			if( IS_FLAGS_ADDRESS( data.flags))
				tuple = new_tuple( I_MOV, 0, symbol->address, MASK_ADDRESS, 0, 0);
			else
				tuple = new_tuple( I_MOV, 0, 0, MASK_LABEL, symbol->buffer, symbol->length);
			tuple->level = symbol->level;
			tuple_head = tuple_tail_to_head( tuple_head, tuple);
		}
	}
	free_tuple_list( init_declarator_list);
	return( tuple_head);
}
Esempio n. 24
0
CRowSet* Inventory::List( EVEItemFlags _flag, uint32 forOwner ) const
{
    PyList *keywords = new PyList();
    keywords->AddItem(new_tuple(new PyString("stacksize"), new PyToken("util.StackSize")));
    keywords->AddItem(new_tuple(new PyString("singleton"), new PyToken("util.Singleton")));

    DBRowDescriptor* header = new DBRowDescriptor(keywords);
    header->AddColumn( "itemID",     DBTYPE_I8 );
    header->AddColumn( "typeID",     DBTYPE_I4 );
    header->AddColumn( "ownerID",    DBTYPE_I4 );
    header->AddColumn( "locationID", DBTYPE_I8 );
    header->AddColumn( "flagID",     DBTYPE_I2 );
    header->AddColumn( "quantity",   DBTYPE_I4 );
    header->AddColumn( "groupID",    DBTYPE_I2 );
    header->AddColumn( "categoryID", DBTYPE_I4 );
    header->AddColumn( "customInfo", DBTYPE_STR );

    //header->AddColumn( "singleton",  DBTYPE_BOOL );
    //header->AddColumn( "stacksize" , DBTYPE_I4 );

    CRowSet* rowset = new CRowSet( &header );
    List( rowset, _flag, forOwner );
    return rowset;
}
/*
 *	convert primary expression string literal into tuple
		$$.tuple = tuple_primary_expr_string_literal( $1.tuple);
 */
TUPLE	*tuple_primary_expr_string_literal( TUPLE *tuple)
{
	int index;
	TUPLE	*tuple_head = 0;
	TUPLE	*lists;
/*
 *	loop over string literal length to move char to w_reg then to memory address
 *	post processing will insert a call printf instruction for each character
 */
	for( index = 0; index < tuple->length; index++)
	{
		lists = new_tuple( I_MOV, tuple->buffer[ index], 0, MASK_VALUE | MASK_W_REG, 0, 0);
		tuple_head = tuple_tail_to_head( tuple_head, lists);
	}
	free_tuple( tuple);
	return( tuple_head);
}
   VstigTuple KernelHandle::getVirtualStigmergyTuple(unsigned int id, std::string key_std)
   {
       std::string robot_id_string=boost::lexical_cast<std::string>(KernelInitializer::unique_robot_id_);
       std::string shm_object_name="KernelData"+robot_id_string;
       boost::interprocess::managed_shared_memory segment(boost::interprocess::open_or_create ,shm_object_name.data(), 102400);
       VoidAllocator alloc_inst (segment.get_segment_manager());
       
       micros_swarm_framework::shm_string  key(key_std.data(), alloc_inst);
   
       std::pair<shm_virtual_stigmergy_type*, std::size_t> virtual_stigmergy = segment.find<shm_virtual_stigmergy_type>("shm_virtual_stigmergy_"); 
       if(virtual_stigmergy.first==0)
       {
           
       }
 
       shm_virtual_stigmergy_type *vst_pointer=virtual_stigmergy.first;
       shm_virtual_stigmergy_type::iterator vst_it;
       vst_it=vst_pointer->find(id);
   
       if(vst_it!=vst_pointer->end())
       {
           shm_virtual_stigmergy_tuple_type::iterator svstt_it=vst_it->second.find(key);
       
           if(svstt_it!=vst_it->second.end())
           {
               shm_string value_shm=svstt_it->second.getVirtualStigmergyValue();
               std::string value(value_shm.data(), value_shm.size());
               time_t time_now=svstt_it->second.getVirtualStigmergyTimestamp();
               unsigned int robot_id=svstt_it->second.getRobotID();
               VstigTuple new_tuple(value, time_now, robot_id);
               
               return new_tuple;
           }
       }
       
       std::string value="";
       time_t time_now=0;
       unsigned int robot_id=0;
       VstigTuple tuple(value, time_now, robot_id);
           
       return tuple;
   }
Esempio n. 27
0
PyObject *PyCachedObject::Encode()
{
    PyTuple *arg_tuple = new PyTuple(7);

    arg_tuple->items[0] = new_tuple(new PyLong(timestamp), new PyInt(version));

    arg_tuple->items[1] = new PyNone();

    arg_tuple->items[2] = new PyInt(nodeID);

    arg_tuple->items[3] = new PyInt(shared?1:0);

    //compression or not, we want to encode this into bytes so it doesn't
    //get cloned in object form just to be encoded later
/*  cache->EncodeData();
    if(compressed) {
        uint8 *buf = new uint8[cache->length];
        uint32 deflen = DeflatePacket(cache->data, cache->length, buf, cache->length);
        if(deflen == 0 || deflen >= cache->length) {
            //failed to deflate or it did no good (client checks this)
            memcpy(buf, cache->data, cache->length);
            deflen = cache->length;
            compressed = false;
        }
        //buf is consumed:
        arg_tuple->items[4] = new PyBuffer(&buf, deflen);
    } else {
        //TODO: we dont really need to clone this if we can figure out a way to say "this is read only"
        //or if we can change this encode method to consume the PyCachedObject (which will almost always be the case)
        arg_tuple->items[4] = cache->Clone();
    }*/
    //TODO: we don't really need to clone this if we can figure out a way to say "this is read only"
    //or if we can change this encode method to consume the PyCachedObject (which will almost always be the case)
    arg_tuple->items[4] = cache->Clone();

    arg_tuple->items[5] = new PyInt(compressed?1:0);

    //same cloning stattement as above.
    arg_tuple->items[6] = objectID->Clone();

    return new PyObject( "objectCaching.CachedObject", arg_tuple );
}
Esempio n. 28
0
  void test_delete_inplace_bounds() {
    Tuple *tuple = new_tuple();

    Integer *count;
    TS_ASSERT_THROWS_ASSERT(count = tuple->delete_inplace(state, Fixnum::from(0), Fixnum::from(4), Qnil),
			    const RubyException &e,
			    TS_ASSERT(Exception::object_bounds_exceeded_error_p(state, e.exception)));
    TS_ASSERT_THROWS_ASSERT(count = tuple->delete_inplace(state, Fixnum::from(1), Fixnum::from(3), Qnil),
			    const RubyException &e,
			    TS_ASSERT(Exception::object_bounds_exceeded_error_p(state, e.exception)));
    TS_ASSERT_THROWS_ASSERT(count = tuple->delete_inplace(state, Fixnum::from(-1), Fixnum::from(3), Qnil),
			    const RubyException &e,
			    TS_ASSERT(Exception::object_bounds_exceeded_error_p(state, e.exception)));
    TS_ASSERT_THROWS_ASSERT(count = tuple->delete_inplace(state, Fixnum::from(0), Fixnum::from(-1), Qnil),
			    const RubyException &e,
			    TS_ASSERT(Exception::object_bounds_exceeded_error_p(state, e.exception)));
    TS_ASSERT_THROWS_ASSERT(count = tuple->delete_inplace(state, Fixnum::from(3), Fixnum::from(1), Qnil),
			    const RubyException &e,
			    TS_ASSERT(Exception::object_bounds_exceeded_error_p(state, e.exception)));
  }
/*
 *	generate the tuple from quad list
 */
TUPLE	*generate_quad_2_tuple( QUAD *quad_list)
{
	TUPLE *tuple;
	TUPLE *tuple_tail;
	QUAD	*quad;
/*
 *	create nop on head of list
 */
	tuple = new_tuple( I_NOP, 0, 0, MASK_INSTR, 0, 0);
	tuple_tail = tuple;
/*
 *	generate the quad linked list structure
 */
	for( quad = quad_list; quad; quad = quad->next)
	{
		tuple_tail->next = generate_quad( quad);
		tuple_tail = end_tuple_list( tuple_tail);
	}
	return tuple;
}
Esempio n. 30
0
 void test_fields_prim() {
   Tuple* tuple = new_tuple();
   TS_ASSERT_EQUALS(Fixnum::from(3), as<Fixnum>(tuple->fields_prim(state)));
 }