~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to client/drizzletest.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:
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
 
      my_seek(fd, 0, SEEK_SET, MYF(0)) == MY_FILEPOS_ERROR)
 
1382
      lseek(fd, 0, SEEK_SET) == 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*)my_malloc(sizeof(*tmp_var)
1560
 
                                                  + name_len+1, MYF(MY_WME))))
 
1559
  if (!(tmp_var=v) && !(tmp_var = (VAR*)malloc(sizeof(*tmp_var)
 
1560
                                               + name_len+1)))
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 *)my_malloc(val_alloc_len+1, MYF(MY_WME))))
 
1566
  if (!(tmp_var->str_val = (char *)malloc(val_alloc_len+1)))
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= my_strdup(buf, MYF(MY_WME))))
 
1713
    if (!(v->env_s= strdup(buf)))
1714
1714
      die("Out of memory");
1715
1715
    putenv(v->env_s);
1716
1716
    free(old_env_s);
1957
1957
  /* Alloc/realloc data for str_val in dest */
1958
1958
  if (dest->alloced_len < src->alloced_len &&
1959
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))))
 
1960
        ? (char *)realloc(dest->str_val, src->alloced_len)
 
1961
        : (char *)malloc(src->alloced_len)))
1962
1962
    die("Out of memory");
1963
1963
  else
1964
1964
    dest->alloced_len= src->alloced_len;
2012
2012
      v->alloced_len = (new_val_len < MIN_VAR_ALLOC - 1) ?
2013
2013
        MIN_VAR_ALLOC : new_val_len + 1;
2014
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))))
 
2015
            v->str_val ? (char *)realloc(v->str_val, v->alloced_len+1)
 
2016
                       : (char *)malloc(v->alloced_len+1)))
2018
2017
        die("Out of memory");
2019
2018
    }
2020
2019
    v->str_val_len = new_val_len;
2046
2045
    cur_file--;
2047
2046
    die("Could not open '%s' for reading", buff);
2048
2047
  }
2049
 
  cur_file->file_name= my_strdup(buff, MYF(MY_FAE));
 
2048
  if (!(cur_file->file_name= strdup(buff)))
 
2049
    die("Out of memory");
2050
2050
  cur_file->lineno=1;
2051
2051
  return(0);
2052
2052
}
3524
3524
    When the connection is closed set name to "-closed_connection-"
3525
3525
    to make it possible to reuse the connection name.
3526
3526
  */
3527
 
  if (!(con->name = my_strdup("-closed_connection-", MYF(MY_WME))))
 
3527
  if (!(con->name = strdup("-closed_connection-")))
3528
3528
    die("Out of memory");
3529
3529
 
3530
3530
  return;
4367
4367
    return(0);
4368
4368
  }
4369
4369
  if (!(*command_ptr= command=
4370
 
        (struct st_command*) my_malloc(sizeof(*command),
4371
 
                                       MYF(MY_WME|MY_ZEROFILL))))
 
4370
        (struct st_command*) malloc(sizeof(*command))))
4372
4371
    die(NULL);
 
4372
  memset(command, 0, sizeof(*command));
4373
4373
  q_lines.push_back(command);
4374
4374
  command->type= Q_UNKNOWN;
4375
4375
 
4396
4396
  while (*p && my_isspace(charset_info, *p))
4397
4397
    p++;
4398
4398
 
4399
 
  if (!(command->query_buf= command->query= my_strdup(p, MYF(MY_WME))))
 
4399
  if (!(command->query_buf= command->query= strdup(p)))
4400
4400
    die("Out of memory");
4401
4401
 
4402
4402
  /* Calculate first word length(the command), terminated by space or ( */
4542
4542
  {
4543
4543
    *(strchr(str, '\0')-1)=0;        /* Remove end newline */
4544
4544
    if (!(embedded_server_args[embedded_server_arg_count]=
4545
 
          (char*) my_strdup(str,MYF(MY_WME))))
 
4545
          (char*) strdup(str)))
4546
4546
    {
4547
4547
      my_fclose(file,MYF(0));
4548
4548
      die("Out of memory");
4578
4578
    if (!(cur_file->file=
4579
4579
          my_fopen(buff, O_RDONLY, MYF(0))))
4580
4580
      die("Could not open '%s' for reading: errno = %d", buff, errno);
4581
 
    cur_file->file_name= my_strdup(buff, MYF(MY_FAE));
 
4581
    if (!(cur_file->file_name= strdup(buff)))
 
4582
      die("Out of memory");
4582
4583
    cur_file->lineno= 1;
4583
4584
    break;
4584
4585
  }
4598
4599
  case 'p':
4599
4600
    if (argument)
4600
4601
    {
4601
 
      free(opt_pass);
4602
 
      opt_pass= my_strdup(argument, MYF(MY_FAE));
 
4602
      if (opt_pass)
 
4603
        free(opt_pass);
 
4604
      opt_pass = strdup(argument);
 
4605
      if (opt_pass == NULL)
 
4606
        die("Out of memory");
4603
4607
      while (*argument) *argument++= 'x';    /* Destroy argument */
4604
4608
      tty_password= 0;
4605
4609
    }
4617
4621
    }
4618
4622
    if (embedded_server_arg_count == MAX_EMBEDDED_SERVER_ARGS-1 ||
4619
4623
        !(embedded_server_args[embedded_server_arg_count++]=
4620
 
          my_strdup(argument, MYF(MY_FAE))))
 
4624
          strdup(argument)))
4621
4625
    {
4622
4626
      die("Can't use server argument");
4623
4627
    }
4689
4693
  if ((fd= my_open(buff, flags,
4690
4694
                   MYF(MY_WME | MY_FFNF))) < 0)
4691
4695
    die("Could not open '%s' for writing: errno = %d", buff, errno);
4692
 
  if (append && my_seek(fd, 0, SEEK_END, MYF(0)) == MY_FILEPOS_ERROR)
 
4696
  if (append && lseek(fd, 0, SEEK_END) == MY_FILEPOS_ERROR)
4693
4697
    die("Could not find end of file '%s': errno = %d", buff, errno);
4694
4698
  if (my_write(fd, (unsigned char*)str, size, MYF(MY_WME|MY_FNABP)))
4695
4699
    die("write failed");
5481
5485
  if (cur_file == file_stack && cur_file->file == 0)
5482
5486
  {
5483
5487
    cur_file->file= stdin;
5484
 
    cur_file->file_name= my_strdup("<stdin>", MYF(MY_WME));
 
5488
    cur_file->file_name= strdup("<stdin>");
 
5489
    if (cur_file->file_name == NULL)
 
5490
      die("Out of memory");
5485
5491
    cur_file->lineno= 1;
5486
5492
  }
5487
5493
  cur_con= connections;
5491
5497
    drizzle_options(&cur_con->drizzle,DRIZZLE_OPT_COMPRESS,NULL);
5492
5498
  drizzle_options(&cur_con->drizzle, DRIZZLE_OPT_LOCAL_INFILE, 0);
5493
5499
 
5494
 
  if (!(cur_con->name = my_strdup("default", MYF(MY_WME))))
 
5500
  if (!(cur_con->name = strdup("default")))
5495
5501
    die("Out of memory");
5496
5502
 
5497
5503
  safe_connect(&cur_con->drizzle, cur_con->name, opt_host, opt_user, opt_pass,
5926
5932
    die("Missing argument in %s", command->query);
5927
5933
 
5928
5934
  /* Allocate a buffer for results */
5929
 
  start= buff= (char *)my_malloc(strlen(from)+1,MYF(MY_WME | MY_FAE));
 
5935
  start= buff= (char *)malloc(strlen(from)+1);
5930
5936
  while (*from)
5931
5937
  {
5932
5938
    char *to;
5939
5945
      die("Wrong number of arguments to replace_column in '%s'", command->query);
5940
5946
    to= get_string(&buff, &from, command);
5941
5947
    free(replace_column[column_number-1]);
5942
 
    replace_column[column_number-1]= my_strdup(to, MYF(MY_WME | MY_FAE));
 
5948
    replace_column[column_number-1]= strdup(to);
 
5949
    if (replace_column[column_number-1] == NULL)
 
5950
      die("Out of memory");
5943
5951
    set_if_bigger(max_replace_column, column_number);
5944
5952
  }
5945
5953
  free(start);
6009
6017
  memset(&from_array, 0, sizeof(from_array));
6010
6018
  if (!*from)
6011
6019
    die("Missing argument in %s", command->query);
6012
 
  start= buff= (char *)my_malloc(strlen(from)+1,MYF(MY_WME | MY_FAE));
 
6020
  start= buff= (char *)malloc(strlen(from)+1);
6013
6021
  while (*from)
6014
6022
  {
6015
6023
    char *to= buff;
6188
6196
  char last_c = 0;
6189
6197
  struct st_regex reg;
6190
6198
 
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));
 
6199
  res=(st_replace_regex*)malloc(sizeof(*res)+expr_len);
 
6200
  if (!res)
 
6201
    return NULL;
6194
6202
  my_init_dynamic_array(&res->regex_arr,sizeof(struct st_regex),128,128);
6195
6203
 
6196
6204
  buf= (char*)res + sizeof(*res);
6247
6255
      die("Out of memory");
6248
6256
  }
6249
6257
  res->odd_buf_len= res->even_buf_len= 8192;
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));
 
6258
  res->even_buf= (char*)malloc(res->even_buf_len);
 
6259
  res->odd_buf= (char*)malloc(res->odd_buf_len);
6252
6260
  res->buf= res->even_buf;
6253
6261
 
6254
6262
  return res;
6525
6533
  if (init_sets(&sets,states))
6526
6534
    return(0);
6527
6535
  found_sets=0;
6528
 
  if (!(found_set= (FOUND_SET*) my_malloc(sizeof(FOUND_SET)*max_length*count,
6529
 
                                          MYF(MY_WME))))
 
6536
  if (!(found_set= (FOUND_SET*) malloc(sizeof(FOUND_SET)*max_length*count)))
 
6537
                                
6530
6538
  {
6531
6539
    free_sets(&sets);
6532
6540
    return(0);
6536
6544
  used_sets=-1;
6537
6545
  word_states=make_new_set(&sets);    /* Start of new word */
6538
6546
  start_states=make_new_set(&sets);    /* This is first state */
6539
 
  if (!(follow=(FOLLOWS*) my_malloc((states+2)*sizeof(FOLLOWS),MYF(MY_WME))))
 
6547
  if (!(follow=(FOLLOWS*) malloc((states+2)*sizeof(FOLLOWS))))
6540
6548
  {
6541
6549
    free_sets(&sets);
6542
6550
    free(found_set);
6728
6736
 
6729
6737
  /* Alloc replace structure for the replace-state-machine */
6730
6738
 
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))))
 
6739
  if ((replace=(REPLACE*) malloc(sizeof(REPLACE)*(sets.count)+
 
6740
                                 sizeof(REPLACE_STRING)*(found_sets+1)+
 
6741
                                 sizeof(char *)*count+result_len)))
6735
6742
  {
 
6743
    memset(replace, 0, sizeof(REPLACE)*(sets.count)+
 
6744
                       sizeof(REPLACE_STRING)*(found_sets+1)+
 
6745
                       sizeof(char *)*count+result_len);
6736
6746
    rep_str=(REPLACE_STRING*) (replace+sets.count);
6737
6747
    to_array= (char **) (rep_str+found_sets+1);
6738
6748
    to_pos=(char *) (to_array+count);
6772
6782
{
6773
6783
  memset(sets, 0, sizeof(*sets));
6774
6784
  sets->size_of_bits=((states+7)/8);
6775
 
  if (!(sets->set_buffer=(REP_SET*) my_malloc(sizeof(REP_SET)*SET_MALLOC_HUNC,
6776
 
                                              MYF(MY_WME))))
 
6785
  if (!(sets->set_buffer=(REP_SET*) malloc(sizeof(REP_SET)*SET_MALLOC_HUNC)))
6777
6786
    return 1;
6778
 
  if (!(sets->bit_buffer=(uint*) my_malloc(sizeof(uint)*sets->size_of_bits*
6779
 
                                           SET_MALLOC_HUNC,MYF(MY_WME))))
 
6787
  if (!(sets->bit_buffer=(uint*) malloc(sizeof(uint)*sets->size_of_bits*
 
6788
                                        SET_MALLOC_HUNC)))
6780
6789
  {
6781
6790
    free(sets->set);
6782
6791
    return 1;
6810
6819
    return set;
6811
6820
  }
6812
6821
  count=sets->count+sets->invisible+SET_MALLOC_HUNC;
6813
 
  if (!(set=(REP_SET*) my_realloc((unsigned char*) sets->set_buffer,
6814
 
                                  sizeof(REP_SET)*count,
6815
 
                                  MYF(MY_WME))))
 
6822
  if (!(set=(REP_SET*) realloc((unsigned char*) sets->set_buffer,
 
6823
                                  sizeof(REP_SET)*count)))
6816
6824
    return 0;
6817
6825
  sets->set_buffer=set;
6818
6826
  sets->set=set+sets->invisible;
6819
 
  if (!(bit_buffer=(uint*) my_realloc((unsigned char*) sets->bit_buffer,
6820
 
                                      (sizeof(uint)*sets->size_of_bits)*count,
6821
 
                                      MYF(MY_WME))))
 
6827
  if (!(bit_buffer=(uint*) realloc((unsigned char*) sets->bit_buffer,
 
6828
                                   (sizeof(uint)*sets->size_of_bits)*count)))
6822
6829
    return 0;
6823
6830
  sets->bit_buffer=bit_buffer;
6824
6831
  for (i=0 ; i < count ; i++)
6970
6977
  if (! pa->typelib.count)
6971
6978
  {
6972
6979
    if (!(pa->typelib.type_names=(const char **)
6973
 
          my_malloc(((PC_MALLOC-MALLOC_OVERHEAD)/
 
6980
          malloc(((PC_MALLOC-MALLOC_OVERHEAD)/
6974
6981
                     (sizeof(char *)+sizeof(*pa->flag))*
6975
 
                     (sizeof(char *)+sizeof(*pa->flag))),MYF(MY_WME))))
 
6982
                     (sizeof(char *)+sizeof(*pa->flag))))))
6976
6983
      return(-1);
6977
 
    if (!(pa->str= (unsigned char*) my_malloc((uint) (PS_MALLOC-MALLOC_OVERHEAD),
6978
 
                                      MYF(MY_WME))))
 
6984
    if (!(pa->str= (unsigned char*) malloc(PS_MALLOC-MALLOC_OVERHEAD)))
6979
6985
    {
6980
6986
      free((char*) pa->typelib.type_names);
6981
6987
      return (-1);
6990
6996
  length=(uint) strlen(name)+1;
6991
6997
  if (pa->length+length >= pa->max_length)
6992
6998
  {
6993
 
    if (!(new_pos= (unsigned char*) my_realloc((unsigned char*) pa->str,
6994
 
                                       (uint) (pa->max_length+PS_MALLOC),
6995
 
                                       MYF(MY_WME))))
 
6999
    if (!(new_pos= (unsigned char*)realloc((unsigned char*)pa->str,
 
7000
                                           (size_t)(pa->max_length+PS_MALLOC))))
6996
7001
      return(1);
6997
7002
    if (new_pos != pa->str)
6998
7003
    {
7006
7011
  }
7007
7012
  if (pa->typelib.count >= pa->max_count-1)
7008
7013
  {
7009
 
    int len;
 
7014
    size_t len;
7010
7015
    pa->array_allocs++;
7011
7016
    len=(PC_MALLOC*pa->array_allocs - MALLOC_OVERHEAD);
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))))
 
7017
    if (!(new_array=
 
7018
         (const char **)realloc((unsigned char*) pa->typelib.type_names,
 
7019
                                 len/
 
7020
                                  (sizeof(unsigned char*)+sizeof(*pa->flag))*
 
7021
                                  (sizeof(unsigned char*)+sizeof(*pa->flag)))))
7017
7022
      return(1);
7018
7023
    pa->typelib.type_names=new_array;
7019
7024
    old_count=pa->max_count;