Skip to content

Commit 32b7d45

Browse files
committed
mysqltest: use a dynamically growing command buffer
1 parent c362ea3 commit 32b7d45

File tree

1 file changed

+26
-16
lines changed

1 file changed

+26
-16
lines changed

client/mysqltest.cc

Lines changed: 26 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -6501,8 +6501,6 @@ static inline bool is_escape_char(char c, char in_string)
65016501
65026502
SYNOPSIS
65036503
read_line
6504-
buf buffer for the read line
6505-
size size of the buffer i.e max size to read
65066504
65076505
DESCRIPTION
65086506
This function actually reads several lines and adds them to the
@@ -6520,21 +6518,37 @@ static inline bool is_escape_char(char c, char in_string)
65206518
65216519
*/
65226520

6523-
int read_line(char *buf, int size)
6521+
static char *read_command_buf= NULL;
6522+
static size_t read_command_buflen= 0;
6523+
static const size_t max_multibyte_length= 6;
6524+
6525+
int read_line()
65246526
{
65256527
char c, last_quote=0, last_char= 0;
6526-
char *p= buf, *buf_end= buf + size - 1;
6528+
char *p= read_command_buf;
6529+
char *buf_end= read_command_buf + read_command_buflen - max_multibyte_length;
65276530
int skip_char= 0;
65286531
my_bool have_slash= FALSE;
65296532

65306533
enum {R_NORMAL, R_Q, R_SLASH_IN_Q,
65316534
R_COMMENT, R_LINE_START} state= R_LINE_START;
65326535
DBUG_ENTER("read_line");
65336536

6537+
*p= 0;
65346538
start_lineno= cur_file->lineno;
65356539
DBUG_PRINT("info", ("Starting to read at lineno: %d", start_lineno));
6536-
for (; p < buf_end ;)
6540+
while (1)
65376541
{
6542+
if (p >= buf_end)
6543+
{
6544+
my_ptrdiff_t off= p - read_command_buf;
6545+
read_command_buf= (char*)my_realloc(read_command_buf,
6546+
read_command_buflen*2, MYF(MY_FAE));
6547+
p= read_command_buf + off;
6548+
read_command_buflen*= 2;
6549+
buf_end= read_command_buf + read_command_buflen - max_multibyte_length;
6550+
}
6551+
65386552
skip_char= 0;
65396553
c= my_getc(cur_file->file);
65406554
if (feof(cur_file->file))
@@ -6570,7 +6584,7 @@ int read_line(char *buf, int size)
65706584
cur_file->lineno++;
65716585

65726586
/* Convert cr/lf to lf */
6573-
if (p != buf && *(p-1) == '\r')
6587+
if (p != read_command_buf && *(p-1) == '\r')
65746588
p--;
65756589
}
65766590

@@ -6585,9 +6599,9 @@ int read_line(char *buf, int size)
65856599
}
65866600
else if ((c == '{' &&
65876601
(!my_strnncoll_simple(charset_info, (const uchar*) "while", 5,
6588-
(uchar*) buf, min(5, p - buf), 0) ||
6602+
(uchar*) read_command_buf, min(5, p - read_command_buf), 0) ||
65896603
!my_strnncoll_simple(charset_info, (const uchar*) "if", 2,
6590-
(uchar*) buf, min(2, p - buf), 0))))
6604+
(uchar*) read_command_buf, min(2, p - read_command_buf), 0))))
65916605
{
65926606
/* Only if and while commands can be terminated by { */
65936607
*p++= c;
@@ -6721,8 +6735,6 @@ int read_line(char *buf, int size)
67216735
*p++= c;
67226736
}
67236737
}
6724-
die("The input buffer is too small for this query.x\n" \
6725-
"check your query or increase MAX_QUERY and recompile");
67266738
DBUG_RETURN(0);
67276739
}
67286740

@@ -6867,12 +6879,8 @@ bool is_delimiter(const char* p)
68676879
terminated by new line '\n' regardless how many "delimiter" it contain.
68686880
*/
68696881

6870-
#define MAX_QUERY (256*1024*2) /* 256K -- a test in sp-big is >128K */
6871-
static char read_command_buf[MAX_QUERY];
6872-
68736882
int read_command(struct st_command** command_ptr)
68746883
{
6875-
char *p= read_command_buf;
68766884
struct st_command* command;
68776885
DBUG_ENTER("read_command");
68786886

@@ -6888,8 +6896,7 @@ int read_command(struct st_command** command_ptr)
68886896
die("Out of memory");
68896897
command->type= Q_UNKNOWN;
68906898

6891-
read_command_buf[0]= 0;
6892-
if (read_line(read_command_buf, sizeof(read_command_buf)))
6899+
if (read_line())
68936900
{
68946901
check_eol_junk(read_command_buf);
68956902
DBUG_RETURN(1);
@@ -6898,6 +6905,7 @@ int read_command(struct st_command** command_ptr)
68986905
if (opt_result_format_version == 1)
68996906
convert_to_format_v1(read_command_buf);
69006907

6908+
char *p= read_command_buf;
69016909
DBUG_PRINT("info", ("query: '%s'", read_command_buf));
69026910
if (*p == '#')
69036911
{
@@ -9025,6 +9033,8 @@ int main(int argc, char **argv)
90259033
init_win_path_patterns();
90269034
#endif
90279035

9036+
read_command_buf= (char*)my_malloc(read_command_buflen= 65536, MYF(MY_FAE));
9037+
90289038
init_dynamic_string(&ds_res, "", 2048, 2048);
90299039
init_alloc_root(&require_file_root, 1024, 1024);
90309040

0 commit comments

Comments
 (0)