~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to mysys/array.cc

  • Committer: Brian Aker
  • Date: 2008-12-09 17:33:02 UTC
  • mfrom: (656.1.54 devel)
  • Revision ID: brian@tangent.org-20081209173302-aptngvc7efxnatnt
Merge from Monty.

Show diffs side-by-side

added added

removed removed

Lines of Context:
36
36
    Static buffers must begin immediately after the array structure.
37
37
 
38
38
  RETURN VALUE
39
 
    true        my_malloc_ci() failed
 
39
    true        malloc() failed
40
40
    false       Ok
41
41
*/
42
42
 
62
62
  array->size_of_element=element_size;
63
63
  if ((array->buffer= (unsigned char*) init_buffer))
64
64
    return(false);
65
 
  if (!(array->buffer=(unsigned char*) my_malloc_ci(element_size*init_alloc,
66
 
                                            MYF(MY_WME))))
 
65
  if (!(array->buffer=(unsigned char*) malloc(element_size*init_alloc)))
67
66
  {
68
67
    array->max_element=0;
69
68
    return(true);
138
137
        In this senerio, the buffer is statically preallocated,
139
138
        so we have to create an all-new malloc since we overflowed
140
139
      */
141
 
      if (!(new_ptr= (char *) my_malloc((array->max_element+
142
 
                                         array->alloc_increment) *
143
 
                                        array->size_of_element,
144
 
                                        MYF(MY_WME))))
 
140
      if (!(new_ptr= (char *) malloc((array->max_element+
 
141
                                     array->alloc_increment) *
 
142
                                     array->size_of_element)))
145
143
        return 0;
146
144
      memcpy(new_ptr, array->buffer,
147
145
             array->elements * array->size_of_element);
148
146
    }
149
 
    else
150
 
    if (!(new_ptr=(char*) my_realloc(array->buffer,(array->max_element+
151
 
                                     array->alloc_increment)*
152
 
                                     array->size_of_element,
153
 
                                     MYF(MY_WME | MY_ALLOW_ZERO_PTR))))
 
147
    else if (!(new_ptr= (char*) realloc(array->buffer,
 
148
                                        (array->max_element+
 
149
                                         array->alloc_increment)*
 
150
                                        array->size_of_element)))
154
151
      return 0;
155
152
    array->buffer= (unsigned char*) new_ptr;
156
153
    array->max_element+=array->alloc_increment;
242
239
         In this senerio, the buffer is statically preallocated,
243
240
         so we have to create an all-new malloc since we overflowed
244
241
       */
245
 
       if (!(new_ptr= (unsigned char *) my_malloc(size *
246
 
                                         array->size_of_element,
247
 
                                         MYF(MY_WME))))
 
242
       if (!(new_ptr= (unsigned char *) malloc(size *
 
243
                                               array->size_of_element)))
248
244
         return 0;
249
245
       memcpy(new_ptr, array->buffer,
250
246
              array->elements * array->size_of_element);
252
248
     else
253
249
 
254
250
 
255
 
    if (!(new_ptr= (unsigned char*) my_realloc(array->buffer,size*
256
 
                                       array->size_of_element,
257
 
                                       MYF(MY_WME | MY_ALLOW_ZERO_PTR))))
 
251
    if (!(new_ptr=(unsigned char*) realloc(array->buffer,
 
252
                                        size* array->size_of_element)))
258
253
      return true;
259
254
    array->buffer= new_ptr;
260
255
    array->max_element= size;
348
343
 
349
344
  if (array->buffer && array->max_element != elements)
350
345
  {
351
 
    array->buffer=(unsigned char*) my_realloc(array->buffer,
352
 
                                     elements*array->size_of_element,
353
 
                                     MYF(MY_WME));
 
346
    array->buffer=(unsigned char*) realloc(array->buffer,
 
347
                                     elements*array->size_of_element);
354
348
    array->max_element=elements;
355
349
  }
356
350
}