1
by brian
clean slate |
1 |
/* Copyright (C) 2000-2001, 2003-2004 MySQL AB
|
2 |
||
3 |
This program is free software; you can redistribute it and/or modify
|
|
4 |
it under the terms of the GNU General Public License as published by
|
|
5 |
the Free Software Foundation; version 2 of the License.
|
|
6 |
||
7 |
This program is distributed in the hope that it will be useful,
|
|
8 |
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
9 |
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
10 |
GNU General Public License for more details.
|
|
11 |
||
12 |
You should have received a copy of the GNU General Public License
|
|
13 |
along with this program; if not, write to the Free Software
|
|
1802.10.2
by Monty Taylor
Update all of the copyright headers to include the correct address. |
14 |
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA */
|
1
by brian
clean slate |
15 |
|
16 |
||
17 |
/* Mallocs for used in threads */
|
|
18 |
||
1241.9.24
by Monty Taylor
Removed m_string.h from server_includes.h. |
19 |
#include "config.h" |
20 |
||
21 |
#include <string.h> |
|
22 |
||
23 |
#include "drizzled/errmsg_print.h" |
|
1253.1.4
by Monty Taylor
Moved sql_alloc into memory. |
24 |
#include "drizzled/memory/sql_alloc.h" |
1241.9.20
by Monty Taylor
Removed global sql_list.h include. |
25 |
#include "drizzled/current_session.h" |
26 |
#include "drizzled/error.h" |
|
1241.9.42
by Monty Taylor
Removed mysys from sql_alloc.h and table.h. |
27 |
#include "drizzled/definitions.h" |
28 |
||
1241.9.64
by Monty Taylor
Moved remaining non-public portions of mysys and mystrings to drizzled/internal. |
29 |
#include "drizzled/internal/my_sys.h" |
1
by brian
clean slate |
30 |
|
1253.1.6
by Monty Taylor
Moved mem_root functions into drizzled::memory:: namespace. |
31 |
namespace drizzled |
32 |
{
|
|
1253.1.3
by Monty Taylor
MEM_ROOT == memory::Root |
33 |
|
1280.1.10
by Monty Taylor
Put everything in drizzled into drizzled namespace. |
34 |
static void sql_alloc_error_handler(void) |
1085.1.2
by Monty Taylor
Fixed -Wmissing-declarations |
35 |
{
|
36 |
errmsg_printf(ERRMSG_LVL_ERROR, "%s",ER(ER_OUT_OF_RESOURCES)); |
|
1
by brian
clean slate |
37 |
}
|
38 |
||
1253.1.6
by Monty Taylor
Moved mem_root functions into drizzled::memory:: namespace. |
39 |
void memory::init_sql_alloc(memory::Root *mem_root, size_t block_size, size_t) |
1
by brian
clean slate |
40 |
{
|
1487
by Brian Aker
More updates for memory::Root |
41 |
mem_root->init_alloc_root(block_size); |
975.1.1
by Brian Aker
LCOV cleanup. |
42 |
mem_root->error_handler= sql_alloc_error_handler; |
1
by brian
clean slate |
43 |
}
|
44 |
||
45 |
||
1253.1.6
by Monty Taylor
Moved mem_root functions into drizzled::memory:: namespace. |
46 |
void *memory::sql_alloc(size_t Size) |
1
by brian
clean slate |
47 |
{
|
1253.1.3
by Monty Taylor
MEM_ROOT == memory::Root |
48 |
memory::Root *root= current_mem_root(); |
1486
by Brian Aker
More encapsulation. |
49 |
return root->alloc_root(Size); |
1
by brian
clean slate |
50 |
}
|
51 |
||
52 |
||
1253.1.6
by Monty Taylor
Moved mem_root functions into drizzled::memory:: namespace. |
53 |
void *memory::sql_calloc(size_t size) |
1
by brian
clean slate |
54 |
{
|
55 |
void *ptr; |
|
1486
by Brian Aker
More encapsulation. |
56 |
|
1253.1.6
by Monty Taylor
Moved mem_root functions into drizzled::memory:: namespace. |
57 |
if ((ptr=memory::sql_alloc(size))) |
212.6.1
by Mats Kindahl
Replacing all bzero() calls with memset() calls and removing the bzero.c file. |
58 |
memset(ptr, 0, size); |
1486
by Brian Aker
More encapsulation. |
59 |
|
1
by brian
clean slate |
60 |
return ptr; |
61 |
}
|
|
62 |
||
63 |
||
1253.1.6
by Monty Taylor
Moved mem_root functions into drizzled::memory:: namespace. |
64 |
char *memory::sql_strdup(const char *str) |
1
by brian
clean slate |
65 |
{
|
66 |
size_t len= strlen(str)+1; |
|
67 |
char *pos; |
|
1253.1.6
by Monty Taylor
Moved mem_root functions into drizzled::memory:: namespace. |
68 |
if ((pos= (char*) memory::sql_alloc(len))) |
1
by brian
clean slate |
69 |
memcpy(pos,str,len); |
70 |
return pos; |
|
71 |
}
|
|
72 |
||
73 |
||
1253.1.6
by Monty Taylor
Moved mem_root functions into drizzled::memory:: namespace. |
74 |
char *memory::sql_strmake(const char *str, size_t len) |
1
by brian
clean slate |
75 |
{
|
76 |
char *pos; |
|
1253.1.6
by Monty Taylor
Moved mem_root functions into drizzled::memory:: namespace. |
77 |
if ((pos= (char*) memory::sql_alloc(len+1))) |
1
by brian
clean slate |
78 |
{
|
79 |
memcpy(pos,str,len); |
|
80 |
pos[len]=0; |
|
81 |
}
|
|
82 |
return pos; |
|
83 |
}
|
|
84 |
||
85 |
||
1253.1.6
by Monty Taylor
Moved mem_root functions into drizzled::memory:: namespace. |
86 |
void* memory::sql_memdup(const void *ptr, size_t len) |
1
by brian
clean slate |
87 |
{
|
88 |
void *pos; |
|
1253.1.6
by Monty Taylor
Moved mem_root functions into drizzled::memory:: namespace. |
89 |
if ((pos= memory::sql_alloc(len))) |
1
by brian
clean slate |
90 |
memcpy(pos,ptr,len); |
91 |
return pos; |
|
92 |
}
|
|
93 |
||
1253.1.4
by Monty Taylor
Moved sql_alloc into memory. |
94 |
void *memory::SqlAlloc::operator new(size_t size) |
95 |
{
|
|
1253.1.6
by Monty Taylor
Moved mem_root functions into drizzled::memory:: namespace. |
96 |
return memory::sql_alloc(size); |
1253.1.4
by Monty Taylor
Moved sql_alloc into memory. |
97 |
}
|
98 |
||
99 |
void *memory::SqlAlloc::operator new[](size_t size) |
|
100 |
{
|
|
1253.1.6
by Monty Taylor
Moved mem_root functions into drizzled::memory:: namespace. |
101 |
return memory::sql_alloc(size); |
1253.1.4
by Monty Taylor
Moved sql_alloc into memory. |
102 |
}
|
103 |
||
104 |
void *memory::SqlAlloc::operator new[](size_t size, memory::Root *mem_root) |
|
1241.9.42
by Monty Taylor
Removed mysys from sql_alloc.h and table.h. |
105 |
{
|
1486
by Brian Aker
More encapsulation. |
106 |
return mem_root->alloc_root(size); |
1241.9.42
by Monty Taylor
Removed mysys from sql_alloc.h and table.h. |
107 |
}
|
108 |
||
1253.1.4
by Monty Taylor
Moved sql_alloc into memory. |
109 |
void *memory::SqlAlloc::operator new(size_t size, memory::Root *mem_root) |
1241.9.42
by Monty Taylor
Removed mysys from sql_alloc.h and table.h. |
110 |
{
|
1486
by Brian Aker
More encapsulation. |
111 |
return mem_root->alloc_root(size); |
1241.9.42
by Monty Taylor
Removed mysys from sql_alloc.h and table.h. |
112 |
}
|
1253.1.6
by Monty Taylor
Moved mem_root functions into drizzled::memory:: namespace. |
113 |
|
114 |
} /* namespace drizzled */ |