1/*****************************************************************************
2
3Copyright (c) 1996, 2009, Oracle and/or its affiliates. All Rights Reserved.
4
5This program is free software; you can redistribute it and/or modify
6it under the terms of the GNU General Public License, version 2.0,
7as published by the Free Software Foundation.
8
9This program is also distributed with certain software (including
10but not limited to OpenSSL) that is licensed under separate terms,
11as designated in a particular file or component or in included license
12documentation.  The authors of MySQL hereby grant you an additional
13permission to link the program and your derivative works with the
14separately licensed software that they have included with MySQL.
15
16This program is distributed in the hope that it will be useful,
17but WITHOUT ANY WARRANTY; without even the implied warranty of
18MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
19GNU General Public License, version 2.0, for more details.
20
21You should have received a copy of the GNU General Public License along with
22this program; if not, write to the Free Software Foundation, Inc.,
2351 Franklin Street, Suite 500, Boston, MA 02110-1335 USA
24
25*****************************************************************************/
26
27/******************************************************************//**
28@file include/dict0mem.ic
29Data dictionary memory object creation
30
31Created 1/8/1996 Heikki Tuuri
32***********************************************************************/
33
34#include "data0type.h"
35#include "dict0mem.h"
36#include "fil0fil.h"
37
38/**********************************************************************//**
39This function poplulates a dict_index_t index memory structure with
40supplied information. */
41UNIV_INLINE
42void
43dict_mem_fill_index_struct(
44/*=======================*/
45	dict_index_t*	index,		/*!< out: index to be filled */
46	mem_heap_t*	heap,		/*!< in: memory heap */
47	const char*	table_name,	/*!< in: table name */
48	const char*	index_name,	/*!< in: index name */
49	ulint		space,		/*!< in: space where the index tree is
50					placed, ignored if the index is of
51					the clustered type */
52	ulint		type,		/*!< in: DICT_UNIQUE,
53					DICT_CLUSTERED, ... ORed */
54	ulint		n_fields)	/*!< in: number of fields */
55{
56
57	if (heap) {
58		index->heap = heap;
59		index->name = mem_heap_strdup(heap, index_name);
60		index->fields = (dict_field_t*) mem_heap_alloc(
61			heap, 1 + n_fields * sizeof(dict_field_t));
62	} else {
63		index->name = index_name;
64		index->heap = NULL;
65		index->fields = NULL;
66	}
67
68	/* Assign a ulint to a 4-bit-mapped field.
69	Only the low-order 4 bits are assigned. */
70	index->type = type;
71#ifndef UNIV_HOTBACKUP
72	index->space = (unsigned int) space;
73	index->page = FIL_NULL;
74#endif /* !UNIV_HOTBACKUP */
75	index->table_name = table_name;
76	index->n_fields = (unsigned int) n_fields;
77	/* The '1 +' above prevents allocation
78	of an empty mem block */
79#ifdef UNIV_DEBUG
80	index->magic_n = DICT_INDEX_MAGIC_N;
81#endif /* UNIV_DEBUG */
82}
83