~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to client/drizzletest.cc

  • Committer: Monty Taylor
  • Date: 2008-12-06 07:22:02 UTC
  • mto: (656.1.7 devel) (660.1.5 codestyle)
  • mto: This revision was merged to the branch mainline in revision 665.
  • Revision ID: monty@inaugust.com-20081206072202-2g25o9doqr1l8euu
OOOh doggie. Got rid of my_alloca.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1379
1379
  /* Write ds to temporary file and set file pos to beginning*/
1380
1380
  if (my_write(fd, (unsigned char *) ds->c_str(), ds->length(),
1381
1381
               MYF(MY_FNABP | MY_WME)) ||
1382
 
      lseek(fd, 0, SEEK_SET) == MY_FILEPOS_ERROR)
 
1382
      my_seek(fd, 0, SEEK_SET, MYF(0)) == MY_FILEPOS_ERROR)
1383
1383
  {
1384
1384
    my_close(fd, MYF(0));
1385
1385
    /* Remove the temporary file */
1556
1556
  if (!val_len && val)
1557
1557
    val_len = strlen(val) ;
1558
1558
  val_alloc_len = val_len + 16; /* room to grow */
1559
 
  if (!(tmp_var=v) && !(tmp_var = (VAR*)malloc(sizeof(*tmp_var)
1560
 
                                               + name_len+1)))
 
1559
  if (!(tmp_var=v) && !(tmp_var = (VAR*)my_malloc(sizeof(*tmp_var)
 
1560
                                                  + name_len+1, MYF(MY_WME))))
1561
1561
    die("Out of memory");
1562
1562
 
1563
1563
  tmp_var->name = (name) ? (char*) tmp_var + sizeof(*tmp_var) : 0;
1564
1564
  tmp_var->alloced = (v == 0);
1565
1565
 
1566
 
  if (!(tmp_var->str_val = (char *)malloc(val_alloc_len+1)))
 
1566
  if (!(tmp_var->str_val = (char *)my_malloc(val_alloc_len+1, MYF(MY_WME))))
1567
1567
    die("Out of memory");
1568
1568
 
1569
1569
  memcpy(tmp_var->name, name, name_len);
1710
1710
    snprintf(buf, sizeof(buf), "%.*s=%.*s",
1711
1711
             v->name_len, v->name,
1712
1712
             v->str_val_len, v->str_val);
1713
 
    if (!(v->env_s= strdup(buf)))
 
1713
    if (!(v->env_s= my_strdup(buf, MYF(MY_WME))))
1714
1714
      die("Out of memory");
1715
1715
    putenv(v->env_s);
1716
1716
    free(old_env_s);
1955
1955
  dest->int_dirty= src->int_dirty;
1956
1956
 
1957
1957
  /* Alloc/realloc data for str_val in dest */
1958
 
  if (dest->alloced_len < src->alloced_len)
1959
 
  {
1960
 
    char *tmpptr= (char *)realloc(dest->str_val, src->alloced_len);
1961
 
    if (tmpptr == NULL)
1962
 
      die("Out of memory");
1963
 
    dest->str_val= tmpptr;
1964
 
  }
 
1958
  if (dest->alloced_len < src->alloced_len &&
 
1959
      !(dest->str_val= dest->str_val
 
1960
        ? (char *)my_realloc(dest->str_val, src->alloced_len, MYF(MY_WME))
 
1961
        : (char *)my_malloc(src->alloced_len, MYF(MY_WME))))
 
1962
    die("Out of memory");
1965
1963
  else
1966
1964
    dest->alloced_len= src->alloced_len;
1967
1965
 
2013
2011
      static int MIN_VAR_ALLOC= 32;
2014
2012
      v->alloced_len = (new_val_len < MIN_VAR_ALLOC - 1) ?
2015
2013
        MIN_VAR_ALLOC : new_val_len + 1;
2016
 
      char *tmpptr= (char *)realloc(v->str_val, v->alloced_len+1);
2017
 
      if (tmpptr == NULL)
 
2014
      if (!(v->str_val =
 
2015
            v->str_val ? (char *)my_realloc(v->str_val, v->alloced_len+1,
 
2016
                                            MYF(MY_WME)) :
 
2017
            (char *)my_malloc(v->alloced_len+1, MYF(MY_WME))))
2018
2018
        die("Out of memory");
2019
 
      v->str_val= tmpptr;
2020
2019
    }
2021
2020
    v->str_val_len = new_val_len;
2022
2021
    memcpy(v->str_val, p, new_val_len);
2047
2046
    cur_file--;
2048
2047
    die("Could not open '%s' for reading", buff);
2049
2048
  }
2050
 
  if (!(cur_file->file_name= strdup(buff)))
2051
 
    die("Out of memory");
 
2049
  cur_file->file_name= my_strdup(buff, MYF(MY_FAE));
2052
2050
  cur_file->lineno=1;
2053
2051
  return(0);
2054
2052
}
3083
3081
    die("drizzle_store_result() retuned NULL for '%s'", query);
3084
3082
  if (!(row = drizzle_fetch_row(res)))
3085
3083
    die("empty result in show master status");
3086
 
  strncpy(master_pos.file, row[0], sizeof(master_pos.file)-1);
 
3084
  my_stpncpy(master_pos.file, row[0], sizeof(master_pos.file)-1);
3087
3085
  master_pos.pos = strtoul(row[1], (char**) 0, 10);
3088
3086
  drizzle_free_result(res);
3089
3087
  return(0);
3526
3524
    When the connection is closed set name to "-closed_connection-"
3527
3525
    to make it possible to reuse the connection name.
3528
3526
  */
3529
 
  if (!(con->name = strdup("-closed_connection-")))
 
3527
  if (!(con->name = my_strdup("-closed_connection-", MYF(MY_WME))))
3530
3528
    die("Out of memory");
3531
3529
 
3532
3530
  return;
4369
4367
    return(0);
4370
4368
  }
4371
4369
  if (!(*command_ptr= command=
4372
 
        (struct st_command*) malloc(sizeof(*command))))
 
4370
        (struct st_command*) my_malloc(sizeof(*command),
 
4371
                                       MYF(MY_WME|MY_ZEROFILL))))
4373
4372
    die(NULL);
4374
 
  memset(command, 0, sizeof(*command));
4375
4373
  q_lines.push_back(command);
4376
4374
  command->type= Q_UNKNOWN;
4377
4375
 
4398
4396
  while (*p && my_isspace(charset_info, *p))
4399
4397
    p++;
4400
4398
 
4401
 
  if (!(command->query_buf= command->query= strdup(p)))
 
4399
  if (!(command->query_buf= command->query= my_strdup(p, MYF(MY_WME))))
4402
4400
    die("Out of memory");
4403
4401
 
4404
4402
  /* Calculate first word length(the command), terminated by space or ( */
4544
4542
  {
4545
4543
    *(strchr(str, '\0')-1)=0;        /* Remove end newline */
4546
4544
    if (!(embedded_server_args[embedded_server_arg_count]=
4547
 
          (char*) strdup(str)))
 
4545
          (char*) my_strdup(str,MYF(MY_WME))))
4548
4546
    {
4549
4547
      my_fclose(file,MYF(0));
4550
4548
      die("Out of memory");
4580
4578
    if (!(cur_file->file=
4581
4579
          my_fopen(buff, O_RDONLY, MYF(0))))
4582
4580
      die("Could not open '%s' for reading: errno = %d", buff, errno);
4583
 
    if (!(cur_file->file_name= strdup(buff)))
4584
 
      die("Out of memory");
 
4581
    cur_file->file_name= my_strdup(buff, MYF(MY_FAE));
4585
4582
    cur_file->lineno= 1;
4586
4583
    break;
4587
4584
  }
4601
4598
  case 'p':
4602
4599
    if (argument)
4603
4600
    {
4604
 
      if (opt_pass)
4605
 
        free(opt_pass);
4606
 
      opt_pass = strdup(argument);
4607
 
      if (opt_pass == NULL)
4608
 
        die("Out of memory");
 
4601
      free(opt_pass);
 
4602
      opt_pass= my_strdup(argument, MYF(MY_FAE));
4609
4603
      while (*argument) *argument++= 'x';    /* Destroy argument */
4610
4604
      tty_password= 0;
4611
4605
    }
4613
4607
      tty_password= 1;
4614
4608
    break;
4615
4609
  case 't':
4616
 
    strncpy(TMPDIR, argument, sizeof(TMPDIR));
 
4610
    my_stpncpy(TMPDIR, argument, sizeof(TMPDIR));
4617
4611
    break;
4618
4612
  case 'A':
4619
4613
    if (!embedded_server_arg_count)
4623
4617
    }
4624
4618
    if (embedded_server_arg_count == MAX_EMBEDDED_SERVER_ARGS-1 ||
4625
4619
        !(embedded_server_args[embedded_server_arg_count++]=
4626
 
          strdup(argument)))
 
4620
          my_strdup(argument, MYF(MY_FAE))))
4627
4621
    {
4628
4622
      die("Can't use server argument");
4629
4623
    }
4695
4689
  if ((fd= my_open(buff, flags,
4696
4690
                   MYF(MY_WME | MY_FFNF))) < 0)
4697
4691
    die("Could not open '%s' for writing: errno = %d", buff, errno);
4698
 
  if (append && lseek(fd, 0, SEEK_END) == MY_FILEPOS_ERROR)
 
4692
  if (append && my_seek(fd, 0, SEEK_END, MYF(0)) == MY_FILEPOS_ERROR)
4699
4693
    die("Could not find end of file '%s': errno = %d", buff, errno);
4700
4694
  if (my_write(fd, (unsigned char*)str, size, MYF(MY_WME|MY_FNABP)))
4701
4695
    die("write failed");
5487
5481
  if (cur_file == file_stack && cur_file->file == 0)
5488
5482
  {
5489
5483
    cur_file->file= stdin;
5490
 
    cur_file->file_name= strdup("<stdin>");
5491
 
    if (cur_file->file_name == NULL)
5492
 
      die("Out of memory");
 
5484
    cur_file->file_name= my_strdup("<stdin>", MYF(MY_WME));
5493
5485
    cur_file->lineno= 1;
5494
5486
  }
5495
5487
  cur_con= connections;
5499
5491
    drizzle_options(&cur_con->drizzle,DRIZZLE_OPT_COMPRESS,NULL);
5500
5492
  drizzle_options(&cur_con->drizzle, DRIZZLE_OPT_LOCAL_INFILE, 0);
5501
5493
 
5502
 
  if (!(cur_con->name = strdup("default")))
 
5494
  if (!(cur_con->name = my_strdup("default", MYF(MY_WME))))
5503
5495
    die("Out of memory");
5504
5496
 
5505
5497
  safe_connect(&cur_con->drizzle, cur_con->name, opt_host, opt_user, opt_pass,
5934
5926
    die("Missing argument in %s", command->query);
5935
5927
 
5936
5928
  /* Allocate a buffer for results */
5937
 
  start= buff= (char *)malloc(strlen(from)+1);
 
5929
  start= buff= (char *)my_malloc(strlen(from)+1,MYF(MY_WME | MY_FAE));
5938
5930
  while (*from)
5939
5931
  {
5940
5932
    char *to;
5947
5939
      die("Wrong number of arguments to replace_column in '%s'", command->query);
5948
5940
    to= get_string(&buff, &from, command);
5949
5941
    free(replace_column[column_number-1]);
5950
 
    replace_column[column_number-1]= strdup(to);
5951
 
    if (replace_column[column_number-1] == NULL)
5952
 
      die("Out of memory");
 
5942
    replace_column[column_number-1]= my_strdup(to, MYF(MY_WME | MY_FAE));
5953
5943
    set_if_bigger(max_replace_column, column_number);
5954
5944
  }
5955
5945
  free(start);
6019
6009
  memset(&from_array, 0, sizeof(from_array));
6020
6010
  if (!*from)
6021
6011
    die("Missing argument in %s", command->query);
6022
 
  start= buff= (char *)malloc(strlen(from)+1);
 
6012
  start= buff= (char *)my_malloc(strlen(from)+1,MYF(MY_WME | MY_FAE));
6023
6013
  while (*from)
6024
6014
  {
6025
6015
    char *to= buff;
6198
6188
  char last_c = 0;
6199
6189
  struct st_regex reg;
6200
6190
 
6201
 
  res=(st_replace_regex*)malloc(sizeof(*res)+expr_len);
6202
 
  if (!res)
6203
 
    return NULL;
 
6191
  /* my_malloc() will die on fail with MY_FAE */
 
6192
  res=(struct st_replace_regex*)my_malloc(
 
6193
                                          sizeof(*res)+expr_len ,MYF(MY_FAE+MY_WME));
6204
6194
  my_init_dynamic_array(&res->regex_arr,sizeof(struct st_regex),128,128);
6205
6195
 
6206
6196
  buf= (char*)res + sizeof(*res);
6257
6247
      die("Out of memory");
6258
6248
  }
6259
6249
  res->odd_buf_len= res->even_buf_len= 8192;
6260
 
  res->even_buf= (char*)malloc(res->even_buf_len);
6261
 
  res->odd_buf= (char*)malloc(res->odd_buf_len);
 
6250
  res->even_buf= (char*)my_malloc(res->even_buf_len,MYF(MY_WME+MY_FAE));
 
6251
  res->odd_buf= (char*)my_malloc(res->odd_buf_len,MYF(MY_WME+MY_FAE));
6262
6252
  res->buf= res->even_buf;
6263
6253
 
6264
6254
  return res;
6398
6388
    return 1;
6399
6389
  }
6400
6390
 
6401
 
  char *substring_to_replace= in_string + ovector[0];
 
6391
  char *substring_to_replace= in_string + ovector[0]; 
6402
6392
  int substring_length= ovector[1] - ovector[0];
6403
6393
  *buf_len_p= strlen(in_string) - substring_length + strlen(replace);
6404
6394
  char * new_buf = (char *)malloc(*buf_len_p+1);
6535
6525
  if (init_sets(&sets,states))
6536
6526
    return(0);
6537
6527
  found_sets=0;
6538
 
  if (!(found_set= (FOUND_SET*) malloc(sizeof(FOUND_SET)*max_length*count)))
6539
 
                                
 
6528
  if (!(found_set= (FOUND_SET*) my_malloc(sizeof(FOUND_SET)*max_length*count,
 
6529
                                          MYF(MY_WME))))
6540
6530
  {
6541
6531
    free_sets(&sets);
6542
6532
    return(0);
6546
6536
  used_sets=-1;
6547
6537
  word_states=make_new_set(&sets);    /* Start of new word */
6548
6538
  start_states=make_new_set(&sets);    /* This is first state */
6549
 
  if (!(follow=(FOLLOWS*) malloc((states+2)*sizeof(FOLLOWS))))
 
6539
  if (!(follow=(FOLLOWS*) my_malloc((states+2)*sizeof(FOLLOWS),MYF(MY_WME))))
6550
6540
  {
6551
6541
    free_sets(&sets);
6552
6542
    free(found_set);
6738
6728
 
6739
6729
  /* Alloc replace structure for the replace-state-machine */
6740
6730
 
6741
 
  if ((replace=(REPLACE*) malloc(sizeof(REPLACE)*(sets.count)+
6742
 
                                 sizeof(REPLACE_STRING)*(found_sets+1)+
6743
 
                                 sizeof(char *)*count+result_len)))
 
6731
  if ((replace=(REPLACE*) my_malloc(sizeof(REPLACE)*(sets.count)+
 
6732
                                    sizeof(REPLACE_STRING)*(found_sets+1)+
 
6733
                                    sizeof(char *)*count+result_len,
 
6734
                                    MYF(MY_WME | MY_ZEROFILL))))
6744
6735
  {
6745
 
    memset(replace, 0, sizeof(REPLACE)*(sets.count)+
6746
 
                       sizeof(REPLACE_STRING)*(found_sets+1)+
6747
 
                       sizeof(char *)*count+result_len);
6748
6736
    rep_str=(REPLACE_STRING*) (replace+sets.count);
6749
6737
    to_array= (char **) (rep_str+found_sets+1);
6750
6738
    to_pos=(char *) (to_array+count);
6751
6739
    for (i=0 ; i < count ; i++)
6752
6740
    {
6753
6741
      to_array[i]=to_pos;
6754
 
      to_pos=strcpy(to_pos,to[i])+strlen(to[i])+1;
 
6742
      to_pos=my_stpcpy(to_pos,to[i])+1;
6755
6743
    }
6756
6744
    rep_str[0].found=1;
6757
6745
    rep_str[0].replace_string=0;
6784
6772
{
6785
6773
  memset(sets, 0, sizeof(*sets));
6786
6774
  sets->size_of_bits=((states+7)/8);
6787
 
  if (!(sets->set_buffer=(REP_SET*) malloc(sizeof(REP_SET)*SET_MALLOC_HUNC)))
 
6775
  if (!(sets->set_buffer=(REP_SET*) my_malloc(sizeof(REP_SET)*SET_MALLOC_HUNC,
 
6776
                                              MYF(MY_WME))))
6788
6777
    return 1;
6789
 
  if (!(sets->bit_buffer=(uint*) malloc(sizeof(uint)*sets->size_of_bits*
6790
 
                                        SET_MALLOC_HUNC)))
 
6778
  if (!(sets->bit_buffer=(uint*) my_malloc(sizeof(uint)*sets->size_of_bits*
 
6779
                                           SET_MALLOC_HUNC,MYF(MY_WME))))
6791
6780
  {
6792
6781
    free(sets->set);
6793
6782
    return 1;
6821
6810
    return set;
6822
6811
  }
6823
6812
  count=sets->count+sets->invisible+SET_MALLOC_HUNC;
6824
 
  if (!(set=(REP_SET*) realloc((unsigned char*) sets->set_buffer,
6825
 
                                  sizeof(REP_SET)*count)))
 
6813
  if (!(set=(REP_SET*) my_realloc((unsigned char*) sets->set_buffer,
 
6814
                                  sizeof(REP_SET)*count,
 
6815
                                  MYF(MY_WME))))
6826
6816
    return 0;
6827
6817
  sets->set_buffer=set;
6828
6818
  sets->set=set+sets->invisible;
6829
 
  if (!(bit_buffer=(uint*) realloc((unsigned char*) sets->bit_buffer,
6830
 
                                   (sizeof(uint)*sets->size_of_bits)*count)))
 
6819
  if (!(bit_buffer=(uint*) my_realloc((unsigned char*) sets->bit_buffer,
 
6820
                                      (sizeof(uint)*sets->size_of_bits)*count,
 
6821
                                      MYF(MY_WME))))
6831
6822
    return 0;
6832
6823
  sets->bit_buffer=bit_buffer;
6833
6824
  for (i=0 ; i < count ; i++)
6979
6970
  if (! pa->typelib.count)
6980
6971
  {
6981
6972
    if (!(pa->typelib.type_names=(const char **)
6982
 
          malloc(((PC_MALLOC-MALLOC_OVERHEAD)/
 
6973
          my_malloc(((PC_MALLOC-MALLOC_OVERHEAD)/
6983
6974
                     (sizeof(char *)+sizeof(*pa->flag))*
6984
 
                     (sizeof(char *)+sizeof(*pa->flag))))))
 
6975
                     (sizeof(char *)+sizeof(*pa->flag))),MYF(MY_WME))))
6985
6976
      return(-1);
6986
 
    if (!(pa->str= (unsigned char*) malloc(PS_MALLOC-MALLOC_OVERHEAD)))
 
6977
    if (!(pa->str= (unsigned char*) my_malloc((uint) (PS_MALLOC-MALLOC_OVERHEAD),
 
6978
                                      MYF(MY_WME))))
6987
6979
    {
6988
6980
      free((char*) pa->typelib.type_names);
6989
6981
      return (-1);
6998
6990
  length=(uint) strlen(name)+1;
6999
6991
  if (pa->length+length >= pa->max_length)
7000
6992
  {
7001
 
    if (!(new_pos= (unsigned char*)realloc((unsigned char*)pa->str,
7002
 
                                           (size_t)(pa->max_length+PS_MALLOC))))
 
6993
    if (!(new_pos= (unsigned char*) my_realloc((unsigned char*) pa->str,
 
6994
                                       (uint) (pa->max_length+PS_MALLOC),
 
6995
                                       MYF(MY_WME))))
7003
6996
      return(1);
7004
6997
    if (new_pos != pa->str)
7005
6998
    {
7013
7006
  }
7014
7007
  if (pa->typelib.count >= pa->max_count-1)
7015
7008
  {
7016
 
    size_t len;
 
7009
    int len;
7017
7010
    pa->array_allocs++;
7018
7011
    len=(PC_MALLOC*pa->array_allocs - MALLOC_OVERHEAD);
7019
 
    if (!(new_array=
7020
 
         (const char **)realloc((unsigned char*) pa->typelib.type_names,
7021
 
                                 len/
7022
 
                                  (sizeof(unsigned char*)+sizeof(*pa->flag))*
7023
 
                                  (sizeof(unsigned char*)+sizeof(*pa->flag)))))
 
7012
    if (!(new_array=(const char **) my_realloc((unsigned char*) pa->typelib.type_names,
 
7013
                                               (uint) len/
 
7014
                                               (sizeof(unsigned char*)+sizeof(*pa->flag))*
 
7015
                                               (sizeof(unsigned char*)+sizeof(*pa->flag)),
 
7016
                                               MYF(MY_WME))))
7024
7017
      return(1);
7025
7018
    pa->typelib.type_names=new_array;
7026
7019
    old_count=pa->max_count;
7032
7025
  pa->flag[pa->typelib.count]=0;      /* Reset flag */
7033
7026
  pa->typelib.type_names[pa->typelib.count++]= (char*) pa->str+pa->length;
7034
7027
  pa->typelib.type_names[pa->typelib.count]= NULL;  /* Put end-mark */
7035
 
  strcpy((char*) pa->str+pa->length,name);
 
7028
  my_stpcpy((char*) pa->str+pa->length,name);
7036
7029
  pa->length+=length;
7037
7030
  return(0);
7038
7031
} /* insert_pointer_name */