1 | /* Copyright (C) 2012-2017 Kentoku Shiba |
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 |
14 | Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ |
15 | |
16 | #define MYSQL_SERVER 1 |
17 | #include <my_global.h> |
18 | #include "mysql_version.h" |
19 | #include "spd_environ.h" |
20 | #if MYSQL_VERSION_ID < 50500 |
21 | #include "mysql_priv.h" |
22 | #include <mysql/plugin.h> |
23 | #else |
24 | #include "sql_priv.h" |
25 | #include "probes_mysql.h" |
26 | #include "sql_class.h" |
27 | #include "sql_analyse.h" |
28 | #endif |
29 | #include "spd_db_include.h" |
30 | #include "spd_include.h" |
31 | #include "spd_malloc.h" |
32 | |
33 | extern handlerton *spider_hton_ptr; |
34 | |
35 | pthread_mutex_t spider_mem_calc_mutex; |
36 | |
37 | const char *spider_alloc_func_name[SPIDER_MEM_CALC_LIST_NUM]; |
38 | const char *spider_alloc_file_name[SPIDER_MEM_CALC_LIST_NUM]; |
39 | ulong spider_alloc_line_no[SPIDER_MEM_CALC_LIST_NUM]; |
40 | ulonglong spider_total_alloc_mem[SPIDER_MEM_CALC_LIST_NUM]; |
41 | longlong spider_current_alloc_mem[SPIDER_MEM_CALC_LIST_NUM]; |
42 | ulonglong spider_alloc_mem_count[SPIDER_MEM_CALC_LIST_NUM]; |
43 | ulonglong spider_free_mem_count[SPIDER_MEM_CALC_LIST_NUM]; |
44 | |
45 | void spider_merge_mem_calc( |
46 | SPIDER_TRX *trx, |
47 | bool force |
48 | ) { |
49 | uint roop_count; |
50 | time_t tmp_time; |
51 | DBUG_ENTER("spider_merge_mem_calc" ); |
52 | if (force) |
53 | { |
54 | pthread_mutex_lock(&spider_mem_calc_mutex); |
55 | tmp_time = (time_t) time((time_t*) 0); |
56 | } else { |
57 | tmp_time = (time_t) time((time_t*) 0); |
58 | if ( |
59 | difftime(tmp_time, trx->mem_calc_merge_time) < 2 || |
60 | pthread_mutex_trylock(&spider_mem_calc_mutex) |
61 | ) |
62 | DBUG_VOID_RETURN; |
63 | } |
64 | for (roop_count = 0; roop_count < SPIDER_MEM_CALC_LIST_NUM; roop_count++) |
65 | { |
66 | DBUG_ASSERT(!spider_alloc_func_name[roop_count] || |
67 | !trx->alloc_func_name[roop_count] || |
68 | spider_alloc_func_name[roop_count] == trx->alloc_func_name[roop_count]); |
69 | DBUG_ASSERT(!spider_alloc_file_name[roop_count] || |
70 | !trx->alloc_file_name[roop_count] || |
71 | spider_alloc_file_name[roop_count] == trx->alloc_file_name[roop_count]); |
72 | DBUG_ASSERT(!spider_alloc_line_no[roop_count] || |
73 | !trx->alloc_line_no[roop_count] || |
74 | spider_alloc_line_no[roop_count] == trx->alloc_line_no[roop_count]); |
75 | if (trx->alloc_func_name[roop_count]) |
76 | { |
77 | spider_alloc_func_name[roop_count] = trx->alloc_func_name[roop_count]; |
78 | spider_alloc_file_name[roop_count] = trx->alloc_file_name[roop_count]; |
79 | spider_alloc_line_no[roop_count] = trx->alloc_line_no[roop_count]; |
80 | spider_total_alloc_mem[roop_count] += |
81 | trx->total_alloc_mem_buffer[roop_count]; |
82 | trx->total_alloc_mem_buffer[roop_count] = 0; |
83 | spider_alloc_mem_count[roop_count] += |
84 | trx->alloc_mem_count_buffer[roop_count]; |
85 | trx->alloc_mem_count_buffer[roop_count] = 0; |
86 | } |
87 | spider_current_alloc_mem[roop_count] += |
88 | trx->current_alloc_mem_buffer[roop_count]; |
89 | trx->current_alloc_mem_buffer[roop_count] = 0; |
90 | spider_free_mem_count[roop_count] += |
91 | trx->free_mem_count_buffer[roop_count]; |
92 | trx->free_mem_count_buffer[roop_count] = 0; |
93 | } |
94 | pthread_mutex_unlock(&spider_mem_calc_mutex); |
95 | trx->mem_calc_merge_time = tmp_time; |
96 | DBUG_VOID_RETURN; |
97 | } |
98 | |
99 | void spider_free_mem_calc( |
100 | SPIDER_TRX *trx, |
101 | uint id, |
102 | size_t size |
103 | ) { |
104 | DBUG_ENTER("spider_free_mem_calc" ); |
105 | DBUG_ASSERT(id < SPIDER_MEM_CALC_LIST_NUM); |
106 | DBUG_PRINT("info" ,("spider trx=%p id=%u size=%llu" , |
107 | trx, id, (ulonglong) size)); |
108 | if (trx) |
109 | { |
110 | DBUG_PRINT("info" ,("spider calc into trx" )); |
111 | trx->current_alloc_mem[id] -= size; |
112 | trx->current_alloc_mem_buffer[id] -= size; |
113 | trx->free_mem_count[id] += 1; |
114 | trx->free_mem_count_buffer[id] += 1; |
115 | } else { |
116 | DBUG_PRINT("info" ,("spider calc into global" )); |
117 | pthread_mutex_lock(&spider_mem_calc_mutex); |
118 | spider_current_alloc_mem[id] -= size; |
119 | spider_free_mem_count[id] += 1; |
120 | pthread_mutex_unlock(&spider_mem_calc_mutex); |
121 | } |
122 | DBUG_VOID_RETURN; |
123 | } |
124 | |
125 | void spider_alloc_mem_calc( |
126 | SPIDER_TRX *trx, |
127 | uint id, |
128 | const char *func_name, |
129 | const char *file_name, |
130 | ulong line_no, |
131 | size_t size |
132 | ) { |
133 | DBUG_ENTER("spider_alloc_mem_calc" ); |
134 | DBUG_ASSERT(id < SPIDER_MEM_CALC_LIST_NUM); |
135 | DBUG_PRINT("info" ,("spider trx=%p id=%u size=%llu" , |
136 | trx, id, (ulonglong) size)); |
137 | if (trx) |
138 | { |
139 | DBUG_PRINT("info" ,("spider calc into trx" )); |
140 | DBUG_ASSERT(!trx->alloc_func_name[id] || |
141 | trx->alloc_func_name[id] == func_name); |
142 | DBUG_ASSERT(!trx->alloc_file_name[id] || |
143 | trx->alloc_file_name[id] == file_name); |
144 | DBUG_ASSERT(!trx->alloc_line_no[id] || |
145 | trx->alloc_line_no[id] == line_no); |
146 | trx->alloc_func_name[id] = func_name; |
147 | trx->alloc_file_name[id] = file_name; |
148 | trx->alloc_line_no[id] = line_no; |
149 | trx->total_alloc_mem[id] += size; |
150 | trx->total_alloc_mem_buffer[id] += size; |
151 | trx->current_alloc_mem[id] += size; |
152 | trx->current_alloc_mem_buffer[id] += size; |
153 | trx->alloc_mem_count[id] += 1; |
154 | trx->alloc_mem_count_buffer[id] += 1; |
155 | } else { |
156 | DBUG_PRINT("info" ,("spider calc into global" )); |
157 | pthread_mutex_lock(&spider_mem_calc_mutex); |
158 | DBUG_ASSERT(!spider_alloc_func_name[id] || |
159 | spider_alloc_func_name[id] == func_name); |
160 | DBUG_ASSERT(!spider_alloc_file_name[id] || |
161 | spider_alloc_file_name[id] == file_name); |
162 | DBUG_ASSERT(!spider_alloc_line_no[id] || |
163 | spider_alloc_line_no[id] == line_no); |
164 | spider_alloc_func_name[id] = func_name; |
165 | spider_alloc_file_name[id] = file_name; |
166 | spider_alloc_line_no[id] = line_no; |
167 | spider_total_alloc_mem[id] += size; |
168 | spider_current_alloc_mem[id] += size; |
169 | spider_alloc_mem_count[id] += 1; |
170 | pthread_mutex_unlock(&spider_mem_calc_mutex); |
171 | } |
172 | DBUG_VOID_RETURN; |
173 | } |
174 | |
175 | void spider_free_mem( |
176 | SPIDER_TRX *trx, |
177 | void *ptr, |
178 | myf my_flags |
179 | ) { |
180 | uint id, size; |
181 | uchar *tmp_ptr = (uchar *) ptr; |
182 | DBUG_ENTER("spider_free_mem" ); |
183 | tmp_ptr -= ALIGN_SIZE(sizeof(uint)); |
184 | size = *((uint *) tmp_ptr); |
185 | tmp_ptr -= ALIGN_SIZE(sizeof(uint)); |
186 | id = *((uint *) tmp_ptr); |
187 | spider_my_free(tmp_ptr, my_flags); |
188 | |
189 | spider_free_mem_calc(trx, id, size); |
190 | DBUG_VOID_RETURN; |
191 | } |
192 | |
193 | void *spider_alloc_mem( |
194 | SPIDER_TRX *trx, |
195 | uint id, |
196 | const char *func_name, |
197 | const char *file_name, |
198 | ulong line_no, |
199 | size_t size, |
200 | myf my_flags |
201 | ) { |
202 | uchar *ptr; |
203 | DBUG_ENTER("spider_alloc_mem" ); |
204 | size += ALIGN_SIZE(sizeof(uint)) + ALIGN_SIZE(sizeof(uint)); |
205 | if (!(ptr = (uchar *) my_malloc(size, my_flags))) |
206 | DBUG_RETURN(NULL); |
207 | |
208 | spider_alloc_mem_calc(trx, id, func_name, file_name, line_no, size); |
209 | *((uint *) ptr) = id; |
210 | ptr += ALIGN_SIZE(sizeof(uint)); |
211 | *((uint *) ptr) = size; |
212 | ptr += ALIGN_SIZE(sizeof(uint)); |
213 | DBUG_RETURN(ptr); |
214 | } |
215 | |
216 | void *spider_bulk_alloc_mem( |
217 | SPIDER_TRX *trx, |
218 | uint id, |
219 | const char *func_name, |
220 | const char *file_name, |
221 | ulong line_no, |
222 | myf my_flags, |
223 | ... |
224 | ) { |
225 | uchar **tmp_ptr, *top_ptr, *current_ptr; |
226 | uint total_size; |
227 | va_list args; |
228 | DBUG_ENTER("spider_bulk_alloc_mem" ); |
229 | total_size = ALIGN_SIZE(sizeof(uint)) + ALIGN_SIZE(sizeof(uint)); |
230 | va_start(args, my_flags); |
231 | while (va_arg(args, char **)) |
232 | total_size += ALIGN_SIZE(va_arg(args, uint)); |
233 | va_end(args); |
234 | |
235 | if (!(top_ptr = (uchar *) my_malloc(total_size, my_flags))) |
236 | DBUG_RETURN(NULL); |
237 | |
238 | spider_alloc_mem_calc(trx, id, func_name, file_name, line_no, total_size); |
239 | *((uint *) top_ptr) = id; |
240 | top_ptr += ALIGN_SIZE(sizeof(uint)); |
241 | *((uint *) top_ptr) = total_size; |
242 | top_ptr += ALIGN_SIZE(sizeof(uint)); |
243 | |
244 | current_ptr = top_ptr; |
245 | va_start(args, my_flags); |
246 | while ((tmp_ptr = (uchar **) va_arg(args, char **))) |
247 | { |
248 | *tmp_ptr = current_ptr; |
249 | current_ptr += ALIGN_SIZE(va_arg(args, uint)); |
250 | } |
251 | va_end(args); |
252 | DBUG_RETURN((void *) top_ptr); |
253 | } |
254 | |
255 | #define SPIDER_STRING_CALC_MEM \ |
256 | if (mem_calc_inited) \ |
257 | { \ |
258 | uint32 new_alloc_mem = \ |
259 | (this->str.is_alloced() ? this->str.alloced_length() : 0); \ |
260 | if (new_alloc_mem != current_alloc_mem) \ |
261 | { \ |
262 | if (new_alloc_mem > current_alloc_mem) \ |
263 | spider_alloc_mem_calc(spider_current_trx, id, func_name, file_name, \ |
264 | line_no, new_alloc_mem - current_alloc_mem); \ |
265 | else \ |
266 | spider_free_mem_calc(spider_current_trx, id, \ |
267 | current_alloc_mem - new_alloc_mem); \ |
268 | current_alloc_mem = new_alloc_mem; \ |
269 | } \ |
270 | } |
271 | |
272 | spider_string::spider_string( |
273 | ) : str(), next(NULL) |
274 | { |
275 | DBUG_ENTER("spider_string::spider_string" ); |
276 | DBUG_PRINT("info" ,("spider this=%p" , this)); |
277 | mem_calc_inited = FALSE; |
278 | DBUG_VOID_RETURN; |
279 | } |
280 | |
281 | spider_string::spider_string( |
282 | uint32 length_arg |
283 | ) : str(length_arg), next(NULL) |
284 | { |
285 | DBUG_ENTER("spider_string::spider_string" ); |
286 | DBUG_PRINT("info" ,("spider this=%p" , this)); |
287 | mem_calc_inited = FALSE; |
288 | DBUG_VOID_RETURN; |
289 | } |
290 | |
291 | spider_string::spider_string( |
292 | const char *str, |
293 | CHARSET_INFO *cs |
294 | ) : str(str, cs), next(NULL) |
295 | { |
296 | DBUG_ENTER("spider_string::spider_string" ); |
297 | DBUG_PRINT("info" ,("spider this=%p" , this)); |
298 | mem_calc_inited = FALSE; |
299 | DBUG_VOID_RETURN; |
300 | } |
301 | |
302 | spider_string::spider_string( |
303 | const char *str, |
304 | uint32 len, |
305 | CHARSET_INFO *cs |
306 | ) : str(str, len, cs), next(NULL) |
307 | { |
308 | DBUG_ENTER("spider_string::spider_string" ); |
309 | DBUG_PRINT("info" ,("spider this=%p" , this)); |
310 | mem_calc_inited = FALSE; |
311 | DBUG_VOID_RETURN; |
312 | } |
313 | |
314 | spider_string::spider_string( |
315 | char *str, |
316 | uint32 len, |
317 | CHARSET_INFO *cs |
318 | ) : str(str, len, cs), next(NULL) |
319 | { |
320 | DBUG_ENTER("spider_string::spider_string" ); |
321 | DBUG_PRINT("info" ,("spider this=%p" , this)); |
322 | mem_calc_inited = FALSE; |
323 | DBUG_VOID_RETURN; |
324 | } |
325 | |
326 | spider_string::spider_string( |
327 | const String &str |
328 | ) : str(str), next(NULL) |
329 | { |
330 | DBUG_ENTER("spider_string::spider_string" ); |
331 | DBUG_PRINT("info" ,("spider this=%p" , this)); |
332 | mem_calc_inited = FALSE; |
333 | DBUG_VOID_RETURN; |
334 | } |
335 | |
336 | spider_string::~spider_string() |
337 | { |
338 | DBUG_ENTER("spider_string::~spider_string" ); |
339 | DBUG_PRINT("info" ,("spider this=%p" , this)); |
340 | if (mem_calc_inited) |
341 | free(); |
342 | DBUG_VOID_RETURN; |
343 | } |
344 | |
345 | void spider_string::init_mem_calc( |
346 | uint id, |
347 | const char *func_name, |
348 | const char *file_name, |
349 | ulong line_no |
350 | ) { |
351 | DBUG_ENTER("spider_string::init_mem_calc" ); |
352 | DBUG_PRINT("info" ,("spider this=%p" , this)); |
353 | DBUG_ASSERT(!mem_calc_inited); |
354 | this->id = id; |
355 | this->func_name = func_name; |
356 | this->file_name = file_name; |
357 | this->line_no = line_no; |
358 | if (str.is_alloced()) |
359 | { |
360 | current_alloc_mem = str.alloced_length(); |
361 | spider_alloc_mem_calc(spider_current_trx, id, func_name, file_name, |
362 | line_no, current_alloc_mem); |
363 | } else |
364 | current_alloc_mem = 0; |
365 | mem_calc_inited = TRUE; |
366 | DBUG_VOID_RETURN; |
367 | } |
368 | |
369 | void spider_string::mem_calc() |
370 | { |
371 | DBUG_ENTER("spider_string::mem_calc" ); |
372 | DBUG_PRINT("info" ,("spider this=%p" , this)); |
373 | DBUG_ASSERT(mem_calc_inited); |
374 | SPIDER_STRING_CALC_MEM; |
375 | DBUG_VOID_RETURN; |
376 | } |
377 | |
378 | String *spider_string::get_str() |
379 | { |
380 | DBUG_ENTER("spider_string::get_str" ); |
381 | DBUG_PRINT("info" ,("spider this=%p" , this)); |
382 | DBUG_RETURN(&str); |
383 | } |
384 | |
385 | void spider_string::set_charset( |
386 | CHARSET_INFO *charset_arg |
387 | ) { |
388 | DBUG_ENTER("spider_string::set_charset" ); |
389 | DBUG_PRINT("info" ,("spider this=%p" , this)); |
390 | str.set_charset(charset_arg); |
391 | DBUG_VOID_RETURN; |
392 | } |
393 | |
394 | CHARSET_INFO *spider_string::charset() const |
395 | { |
396 | DBUG_ENTER("spider_string::charset" ); |
397 | DBUG_PRINT("info" ,("spider this=%p" , this)); |
398 | DBUG_RETURN(str.charset()); |
399 | } |
400 | |
401 | uint32 spider_string::length() const |
402 | { |
403 | DBUG_ENTER("spider_string::length" ); |
404 | DBUG_PRINT("info" ,("spider this=%p" , this)); |
405 | DBUG_RETURN(str.length()); |
406 | } |
407 | |
408 | uint32 spider_string::alloced_length() const |
409 | { |
410 | DBUG_ENTER("spider_string::alloced_length" ); |
411 | DBUG_PRINT("info" ,("spider this=%p" , this)); |
412 | DBUG_RETURN(str.alloced_length()); |
413 | } |
414 | |
415 | char &spider_string::operator [] (uint32 i) const |
416 | { |
417 | DBUG_ENTER("spider_string::operator []" ); |
418 | DBUG_PRINT("info" ,("spider this=%p" , this)); |
419 | DBUG_RETURN(str[i]); |
420 | } |
421 | |
422 | void spider_string::length( |
423 | uint32 len |
424 | ) { |
425 | DBUG_ENTER("spider_string::length" ); |
426 | DBUG_PRINT("info" ,("spider this=%p" , this)); |
427 | str.length(len); |
428 | DBUG_VOID_RETURN; |
429 | } |
430 | |
431 | bool spider_string::is_empty() const |
432 | { |
433 | DBUG_ENTER("spider_string::is_empty" ); |
434 | DBUG_PRINT("info" ,("spider this=%p" , this)); |
435 | DBUG_RETURN(str.is_empty()); |
436 | } |
437 | |
438 | const char *spider_string::ptr() const |
439 | { |
440 | DBUG_ENTER("spider_string::ptr" ); |
441 | DBUG_PRINT("info" ,("spider this=%p" , this)); |
442 | DBUG_RETURN(str.ptr()); |
443 | } |
444 | |
445 | char *spider_string::c_ptr() |
446 | { |
447 | DBUG_ENTER("spider_string::c_ptr" ); |
448 | DBUG_PRINT("info" ,("spider this=%p" , this)); |
449 | DBUG_ASSERT(mem_calc_inited); |
450 | DBUG_ASSERT((!current_alloc_mem && !str.is_alloced()) || |
451 | current_alloc_mem == str.alloced_length()); |
452 | char *res = str.c_ptr(); |
453 | SPIDER_STRING_CALC_MEM; |
454 | DBUG_RETURN(res); |
455 | } |
456 | |
457 | char *spider_string::c_ptr_quick() |
458 | { |
459 | DBUG_ENTER("spider_string::c_ptr_quick" ); |
460 | DBUG_PRINT("info" ,("spider this=%p" , this)); |
461 | DBUG_RETURN(str.c_ptr_quick()); |
462 | } |
463 | |
464 | char *spider_string::c_ptr_safe() |
465 | { |
466 | DBUG_ENTER("spider_string::c_ptr_safe" ); |
467 | DBUG_PRINT("info" ,("spider this=%p" , this)); |
468 | DBUG_ASSERT(mem_calc_inited); |
469 | DBUG_ASSERT((!current_alloc_mem && !str.is_alloced()) || |
470 | current_alloc_mem == str.alloced_length()); |
471 | char *res = str.c_ptr_safe(); |
472 | SPIDER_STRING_CALC_MEM; |
473 | DBUG_RETURN(res); |
474 | } |
475 | |
476 | LEX_STRING spider_string::lex_string() const |
477 | { |
478 | DBUG_ENTER("spider_string::lex_string" ); |
479 | DBUG_PRINT("info" ,("spider this=%p" , this)); |
480 | DBUG_RETURN(str.lex_string()); |
481 | } |
482 | |
483 | void spider_string::set( |
484 | String &str, |
485 | uint32 offset, |
486 | uint32 arg_length |
487 | ) { |
488 | DBUG_ENTER("spider_string::set" ); |
489 | DBUG_PRINT("info" ,("spider this=%p" , this)); |
490 | DBUG_ASSERT(mem_calc_inited); |
491 | DBUG_ASSERT((!current_alloc_mem && !str.is_alloced()) || |
492 | current_alloc_mem == str.alloced_length()); |
493 | str.set(str, offset, arg_length); |
494 | SPIDER_STRING_CALC_MEM; |
495 | DBUG_VOID_RETURN; |
496 | } |
497 | |
498 | void spider_string::set( |
499 | char *str, |
500 | uint32 arg_length, |
501 | CHARSET_INFO *cs |
502 | ) { |
503 | DBUG_ENTER("spider_string::set" ); |
504 | DBUG_PRINT("info" ,("spider this=%p" , this)); |
505 | DBUG_ASSERT(mem_calc_inited); |
506 | DBUG_ASSERT((!current_alloc_mem && !this->str.is_alloced()) || |
507 | current_alloc_mem == this->str.alloced_length()); |
508 | this->str.set(str, arg_length, cs); |
509 | SPIDER_STRING_CALC_MEM; |
510 | DBUG_VOID_RETURN; |
511 | } |
512 | |
513 | void spider_string::set( |
514 | const char *str, |
515 | uint32 arg_length, |
516 | CHARSET_INFO *cs |
517 | ) { |
518 | DBUG_ENTER("spider_string::set" ); |
519 | DBUG_PRINT("info" ,("spider this=%p" , this)); |
520 | DBUG_ASSERT(mem_calc_inited); |
521 | DBUG_ASSERT((!current_alloc_mem && !this->str.is_alloced()) || |
522 | current_alloc_mem == this->str.alloced_length()); |
523 | this->str.set(str, arg_length, cs); |
524 | SPIDER_STRING_CALC_MEM; |
525 | DBUG_VOID_RETURN; |
526 | } |
527 | |
528 | bool spider_string::set_ascii( |
529 | const char *str, |
530 | uint32 arg_length |
531 | ) { |
532 | DBUG_ENTER("spider_string::set_ascii" ); |
533 | DBUG_PRINT("info" ,("spider this=%p" , this)); |
534 | DBUG_ASSERT(mem_calc_inited); |
535 | DBUG_ASSERT((!current_alloc_mem && !this->str.is_alloced()) || |
536 | current_alloc_mem == this->str.alloced_length()); |
537 | bool res = this->str.set_ascii(str, arg_length); |
538 | SPIDER_STRING_CALC_MEM; |
539 | DBUG_RETURN(res); |
540 | } |
541 | |
542 | void spider_string::set_quick( |
543 | char *str, |
544 | uint32 arg_length, |
545 | CHARSET_INFO *cs |
546 | ) { |
547 | DBUG_ENTER("spider_string::set_quick" ); |
548 | DBUG_PRINT("info" ,("spider this=%p" , this)); |
549 | DBUG_ASSERT(mem_calc_inited); |
550 | DBUG_ASSERT((!current_alloc_mem && !this->str.is_alloced()) || |
551 | current_alloc_mem == this->str.alloced_length()); |
552 | this->str.set_quick(str, arg_length, cs); |
553 | SPIDER_STRING_CALC_MEM; |
554 | DBUG_VOID_RETURN; |
555 | } |
556 | |
557 | bool spider_string::set_int( |
558 | longlong num, |
559 | bool unsigned_flag, |
560 | CHARSET_INFO *cs |
561 | ) { |
562 | DBUG_ENTER("spider_string::set_int" ); |
563 | DBUG_PRINT("info" ,("spider this=%p" , this)); |
564 | DBUG_ASSERT(mem_calc_inited); |
565 | DBUG_ASSERT((!current_alloc_mem && !str.is_alloced()) || |
566 | current_alloc_mem == str.alloced_length()); |
567 | bool res = str.set_int(num, unsigned_flag, cs); |
568 | SPIDER_STRING_CALC_MEM; |
569 | DBUG_RETURN(res); |
570 | } |
571 | |
572 | bool spider_string::set( |
573 | longlong num, |
574 | CHARSET_INFO *cs |
575 | ) { |
576 | DBUG_ENTER("spider_string::set" ); |
577 | DBUG_PRINT("info" ,("spider this=%p" , this)); |
578 | DBUG_ASSERT(mem_calc_inited); |
579 | DBUG_ASSERT((!current_alloc_mem && !str.is_alloced()) || |
580 | current_alloc_mem == str.alloced_length()); |
581 | bool res = str.set(num, cs); |
582 | SPIDER_STRING_CALC_MEM; |
583 | DBUG_RETURN(res); |
584 | } |
585 | |
586 | bool spider_string::set( |
587 | ulonglong num, |
588 | CHARSET_INFO *cs |
589 | ) { |
590 | DBUG_ENTER("spider_string::set" ); |
591 | DBUG_PRINT("info" ,("spider this=%p" , this)); |
592 | DBUG_ASSERT(mem_calc_inited); |
593 | DBUG_ASSERT((!current_alloc_mem && !str.is_alloced()) || |
594 | current_alloc_mem == str.alloced_length()); |
595 | bool res = str.set(num, cs); |
596 | SPIDER_STRING_CALC_MEM; |
597 | DBUG_RETURN(res); |
598 | } |
599 | |
600 | bool spider_string::set_real( |
601 | double num, |
602 | uint decimals, |
603 | CHARSET_INFO *cs |
604 | ) { |
605 | DBUG_ENTER("spider_string::set_real" ); |
606 | DBUG_PRINT("info" ,("spider this=%p" , this)); |
607 | DBUG_ASSERT(mem_calc_inited); |
608 | DBUG_ASSERT((!current_alloc_mem && !str.is_alloced()) || |
609 | current_alloc_mem == str.alloced_length()); |
610 | bool res = str.set_real(num, decimals, cs); |
611 | SPIDER_STRING_CALC_MEM; |
612 | DBUG_RETURN(res); |
613 | } |
614 | |
615 | void spider_string::chop() |
616 | { |
617 | DBUG_ENTER("spider_string::chop" ); |
618 | DBUG_PRINT("info" ,("spider this=%p" , this)); |
619 | str.chop(); |
620 | DBUG_VOID_RETURN; |
621 | } |
622 | |
623 | void spider_string::free() |
624 | { |
625 | DBUG_ENTER("spider_string::free" ); |
626 | DBUG_PRINT("info" ,("spider this=%p" , this)); |
627 | DBUG_ASSERT(mem_calc_inited); |
628 | DBUG_ASSERT((!current_alloc_mem && !str.is_alloced()) || |
629 | current_alloc_mem == str.alloced_length()); |
630 | str.free(); |
631 | if (mem_calc_inited && current_alloc_mem) |
632 | { |
633 | spider_free_mem_calc(spider_current_trx, id, current_alloc_mem); |
634 | current_alloc_mem = 0; |
635 | } |
636 | DBUG_VOID_RETURN; |
637 | } |
638 | |
639 | bool spider_string::alloc(uint32 arg_length) |
640 | { |
641 | bool res; |
642 | DBUG_ENTER("spider_string::alloc" ); |
643 | DBUG_PRINT("info" ,("spider this=%p" , this)); |
644 | DBUG_ASSERT(mem_calc_inited); |
645 | DBUG_ASSERT((!current_alloc_mem && !str.is_alloced()) || |
646 | current_alloc_mem == str.alloced_length()); |
647 | res = str.alloc(arg_length); |
648 | SPIDER_STRING_CALC_MEM; |
649 | DBUG_RETURN(res); |
650 | } |
651 | |
652 | bool spider_string::real_alloc(uint32 arg_length) |
653 | { |
654 | bool res; |
655 | DBUG_ENTER("spider_string::real_alloc" ); |
656 | DBUG_PRINT("info" ,("spider this=%p" , this)); |
657 | DBUG_ASSERT(mem_calc_inited); |
658 | res = str.real_alloc(arg_length); |
659 | /* |
660 | if (mem_calc_inited && !res && arg_length) |
661 | */ |
662 | if (mem_calc_inited && !res) |
663 | { |
664 | DBUG_ASSERT(!current_alloc_mem); |
665 | spider_alloc_mem_calc(spider_current_trx, id, func_name, file_name, |
666 | line_no, str.alloced_length()); |
667 | current_alloc_mem = str.alloced_length(); |
668 | } |
669 | DBUG_RETURN(res); |
670 | } |
671 | |
672 | bool spider_string::realloc(uint32 arg_length) |
673 | { |
674 | bool res; |
675 | DBUG_ENTER("spider_string::realloc" ); |
676 | DBUG_PRINT("info" ,("spider this=%p" , this)); |
677 | DBUG_ASSERT(mem_calc_inited); |
678 | DBUG_ASSERT((!current_alloc_mem && !str.is_alloced()) || |
679 | current_alloc_mem == str.alloced_length()); |
680 | res = str.realloc(arg_length); |
681 | if (mem_calc_inited && !res && current_alloc_mem < str.alloced_length()) |
682 | { |
683 | spider_alloc_mem_calc(spider_current_trx, id, func_name, file_name, |
684 | line_no, str.alloced_length() - current_alloc_mem); |
685 | current_alloc_mem = str.alloced_length(); |
686 | } |
687 | DBUG_RETURN(res); |
688 | } |
689 | |
690 | void spider_string::shrink( |
691 | uint32 arg_length |
692 | ) { |
693 | DBUG_ENTER("spider_string::shrink" ); |
694 | DBUG_PRINT("info" ,("spider this=%p" , this)); |
695 | DBUG_ASSERT(mem_calc_inited); |
696 | DBUG_ASSERT((!current_alloc_mem && !str.is_alloced()) || |
697 | current_alloc_mem == str.alloced_length()); |
698 | str.shrink(arg_length); |
699 | SPIDER_STRING_CALC_MEM; |
700 | DBUG_VOID_RETURN; |
701 | } |
702 | |
703 | bool spider_string::is_alloced() |
704 | { |
705 | DBUG_ENTER("spider_string::is_alloced" ); |
706 | DBUG_PRINT("info" ,("spider this=%p" , this)); |
707 | DBUG_RETURN(str.is_alloced()); |
708 | } |
709 | |
710 | spider_string &spider_string::operator = ( |
711 | const String &s |
712 | ) { |
713 | DBUG_ENTER("spider_string::operator =" ); |
714 | DBUG_PRINT("info" ,("spider this=%p" , this)); |
715 | DBUG_ASSERT(mem_calc_inited); |
716 | DBUG_ASSERT((!current_alloc_mem && !str.is_alloced()) || |
717 | current_alloc_mem == str.alloced_length()); |
718 | str = s; |
719 | SPIDER_STRING_CALC_MEM; |
720 | DBUG_RETURN(*this); |
721 | } |
722 | |
723 | bool spider_string::copy() |
724 | { |
725 | DBUG_ENTER("spider_string::copy" ); |
726 | DBUG_PRINT("info" ,("spider this=%p" , this)); |
727 | DBUG_ASSERT(mem_calc_inited); |
728 | DBUG_ASSERT((!current_alloc_mem && !str.is_alloced()) || |
729 | current_alloc_mem == str.alloced_length()); |
730 | bool res = str.copy(); |
731 | SPIDER_STRING_CALC_MEM; |
732 | DBUG_RETURN(res); |
733 | } |
734 | |
735 | bool spider_string::copy( |
736 | const spider_string &s |
737 | ) { |
738 | DBUG_ENTER("spider_string::copy" ); |
739 | DBUG_PRINT("info" ,("spider this=%p" , this)); |
740 | DBUG_ASSERT(mem_calc_inited); |
741 | DBUG_ASSERT((!current_alloc_mem && !str.is_alloced()) || |
742 | current_alloc_mem == str.alloced_length()); |
743 | bool res = str.copy(s.str); |
744 | SPIDER_STRING_CALC_MEM; |
745 | DBUG_RETURN(res); |
746 | } |
747 | |
748 | bool spider_string::copy( |
749 | const String &s |
750 | ) { |
751 | DBUG_ENTER("spider_string::copy" ); |
752 | DBUG_PRINT("info" ,("spider this=%p" , this)); |
753 | DBUG_ASSERT(mem_calc_inited); |
754 | DBUG_ASSERT((!current_alloc_mem && !str.is_alloced()) || |
755 | current_alloc_mem == str.alloced_length()); |
756 | bool res = str.copy(s); |
757 | SPIDER_STRING_CALC_MEM; |
758 | DBUG_RETURN(res); |
759 | } |
760 | |
761 | bool spider_string::copy( |
762 | const char *s, |
763 | uint32 arg_length, |
764 | CHARSET_INFO *cs |
765 | ) { |
766 | DBUG_ENTER("spider_string::copy" ); |
767 | DBUG_PRINT("info" ,("spider this=%p" , this)); |
768 | DBUG_ASSERT(mem_calc_inited); |
769 | DBUG_ASSERT((!current_alloc_mem && !str.is_alloced()) || |
770 | current_alloc_mem == str.alloced_length()); |
771 | bool res = str.copy(s, arg_length, cs); |
772 | SPIDER_STRING_CALC_MEM; |
773 | DBUG_RETURN(res); |
774 | } |
775 | |
776 | bool spider_string::needs_conversion( |
777 | uint32 arg_length, |
778 | CHARSET_INFO *cs_from, |
779 | CHARSET_INFO *cs_to, |
780 | uint32 *offset |
781 | ) { |
782 | DBUG_ENTER("spider_string::needs_conversion" ); |
783 | DBUG_PRINT("info" ,("spider this=%p" , this)); |
784 | DBUG_RETURN(str.needs_conversion(arg_length, cs_from, cs_to, offset)); |
785 | } |
786 | |
787 | bool spider_string::copy_aligned( |
788 | const char *s, |
789 | uint32 arg_length, |
790 | uint32 offset, |
791 | CHARSET_INFO *cs |
792 | ) { |
793 | DBUG_ENTER("spider_string::copy_aligned" ); |
794 | DBUG_PRINT("info" ,("spider this=%p" , this)); |
795 | DBUG_ASSERT(mem_calc_inited); |
796 | DBUG_ASSERT((!current_alloc_mem && !str.is_alloced()) || |
797 | current_alloc_mem == str.alloced_length()); |
798 | bool res = str.copy_aligned(s, arg_length, offset, cs); |
799 | SPIDER_STRING_CALC_MEM; |
800 | DBUG_RETURN(res); |
801 | } |
802 | |
803 | bool spider_string::set_or_copy_aligned( |
804 | const char *s, |
805 | uint32 arg_length, |
806 | CHARSET_INFO *cs |
807 | ) { |
808 | DBUG_ENTER("spider_string::set_or_copy_aligned" ); |
809 | DBUG_PRINT("info" ,("spider this=%p" , this)); |
810 | DBUG_ASSERT(mem_calc_inited); |
811 | DBUG_ASSERT((!current_alloc_mem && !str.is_alloced()) || |
812 | current_alloc_mem == str.alloced_length()); |
813 | bool res = str.set_or_copy_aligned(s, arg_length, cs); |
814 | SPIDER_STRING_CALC_MEM; |
815 | DBUG_RETURN(res); |
816 | } |
817 | |
818 | bool spider_string::copy( |
819 | const char *s, |
820 | uint32 arg_length, |
821 | CHARSET_INFO *csfrom, |
822 | CHARSET_INFO *csto, |
823 | uint *errors |
824 | ) { |
825 | DBUG_ENTER("spider_string::copy" ); |
826 | DBUG_PRINT("info" ,("spider this=%p" , this)); |
827 | DBUG_ASSERT(mem_calc_inited); |
828 | DBUG_ASSERT((!current_alloc_mem && !str.is_alloced()) || |
829 | current_alloc_mem == str.alloced_length()); |
830 | bool res = str.copy(s, arg_length, csfrom, csto, errors); |
831 | SPIDER_STRING_CALC_MEM; |
832 | DBUG_RETURN(res); |
833 | } |
834 | |
835 | bool spider_string::append( |
836 | const spider_string &s |
837 | ) { |
838 | DBUG_ENTER("spider_string::append" ); |
839 | DBUG_PRINT("info" ,("spider this=%p" , this)); |
840 | DBUG_ASSERT(mem_calc_inited); |
841 | DBUG_ASSERT((!current_alloc_mem && !str.is_alloced()) || |
842 | current_alloc_mem == str.alloced_length()); |
843 | bool res = str.append(s.str); |
844 | SPIDER_STRING_CALC_MEM; |
845 | DBUG_RETURN(res); |
846 | } |
847 | |
848 | bool spider_string::append( |
849 | const String &s |
850 | ) { |
851 | DBUG_ENTER("spider_string::append" ); |
852 | DBUG_PRINT("info" ,("spider this=%p" , this)); |
853 | DBUG_ASSERT(mem_calc_inited); |
854 | DBUG_ASSERT((!current_alloc_mem && !str.is_alloced()) || |
855 | current_alloc_mem == str.alloced_length()); |
856 | bool res = str.append(s); |
857 | SPIDER_STRING_CALC_MEM; |
858 | DBUG_RETURN(res); |
859 | } |
860 | |
861 | bool spider_string::append( |
862 | const char *s |
863 | ) { |
864 | DBUG_ENTER("spider_string::append" ); |
865 | DBUG_PRINT("info" ,("spider this=%p" , this)); |
866 | DBUG_ASSERT(mem_calc_inited); |
867 | DBUG_ASSERT((!current_alloc_mem && !str.is_alloced()) || |
868 | current_alloc_mem == str.alloced_length()); |
869 | bool res = str.append(s); |
870 | SPIDER_STRING_CALC_MEM; |
871 | DBUG_RETURN(res); |
872 | } |
873 | |
874 | bool spider_string::append( |
875 | LEX_STRING *ls |
876 | ) { |
877 | DBUG_ENTER("spider_string::append" ); |
878 | DBUG_PRINT("info" ,("spider this=%p" , this)); |
879 | DBUG_ASSERT(mem_calc_inited); |
880 | DBUG_ASSERT((!current_alloc_mem && !str.is_alloced()) || |
881 | current_alloc_mem == str.alloced_length()); |
882 | bool res = str.append(ls); |
883 | SPIDER_STRING_CALC_MEM; |
884 | DBUG_RETURN(res); |
885 | } |
886 | |
887 | bool spider_string::append( |
888 | const char *s, |
889 | uint32 arg_length |
890 | ) { |
891 | DBUG_ENTER("spider_string::append" ); |
892 | DBUG_PRINT("info" ,("spider this=%p" , this)); |
893 | DBUG_ASSERT(mem_calc_inited); |
894 | DBUG_ASSERT((!current_alloc_mem && !str.is_alloced()) || |
895 | current_alloc_mem == str.alloced_length()); |
896 | bool res = str.append(s, arg_length); |
897 | SPIDER_STRING_CALC_MEM; |
898 | DBUG_RETURN(res); |
899 | } |
900 | |
901 | bool spider_string::append( |
902 | const char *s, |
903 | uint32 arg_length, |
904 | CHARSET_INFO *cs |
905 | ) { |
906 | DBUG_ENTER("spider_string::append" ); |
907 | DBUG_PRINT("info" ,("spider this=%p" , this)); |
908 | DBUG_ASSERT(mem_calc_inited); |
909 | DBUG_ASSERT((!current_alloc_mem && !str.is_alloced()) || |
910 | current_alloc_mem == str.alloced_length()); |
911 | bool res = str.append(s, arg_length, cs); |
912 | SPIDER_STRING_CALC_MEM; |
913 | DBUG_RETURN(res); |
914 | } |
915 | |
916 | bool spider_string::append_ulonglong( |
917 | ulonglong val |
918 | ) { |
919 | DBUG_ENTER("spider_string::append_ulonglong" ); |
920 | DBUG_PRINT("info" ,("spider this=%p" , this)); |
921 | DBUG_ASSERT(mem_calc_inited); |
922 | DBUG_ASSERT((!current_alloc_mem && !str.is_alloced()) || |
923 | current_alloc_mem == str.alloced_length()); |
924 | bool res = str.append_ulonglong(val); |
925 | SPIDER_STRING_CALC_MEM; |
926 | DBUG_RETURN(res); |
927 | } |
928 | |
929 | bool spider_string::append( |
930 | IO_CACHE *file, |
931 | uint32 arg_length |
932 | ) { |
933 | DBUG_ENTER("spider_string::append" ); |
934 | DBUG_PRINT("info" ,("spider this=%p" , this)); |
935 | DBUG_ASSERT(mem_calc_inited); |
936 | DBUG_ASSERT((!current_alloc_mem && !str.is_alloced()) || |
937 | current_alloc_mem == str.alloced_length()); |
938 | bool res = str.append(file, arg_length); |
939 | SPIDER_STRING_CALC_MEM; |
940 | DBUG_RETURN(res); |
941 | } |
942 | |
943 | bool spider_string::append_with_prefill( |
944 | const char *s, |
945 | uint32 arg_length, |
946 | uint32 full_length, |
947 | char fill_char |
948 | ) { |
949 | DBUG_ENTER("spider_string::append_with_prefill" ); |
950 | DBUG_PRINT("info" ,("spider this=%p" , this)); |
951 | DBUG_ASSERT(mem_calc_inited); |
952 | DBUG_ASSERT((!current_alloc_mem && !str.is_alloced()) || |
953 | current_alloc_mem == str.alloced_length()); |
954 | bool res = str.append_with_prefill(s, arg_length, full_length, |
955 | fill_char); |
956 | SPIDER_STRING_CALC_MEM; |
957 | DBUG_RETURN(res); |
958 | } |
959 | |
960 | int spider_string::strstr( |
961 | const String &search, |
962 | uint32 offset |
963 | ) { |
964 | DBUG_ENTER("spider_string::strstr" ); |
965 | DBUG_PRINT("info" ,("spider this=%p" , this)); |
966 | DBUG_RETURN(str.strstr(search, offset)); |
967 | } |
968 | |
969 | int spider_string::strrstr( |
970 | const String &search, |
971 | uint32 offset |
972 | ) { |
973 | DBUG_ENTER("spider_string::strrstr" ); |
974 | DBUG_PRINT("info" ,("spider this=%p" , this)); |
975 | DBUG_RETURN(str.strrstr(search, offset)); |
976 | } |
977 | |
978 | bool spider_string::replace( |
979 | uint32 offset, |
980 | uint32 arg_length, |
981 | const char *to, |
982 | uint32 length |
983 | ) { |
984 | DBUG_ENTER("spider_string::replace" ); |
985 | DBUG_PRINT("info" ,("spider this=%p" , this)); |
986 | DBUG_ASSERT(mem_calc_inited); |
987 | DBUG_ASSERT((!current_alloc_mem && !str.is_alloced()) || |
988 | current_alloc_mem == str.alloced_length()); |
989 | bool res = str.replace(offset, arg_length, to, length); |
990 | SPIDER_STRING_CALC_MEM; |
991 | DBUG_RETURN(res); |
992 | } |
993 | |
994 | bool spider_string::replace( |
995 | uint32 offset, |
996 | uint32 arg_length, |
997 | const String &to |
998 | ) { |
999 | DBUG_ENTER("spider_string::replace" ); |
1000 | DBUG_PRINT("info" ,("spider this=%p" , this)); |
1001 | DBUG_ASSERT(mem_calc_inited); |
1002 | DBUG_ASSERT((!current_alloc_mem && !str.is_alloced()) || |
1003 | current_alloc_mem == str.alloced_length()); |
1004 | bool res = str.replace(offset, arg_length, to); |
1005 | SPIDER_STRING_CALC_MEM; |
1006 | DBUG_RETURN(res); |
1007 | } |
1008 | |
1009 | bool spider_string::append( |
1010 | char chr |
1011 | ) { |
1012 | DBUG_ENTER("spider_string::append" ); |
1013 | DBUG_PRINT("info" ,("spider this=%p" , this)); |
1014 | DBUG_ASSERT(mem_calc_inited); |
1015 | DBUG_ASSERT((!current_alloc_mem && !str.is_alloced()) || |
1016 | current_alloc_mem == str.alloced_length()); |
1017 | bool res = str.append(chr); |
1018 | SPIDER_STRING_CALC_MEM; |
1019 | DBUG_RETURN(res); |
1020 | } |
1021 | |
1022 | bool spider_string::fill( |
1023 | uint32 max_length, |
1024 | char fill |
1025 | ) { |
1026 | DBUG_ENTER("spider_string::fill" ); |
1027 | DBUG_PRINT("info" ,("spider this=%p" , this)); |
1028 | DBUG_ASSERT(mem_calc_inited); |
1029 | DBUG_ASSERT((!current_alloc_mem && !str.is_alloced()) || |
1030 | current_alloc_mem == str.alloced_length()); |
1031 | bool res = str.fill(max_length, fill); |
1032 | SPIDER_STRING_CALC_MEM; |
1033 | DBUG_RETURN(res); |
1034 | } |
1035 | |
1036 | void spider_string::strip_sp() |
1037 | { |
1038 | DBUG_ENTER("spider_string::strip_sp" ); |
1039 | DBUG_PRINT("info" ,("spider this=%p" , this)); |
1040 | str.strip_sp(); |
1041 | DBUG_VOID_RETURN; |
1042 | } |
1043 | |
1044 | uint32 spider_string::numchars() |
1045 | { |
1046 | DBUG_ENTER("spider_string::numchars" ); |
1047 | DBUG_PRINT("info" ,("spider this=%p" , this)); |
1048 | DBUG_RETURN(str.numchars()); |
1049 | } |
1050 | |
1051 | int spider_string::charpos( |
1052 | int i, |
1053 | uint32 offset |
1054 | ) { |
1055 | DBUG_ENTER("spider_string::charpos" ); |
1056 | DBUG_PRINT("info" ,("spider this=%p" , this)); |
1057 | DBUG_RETURN(str.charpos(i, offset)); |
1058 | } |
1059 | |
1060 | int spider_string::reserve( |
1061 | uint32 space_needed |
1062 | ) { |
1063 | DBUG_ENTER("spider_string::reserve" ); |
1064 | DBUG_PRINT("info" ,("spider this=%p" , this)); |
1065 | DBUG_ASSERT(mem_calc_inited); |
1066 | DBUG_ASSERT((!current_alloc_mem && !str.is_alloced()) || |
1067 | current_alloc_mem == str.alloced_length()); |
1068 | int res = str.reserve(space_needed); |
1069 | SPIDER_STRING_CALC_MEM; |
1070 | DBUG_RETURN(res); |
1071 | } |
1072 | |
1073 | int spider_string::reserve( |
1074 | uint32 space_needed, |
1075 | uint32 grow_by |
1076 | ) { |
1077 | DBUG_ENTER("spider_string::reserve" ); |
1078 | DBUG_PRINT("info" ,("spider this=%p" , this)); |
1079 | DBUG_ASSERT(mem_calc_inited); |
1080 | DBUG_ASSERT((!current_alloc_mem && !str.is_alloced()) || |
1081 | current_alloc_mem == str.alloced_length()); |
1082 | int res = str.reserve(space_needed, grow_by); |
1083 | SPIDER_STRING_CALC_MEM; |
1084 | DBUG_RETURN(res); |
1085 | } |
1086 | |
1087 | void spider_string::q_append( |
1088 | const char c |
1089 | ) { |
1090 | DBUG_ENTER("spider_string::q_append" ); |
1091 | DBUG_PRINT("info" ,("spider this=%p" , this)); |
1092 | str.q_append(c); |
1093 | DBUG_VOID_RETURN; |
1094 | } |
1095 | |
1096 | void spider_string::q_append( |
1097 | const uint32 n |
1098 | ) { |
1099 | DBUG_ENTER("spider_string::q_append" ); |
1100 | DBUG_PRINT("info" ,("spider this=%p" , this)); |
1101 | str.q_append(n); |
1102 | DBUG_VOID_RETURN; |
1103 | } |
1104 | |
1105 | void spider_string::q_append( |
1106 | double d |
1107 | ) { |
1108 | DBUG_ENTER("spider_string::q_append" ); |
1109 | DBUG_PRINT("info" ,("spider this=%p" , this)); |
1110 | str.q_append(d); |
1111 | DBUG_VOID_RETURN; |
1112 | } |
1113 | |
1114 | void spider_string::q_append( |
1115 | double *d |
1116 | ) { |
1117 | DBUG_ENTER("spider_string::q_append" ); |
1118 | DBUG_PRINT("info" ,("spider this=%p" , this)); |
1119 | str.q_append(d); |
1120 | DBUG_VOID_RETURN; |
1121 | } |
1122 | |
1123 | void spider_string::q_append( |
1124 | const char *data, |
1125 | uint32 data_len |
1126 | ) { |
1127 | DBUG_ENTER("spider_string::q_append" ); |
1128 | DBUG_PRINT("info" ,("spider this=%p" , this)); |
1129 | str.q_append(data, data_len); |
1130 | DBUG_VOID_RETURN; |
1131 | } |
1132 | |
1133 | void spider_string::write_at_position( |
1134 | int position, |
1135 | uint32 value |
1136 | ) { |
1137 | DBUG_ENTER("spider_string::write_at_position" ); |
1138 | DBUG_PRINT("info" ,("spider this=%p" , this)); |
1139 | str.write_at_position(position, value); |
1140 | DBUG_VOID_RETURN; |
1141 | } |
1142 | |
1143 | void spider_string::qs_append( |
1144 | const char *str, |
1145 | uint32 len |
1146 | ) { |
1147 | DBUG_ENTER("spider_string::qs_append" ); |
1148 | DBUG_PRINT("info" ,("spider this=%p" , this)); |
1149 | this->str.qs_append(str, len); |
1150 | DBUG_VOID_RETURN; |
1151 | } |
1152 | |
1153 | void spider_string::qs_append( |
1154 | double d |
1155 | ) { |
1156 | DBUG_ENTER("spider_string::qs_append" ); |
1157 | DBUG_PRINT("info" ,("spider this=%p" , this)); |
1158 | str.qs_append(d); |
1159 | DBUG_VOID_RETURN; |
1160 | } |
1161 | |
1162 | void spider_string::qs_append( |
1163 | double *d |
1164 | ) { |
1165 | DBUG_ENTER("spider_string::qs_append" ); |
1166 | DBUG_PRINT("info" ,("spider this=%p" , this)); |
1167 | str.qs_append(d); |
1168 | DBUG_VOID_RETURN; |
1169 | } |
1170 | |
1171 | void spider_string::qs_append( |
1172 | const char c |
1173 | ) { |
1174 | DBUG_ENTER("spider_string::qs_append" ); |
1175 | DBUG_PRINT("info" ,("spider this=%p" , this)); |
1176 | str.qs_append(c); |
1177 | DBUG_VOID_RETURN; |
1178 | } |
1179 | |
1180 | void spider_string::qs_append( |
1181 | int i |
1182 | ) { |
1183 | DBUG_ENTER("spider_string::qs_append" ); |
1184 | DBUG_PRINT("info" ,("spider this=%p" , this)); |
1185 | str.qs_append(i); |
1186 | DBUG_VOID_RETURN; |
1187 | } |
1188 | |
1189 | void spider_string::qs_append( |
1190 | uint i |
1191 | ) { |
1192 | DBUG_ENTER("spider_string::qs_append" ); |
1193 | DBUG_PRINT("info" ,("spider this=%p" , this)); |
1194 | str.qs_append(i); |
1195 | DBUG_VOID_RETURN; |
1196 | } |
1197 | |
1198 | char *spider_string::prep_append( |
1199 | uint32 arg_length, |
1200 | uint32 step_alloc |
1201 | ) { |
1202 | DBUG_ENTER("spider_string::prep_append" ); |
1203 | DBUG_PRINT("info" ,("spider this=%p" , this)); |
1204 | DBUG_ASSERT(mem_calc_inited); |
1205 | DBUG_ASSERT((!current_alloc_mem && !str.is_alloced()) || |
1206 | current_alloc_mem == str.alloced_length()); |
1207 | char *res = str.prep_append(arg_length, step_alloc); |
1208 | SPIDER_STRING_CALC_MEM; |
1209 | DBUG_RETURN(res); |
1210 | } |
1211 | |
1212 | bool spider_string::append( |
1213 | const char *s, |
1214 | uint32 arg_length, |
1215 | uint32 step_alloc |
1216 | ) { |
1217 | DBUG_ENTER("spider_string::append" ); |
1218 | DBUG_PRINT("info" ,("spider this=%p" , this)); |
1219 | DBUG_ASSERT(mem_calc_inited); |
1220 | DBUG_ASSERT((!current_alloc_mem && !str.is_alloced()) || |
1221 | current_alloc_mem == str.alloced_length()); |
1222 | bool res = str.append(s, arg_length, step_alloc); |
1223 | SPIDER_STRING_CALC_MEM; |
1224 | DBUG_RETURN(res); |
1225 | } |
1226 | |
1227 | void spider_string::append_escape_string( |
1228 | const char *st, |
1229 | uint len |
1230 | ) { |
1231 | DBUG_ENTER("spider_string::append_escape_string" ); |
1232 | DBUG_PRINT("info" ,("spider this=%p" , this)); |
1233 | DBUG_ASSERT(mem_calc_inited); |
1234 | DBUG_ASSERT((!current_alloc_mem && !str.is_alloced()) || |
1235 | current_alloc_mem == str.alloced_length()); |
1236 | str.length(str.length() + escape_string_for_mysql( |
1237 | str.charset(), (char *) str.ptr() + str.length(), 0, st, len)); |
1238 | DBUG_VOID_RETURN; |
1239 | } |
1240 | |
1241 | bool spider_string::append_for_single_quote( |
1242 | const char *st, |
1243 | uint len |
1244 | ) { |
1245 | DBUG_ENTER("spider_string::append_for_single_quote" ); |
1246 | DBUG_PRINT("info" ,("spider this=%p" , this)); |
1247 | DBUG_ASSERT(mem_calc_inited); |
1248 | DBUG_ASSERT((!current_alloc_mem && !str.is_alloced()) || |
1249 | current_alloc_mem == str.alloced_length()); |
1250 | #ifdef SPIDER_HAS_APPEND_FOR_SINGLE_QUOTE |
1251 | bool res = str.append_for_single_quote(st, len); |
1252 | #else |
1253 | String ststr(st, len, str.charset()); |
1254 | bool res = append_escaped(&str, &ststr); |
1255 | #endif |
1256 | SPIDER_STRING_CALC_MEM; |
1257 | DBUG_RETURN(res); |
1258 | } |
1259 | |
1260 | bool spider_string::append_for_single_quote( |
1261 | const String *s |
1262 | ) { |
1263 | DBUG_ENTER("spider_string::append_for_single_quote" ); |
1264 | DBUG_PRINT("info" ,("spider this=%p" , this)); |
1265 | DBUG_ASSERT(mem_calc_inited); |
1266 | DBUG_ASSERT((!current_alloc_mem && !str.is_alloced()) || |
1267 | current_alloc_mem == str.alloced_length()); |
1268 | #ifdef SPIDER_HAS_APPEND_FOR_SINGLE_QUOTE |
1269 | bool res = str.append_for_single_quote(s); |
1270 | #else |
1271 | bool res = append_escaped(&str, (String *) s); |
1272 | #endif |
1273 | SPIDER_STRING_CALC_MEM; |
1274 | DBUG_RETURN(res); |
1275 | } |
1276 | |
1277 | bool spider_string::append_for_single_quote( |
1278 | const char *st |
1279 | ) { |
1280 | DBUG_ENTER("spider_string::append_for_single_quote" ); |
1281 | DBUG_PRINT("info" ,("spider this=%p" , this)); |
1282 | DBUG_ASSERT(mem_calc_inited); |
1283 | DBUG_ASSERT((!current_alloc_mem && !str.is_alloced()) || |
1284 | current_alloc_mem == str.alloced_length()); |
1285 | #ifdef SPIDER_HAS_APPEND_FOR_SINGLE_QUOTE |
1286 | bool res = str.append_for_single_quote(st); |
1287 | #else |
1288 | String ststr(st, str.charset()); |
1289 | bool res = append_escaped(&str, &ststr); |
1290 | #endif |
1291 | SPIDER_STRING_CALC_MEM; |
1292 | DBUG_RETURN(res); |
1293 | } |
1294 | |
1295 | void spider_string::swap( |
1296 | spider_string &s |
1297 | ) { |
1298 | DBUG_ENTER("spider_string::swap" ); |
1299 | DBUG_PRINT("info" ,("spider this=%p" , this)); |
1300 | DBUG_ASSERT(mem_calc_inited); |
1301 | DBUG_ASSERT((!current_alloc_mem && !str.is_alloced()) || |
1302 | current_alloc_mem == str.alloced_length()); |
1303 | str.swap(s.str); |
1304 | SPIDER_STRING_CALC_MEM; |
1305 | DBUG_VOID_RETURN; |
1306 | } |
1307 | |
1308 | bool spider_string::uses_buffer_owned_by( |
1309 | const String *s |
1310 | ) const |
1311 | { |
1312 | DBUG_ENTER("spider_string::uses_buffer_owned_by" ); |
1313 | DBUG_PRINT("info" ,("spider this=%p" , this)); |
1314 | DBUG_RETURN(str.uses_buffer_owned_by(s)); |
1315 | } |
1316 | |
1317 | bool spider_string::is_ascii() const |
1318 | { |
1319 | DBUG_ENTER("spider_string::is_ascii" ); |
1320 | DBUG_PRINT("info" ,("spider this=%p" , this)); |
1321 | DBUG_RETURN(str.is_ascii()); |
1322 | } |
1323 | |