pair_t * pair_create(const object_t * first, const object_t * second) {
    pair_t * pair;

    if (!(pair = malloc(sizeof(pair_t))))     goto ERR_MALLOC;
    if (!(pair->first  = object_dup(first)))  goto ERR_FIRST_DUP;
    if (!(pair->second = object_dup(second))) goto ERR_SECOND_DUP;
    return pair;

ERR_SECOND_DUP:
    if (first->free && first->element) object_free(first->element);
ERR_FIRST_DUP:
    free(pair);
ERR_MALLOC:
    return NULL;
}
Example #2
0
/*
 * Add an item to the player's inventory.  Uses inven_carry_inven()
 * to do the real work.
 */
s16b inven_carry(object_type *o_ptr, bool final)
{
	s32b slot;
	object_type *copy_ptr;

	/* Clean out unused fields */
	o_ptr->iy = o_ptr->ix = 0;
	o_ptr->next_o_idx = 0;
	o_ptr->held_m_idx = 0;

	/* Make a copy in case we need it */
	copy_ptr = object_dup(o_ptr);

	slot = inven_carry_inven(get_inven(p_ptr, INVEN_INVEN), o_ptr, final);
	if (slot == -1)
	{
		drop_near(copy_ptr, 0, p_ptr->py, p_ptr->px);
	}
	else
	{
		/* Ok we didnt needed the copy */
		object_wipe(copy_ptr);
		delete_object(copy_ptr);
	}
	return slot;
} /* inven_carry() */