100
/**************************************************************************
101
Duplicates a NUL-terminated string, allocated from a memory heap. */
101
/**********************************************************************//**
102
Duplicates a NUL-terminated string, allocated from a memory heap.
103
@return own: a copy of the string */
106
/* out, own: a copy of the string */
107
mem_heap_t* heap, /* in: memory heap where string is allocated */
108
const char* str) /* in: string to be copied */
108
mem_heap_t* heap, /*!< in: memory heap where string is allocated */
109
const char* str) /*!< in: string to be copied */
110
111
return(mem_heap_dup(heap, str, strlen(str) + 1));
113
/**************************************************************************
114
Duplicate a block of data, allocated from a memory heap. */
114
/**********************************************************************//**
115
Duplicate a block of data, allocated from a memory heap.
116
@return own: a copy of the data */
119
/* out, own: a copy of the data */
120
mem_heap_t* heap, /* in: memory heap where copy is allocated */
121
const void* data, /* in: data to be copied */
122
ulint len) /* in: length of data, in bytes */
121
mem_heap_t* heap, /*!< in: memory heap where copy is allocated */
122
const void* data, /*!< in: data to be copied */
123
ulint len) /*!< in: length of data, in bytes */
124
125
return(memcpy(mem_heap_alloc(heap, len), data, len));
127
/**************************************************************************
128
Concatenate two memory blocks and return the result, using a memory heap. */
133
/* out, own: the result */
134
mem_heap_t* heap, /* in: memory heap where result is allocated */
135
const void* b1, /* in: block 1 */
136
ulint len1, /* in: length of b1, in bytes */
137
const void* b2, /* in: block 2 */
138
ulint len2) /* in: length of b2, in bytes */
140
void* res = mem_heap_alloc(heap, len1 + len2);
142
memcpy(res, b1, len1);
143
memcpy((char*)res + len1, b2, len2);
148
/**************************************************************************
149
Concatenate two strings and return the result, using a memory heap. */
128
/**********************************************************************//**
129
Concatenate two strings and return the result, using a memory heap.
130
@return own: the result */
154
/* out, own: the result */
155
mem_heap_t* heap, /* in: memory heap where string is allocated */
156
const char* s1, /* in: string 1 */
157
const char* s2) /* in: string 2 */
135
mem_heap_t* heap, /*!< in: memory heap where string is allocated */
136
const char* s1, /*!< in: string 1 */
137
const char* s2) /*!< in: string 2 */
160
140
ulint s1_len = strlen(s1);
174
/********************************************************************
175
Helper function for mem_heap_printf. */
154
/****************************************************************//**
155
Helper function for mem_heap_printf.
156
@return length of formatted string, including terminating NUL */
178
159
mem_heap_printf_low(
179
160
/*================*/
180
/* out: length of formatted string,
181
including terminating NUL */
182
char* buf, /* in/out: buffer to store formatted string
161
char* buf, /*!< in/out: buffer to store formatted string
183
162
in, or NULL to just calculate length */
184
const char* format, /* in: format string */
185
va_list ap) /* in: arguments */
163
const char* format, /*!< in: format string */
164
va_list ap) /*!< in: arguments */
284
/********************************************************************
263
/****************************************************************//**
285
264
A simple (s)printf replacement that dynamically allocates the space for the
286
265
formatted string from the given heap. This supports a very limited set of
287
266
the printf syntax: types 's' and 'u' and length modifier 'l' (which is
288
required for the 'u' type). */
267
required for the 'u' type).
268
@return heap-allocated formatted string */
293
/* out: heap-allocated formatted string */
294
mem_heap_t* heap, /* in: memory heap */
295
const char* format, /* in: format string */
273
mem_heap_t* heap, /*!< in: memory heap */
274
const char* format, /*!< in: format string */
317
/*******************************************************************
318
Creates a memory heap block where data can be allocated. */
296
/***************************************************************//**
297
Creates a memory heap block where data can be allocated.
298
@return own: memory heap block, NULL if did not succeed (only possible
299
for MEM_HEAP_BTR_SEARCH type heaps) */
321
302
mem_heap_create_block(
322
303
/*==================*/
323
/* out, own: memory heap block, NULL if
324
did not succeed (only possible for
325
MEM_HEAP_BTR_SEARCH type heaps) */
326
mem_heap_t* heap, /* in: memory heap or NULL if first block
304
mem_heap_t* heap, /*!< in: memory heap or NULL if first block
327
305
should be created */
328
ulint n, /* in: number of bytes needed for user data */
329
ulint type, /* in: type of heap: MEM_HEAP_DYNAMIC or
306
ulint n, /*!< in: number of bytes needed for user data */
307
ulint type, /*!< in: type of heap: MEM_HEAP_DYNAMIC or
330
308
MEM_HEAP_BUFFER */
331
const char* file_name,/* in: file name where created */
332
ulint line) /* in: line where created */
309
const char* file_name,/*!< in: file name where created */
310
ulint line) /*!< in: line where created */
312
#ifndef UNIV_HOTBACKUP
334
313
buf_block_t* buf_block = NULL;
314
#endif /* !UNIV_HOTBACKUP */
335
315
mem_block_t* block;
395
383
mem_block_set_free(block, MEM_BLOCK_HEADER_SIZE);
396
384
mem_block_set_start(block, MEM_BLOCK_HEADER_SIZE);
398
block->free_block = NULL;
400
386
ut_ad((ulint)MEM_BLOCK_HEADER_SIZE < len);
405
/*******************************************************************
406
Adds a new block to a memory heap. */
391
/***************************************************************//**
392
Adds a new block to a memory heap.
393
@return created block, NULL if did not succeed (only possible for
394
MEM_HEAP_BTR_SEARCH type heaps) */
409
397
mem_heap_add_block(
410
398
/*===============*/
411
/* out: created block, NULL if did not
412
succeed (only possible for
413
MEM_HEAP_BTR_SEARCH type heaps)*/
414
mem_heap_t* heap, /* in: memory heap */
415
ulint n) /* in: number of bytes user needs */
399
mem_heap_t* heap, /*!< in: memory heap */
400
ulint n) /*!< in: number of bytes user needs */
417
402
mem_block_t* block;
418
403
mem_block_t* new_block;
458
443
return(new_block);
461
/**********************************************************************
446
/******************************************************************//**
462
447
Frees a block from a memory heap. */
465
450
mem_heap_block_free(
466
451
/*================*/
467
mem_heap_t* heap, /* in: heap */
468
mem_block_t* block) /* in: block to free */
452
mem_heap_t* heap, /*!< in: heap */
453
mem_block_t* block) /*!< in: block to free */
472
buf_block_t* buf_block;
457
#ifndef UNIV_HOTBACKUP
458
buf_block_t* buf_block = block->buf_block;
459
#endif /* !UNIV_HOTBACKUP */
474
461
if (block->magic_n != MEM_BLOCK_MAGIC_N) {
475
462
mem_analyze_corruption(block);
508
495
buf_block_free(buf_block);
497
#else /* !UNIV_HOTBACKUP */
499
#endif /* !UNIV_HOTBACKUP */
512
/**********************************************************************
502
#ifndef UNIV_HOTBACKUP
503
/******************************************************************//**
513
504
Frees the free_block field from a memory heap. */
516
507
mem_heap_free_block_free(
517
508
/*=====================*/
518
mem_heap_t* heap) /* in: heap */
509
mem_heap_t* heap) /*!< in: heap */
520
511
if (UNIV_LIKELY_NULL(heap->free_block)) {