struct pvm_object
pvm_copy_object( struct pvm_object in_object )
{
    // TODO ERROR throw!
    if(in_object.data->_flags & PHANTOM_OBJECT_STORAGE_FLAG_IS_INTERNAL)
        panic("internal object copy?!");

    //ref_inc_o( in_object.data->_class );  //increment if class is refcounted
    struct pvm_object in_class = in_object.data->_class;
    int da_size = in_object.data->_da_size;

    struct pvm_object out = pvm_object_create_dynamic( in_class, da_size );

    int i = da_size/sizeof(struct pvm_object);
    for(; i >= 0; i-- )
    {
        if(da_po_ptr((in_object.data)->da)[i].data)
            ref_inc_o( da_po_ptr((in_object.data)->da)[i] );
    }

    memcpy( out.data->da, in_object.data->da, da_size );
    // TODO: check for special cases - copy c'tor?

    return out;
}
Exemple #2
0
struct pvm_object     pvm_create_string_object_binary_cat(
		const char *value1, int n_bytes1,
		const char *value2, int n_bytes2
)
{
	int das = sizeof(struct data_area_4_string)+n_bytes1+n_bytes2;
	struct pvm_object string_class = pvm_get_string_class();

	struct pvm_object	_data = pvm_object_create_dynamic( string_class, das );

	struct data_area_4_string* data_area = (struct data_area_4_string*)&(_data.data->da);

	pvm_internal_init_string(_data.data);

	if(value1)
	{
		memcpy(data_area->data, value1, data_area->length = n_bytes1 );
		if(value2)
		{
			memcpy(data_area->data+n_bytes1, value2, n_bytes2 );
			data_area->length += n_bytes2;
		}
	}

	return _data;

}
Exemple #3
0
struct pvm_object     pvm_create_binary_object(int size, void *init)
{
	struct pvm_object ret = pvm_object_create_dynamic( pvm_get_binary_class(), size + sizeof(struct data_area_4_binary) );

	struct data_area_4_binary *da = (struct data_area_4_binary *)ret.data->da;
	da->data_size = size;
	if( init != NULL ) memcpy( da->data, init, size );
	return ret;
}
Exemple #4
0
static struct pvm_object create_interface_worker( int n_methods )
{
	//if(debug_init) printf("create interface\n");

	int das = n_methods*sizeof(struct pvm_object);

	pvm_object_t ret = pvm_object_create_dynamic( pvm_get_interface_class(), das );
	return ret;
}
Exemple #5
0
struct pvm_object     pvm_create_code_object(int size, void *code)
{
	struct pvm_object ret = pvm_object_create_dynamic( pvm_get_code_class(), size + sizeof(struct data_area_4_code) );

	struct data_area_4_code *da = (struct data_area_4_code *)ret.data->da;
	da->code_size = size;
	memcpy( da->code, code, size );
	return ret;
}
Exemple #6
0
struct pvm_object     pvm_create_string_object_binary(const char *value, int n_bytes)
{
	int das = sizeof(struct data_area_4_string)+n_bytes;
	struct pvm_object string_class = pvm_get_string_class();

	struct pvm_object	_data = pvm_object_create_dynamic( string_class, das );

	struct data_area_4_string* data_area = (struct data_area_4_string*)&(_data.data->da);

	pvm_internal_init_string(_data.data);

	if(value)
		memcpy(data_area->data, value, data_area->length = n_bytes );

	return _data;

}
Exemple #7
0
struct pvm_object
pvm_create_page_object( int n_slots, struct pvm_object *init, int init_slots )
{
	int das = n_slots*sizeof(struct pvm_object);

	struct pvm_object _data = pvm_object_create_dynamic( pvm_get_page_class(), das );

	struct pvm_object * data_area = (struct pvm_object *)&(_data.data->da);

	// NB! Bug! Here is the way to set object pointers to some garbage value
	//if( init_value )	memcpy( data_area, init_value, das );
	//else            	memset( data_area, 0, das );

	assert(init_slots < n_slots);

	int i;
	for( i = 0; i < init_slots; i++ )
		data_area[i] = *init++;

	for( ; i < n_slots; i++ )
		data_area[i] = pvm_get_null_object();

	return _data;
}
Exemple #8
0
static struct pvm_object
pvm_object_create_fixed( struct pvm_object object_class )
{
	return pvm_object_create_dynamic( object_class, -1 );
}