~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to mysys/my_alloc.c

  • Committer: Brian Aker
  • Date: 2008-10-06 06:47:29 UTC
  • Revision ID: brian@tangent.org-20081006064729-2i9mhjkzyvow9xsm
RemoveĀ uint.

Show diffs side-by-side

added added

removed removed

Lines of Context:
15
15
 
16
16
/* Routines to handle mallocing of results which will be freed the same time */
17
17
 
18
 
#include <my_global.h>
 
18
#include <mystrings/m_string.h>
19
19
#include <my_sys.h>
20
 
#include <m_string.h>
21
20
#undef EXTRA_DEBUG
22
21
#define EXTRA_DEBUG
23
22
 
117
116
        {
118
117
          /* remove block from the list and free it */
119
118
          *prev= mem->next;
120
 
          my_free(mem, MYF(0));
 
119
          free(mem);
121
120
        }
122
121
        else
123
122
          prev= &mem->next;
154
153
  {
155
154
    if (mem_root->error_handler)
156
155
      (*mem_root->error_handler)();
157
 
    return((uchar*) 0);                 /* purecov: inspected */
 
156
    return((unsigned char*) 0);                 /* purecov: inspected */
158
157
  }
159
158
  next->next= mem_root->used;
160
159
  next->size= length;
161
160
  mem_root->used= next;
162
 
  return((uchar*) (((char*) next)+ALIGN_SIZE(sizeof(USED_MEM))));
 
161
  return((unsigned char*) (((char*) next)+ALIGN_SIZE(sizeof(USED_MEM))));
163
162
#else
164
163
  size_t get_size, block_size;
165
 
  uchar* point;
 
164
  unsigned char* point;
166
165
  register USED_MEM *next= 0;
167
166
  register USED_MEM **prev;
168
167
  assert(alloc_root_inited(mem_root));
187
186
  {                                             /* Time to alloc new block */
188
187
    block_size= mem_root->block_size * (mem_root->block_num >> 2);
189
188
    get_size= length+ALIGN_SIZE(sizeof(USED_MEM));
190
 
    get_size= max(get_size, block_size);
 
189
    get_size= cmax(get_size, block_size);
191
190
 
192
191
    if (!(next = (USED_MEM*) my_malloc(get_size,MYF(MY_WME | ME_FATALERROR))))
193
192
    {
202
201
    *prev=next;
203
202
  }
204
203
 
205
 
  point= (uchar*) ((char*) next+ (next->size-next->left));
 
204
  point= (unsigned char*) ((char*) next+ (next->size-next->left));
206
205
  /*TODO: next part may be unneded due to mem_root->first_block_usage counter*/
207
206
  if ((next->left-= length) < mem_root->min_malloc)
208
207
  {                                             /* Full block */
313
312
 
314
313
  NOTES
315
314
    One can call this function either with root block initialised with
316
 
    init_alloc_root() or with a bzero()-ed block.
 
315
    init_alloc_root() or with a zero:ed block.
317
316
    It's also safe to call this multiple times with the same mem_root.
318
317
*/
319
318
 
333
332
  {
334
333
    old=next; next= next->next ;
335
334
    if (old != root->pre_alloc)
336
 
      my_free(old,MYF(0));
 
335
      free(old);
337
336
  }
338
337
  for (next=root->free ; next ;)
339
338
  {
340
339
    old=next; next= next->next;
341
340
    if (old != root->pre_alloc)
342
 
      my_free(old,MYF(0));
 
341
      free(old);
343
342
  }
344
343
  root->used=root->free=0;
345
344
  if (root->pre_alloc)