~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to drizzled/sql_alloc.cc

  • Committer: Brian Aker
  • Date: 2009-10-15 00:22:33 UTC
  • mto: (1183.1.11 merge)
  • mto: This revision was merged to the branch mainline in revision 1198.
  • Revision ID: brian@gaz-20091015002233-fa4ao2mbc67wls91
First pass of information engine. OMG, ponies... is it so much easier to
deal with creating and engine.

The list table iterator though... its ass, needs to go. We should also
abstract out share. Very few engines need a custom one. Just say'in

Show diffs side-by-side

added added

removed removed

Lines of Context:
11
11
 
12
12
   You should have received a copy of the GNU General Public License
13
13
   along with this program; if not, write to the Free Software
14
 
   Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA */
 
14
   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA */
15
15
 
16
16
 
17
17
/* Mallocs for used in threads */
18
18
 
19
 
#include "config.h"
20
 
 
21
 
#include <string.h>
22
 
 
23
 
#include "drizzled/errmsg_print.h"
24
 
#include "drizzled/memory/sql_alloc.h"
25
 
#include "drizzled/current_session.h"
26
 
#include "drizzled/error.h"
27
 
#include "drizzled/definitions.h"
28
 
 
29
 
#include "drizzled/internal/my_sys.h"
30
 
 
31
 
namespace drizzled
32
 
{
33
 
 
34
 
static void sql_alloc_error_handler(void)
 
19
#include <drizzled/server_includes.h>
 
20
#include <drizzled/current_session.h>
 
21
#include <drizzled/error.h>
 
22
 
 
23
extern "C" void sql_alloc_error_handler(void);
 
24
 
 
25
extern "C" void sql_alloc_error_handler(void)
35
26
{
36
27
  errmsg_printf(ERRMSG_LVL_ERROR, "%s",ER(ER_OUT_OF_RESOURCES));
37
28
}
38
29
 
39
 
void memory::init_sql_alloc(memory::Root *mem_root, size_t block_size, size_t)
 
30
void init_sql_alloc(MEM_ROOT *mem_root, size_t block_size, size_t pre_alloc)
40
31
{
41
 
  mem_root->init_alloc_root(block_size);
 
32
  init_alloc_root(mem_root, block_size, pre_alloc);
42
33
  mem_root->error_handler= sql_alloc_error_handler;
43
34
}
44
35
 
45
36
 
46
 
void *memory::sql_alloc(size_t Size)
 
37
void *sql_alloc(size_t Size)
47
38
{
48
 
  memory::Root *root= current_mem_root();
49
 
  return root->alloc_root(Size);
 
39
  MEM_ROOT *root= current_mem_root();
 
40
  return alloc_root(root,Size);
50
41
}
51
42
 
52
43
 
53
 
void *memory::sql_calloc(size_t size)
 
44
void *sql_calloc(size_t size)
54
45
{
55
46
  void *ptr;
56
 
 
57
 
  if ((ptr=memory::sql_alloc(size)))
 
47
  if ((ptr=sql_alloc(size)))
58
48
    memset(ptr, 0, size);
59
 
 
60
49
  return ptr;
61
50
}
62
51
 
63
52
 
64
 
char *memory::sql_strdup(const char *str)
 
53
char *sql_strdup(const char *str)
65
54
{
66
55
  size_t len= strlen(str)+1;
67
56
  char *pos;
68
 
  if ((pos= (char*) memory::sql_alloc(len)))
 
57
  if ((pos= (char*) sql_alloc(len)))
69
58
    memcpy(pos,str,len);
70
59
  return pos;
71
60
}
72
61
 
73
62
 
74
 
char *memory::sql_strmake(const char *str, size_t len)
 
63
char *sql_strmake(const char *str, size_t len)
75
64
{
76
65
  char *pos;
77
 
  if ((pos= (char*) memory::sql_alloc(len+1)))
 
66
  if ((pos= (char*) sql_alloc(len+1)))
78
67
  {
79
68
    memcpy(pos,str,len);
80
69
    pos[len]=0;
83
72
}
84
73
 
85
74
 
86
 
void* memory::sql_memdup(const void *ptr, size_t len)
 
75
void* sql_memdup(const void *ptr, size_t len)
87
76
{
88
77
  void *pos;
89
 
  if ((pos= memory::sql_alloc(len)))
 
78
  if ((pos= sql_alloc(len)))
90
79
    memcpy(pos,ptr,len);
91
80
  return pos;
92
81
}
93
82
 
94
 
void *memory::SqlAlloc::operator new(size_t size)
95
 
{
96
 
  return memory::sql_alloc(size);
97
 
}
98
 
 
99
 
void *memory::SqlAlloc::operator new[](size_t size)
100
 
{
101
 
  return memory::sql_alloc(size);
102
 
}
103
 
 
104
 
void *memory::SqlAlloc::operator new[](size_t size, memory::Root *mem_root)
105
 
{
106
 
  return mem_root->alloc_root(size);
107
 
}
108
 
 
109
 
void *memory::SqlAlloc::operator new(size_t size, memory::Root *mem_root)
110
 
{
111
 
  return mem_root->alloc_root(size);
112
 
}
113
 
 
114
 
} /* namespace drizzled */