1
Author: HJ Lu <hjl@lucon.org>
2
Description: Fixes problems when running GCCs testsuite (Closes: #156854).
4
diff -Naurp expect.orig/exp_chan.c expect/exp_chan.c
5
--- expect.orig/exp_chan.c 2009-08-03 06:58:30.000000000 +0000
6
+++ expect/exp_chan.c 2009-08-03 08:33:41.000000000 +0000
7
@@ -622,6 +622,7 @@ expCreateChannel(interp,fdin,fdout,pid)
8
esPtr->buffer = Tcl_NewStringObj("",0);
9
Tcl_IncrRefCount(esPtr->buffer);
10
esPtr->umsize = exp_default_match_max;
11
+ esPtr->umsize_changed = exp_default_match_max_changed;
12
/* this will reallocate object with an appropriate sized buffer */
15
diff -Naurp expect.orig/exp_command.h expect/exp_command.h
16
--- expect.orig/exp_command.h 2009-08-03 06:58:30.000000000 +0000
17
+++ expect/exp_command.h 2009-08-03 08:33:41.000000000 +0000
18
@@ -30,6 +30,7 @@ would appreciate credit if this program
19
EXTERN char * exp_get_var _ANSI_ARGS_((Tcl_Interp *,char *));
21
EXTERN int exp_default_match_max;
22
+EXTERN int exp_default_match_max_changed;
23
EXTERN int exp_default_parity;
24
EXTERN int exp_default_rm_nulls;
25
EXTERN int exp_default_close_on_eof;
26
@@ -103,6 +104,7 @@ typedef struct ExpState {
27
int msize; /* # of bytes that buffer can hold (max) */
28
int umsize; /* # of bytes (min) that is guaranteed to match */
29
/* this comes from match_max command */
30
+ int umsize_changed; /* is umsize changed by user? */
31
int printed; /* # of bytes written to stdout (if logging on) */
32
/* but not actually returned via a match yet */
33
int echoed; /* additional # of bytes (beyond "printed" above) */
34
diff -Naurp expect.orig/expect.c expect/expect.c
35
--- expect.orig/expect.c 2009-08-03 06:58:30.000000000 +0000
36
+++ expect/expect.c 2009-08-03 08:33:41.000000000 +0000
37
@@ -41,8 +41,17 @@ would appreciate credit if this program
41
+/* The initial length is 2000. We increment it by 2000. The maximum
42
+ is 8MB (0x800000). */
43
+#define EXP_MATCH_MAX 2000
44
+#define EXP_MATCH_INC 2000
45
+#define EXP_MATCH_STEP_LIMIT 0x700000
46
+#define EXP_MATCH_LIMIT 0x800000
47
+#define EXP_MATCH_LIMIT_QUOTE "0x800000"
49
/* initial length of strings that we can guarantee patterns can match */
50
-int exp_default_match_max = 2000;
51
+int exp_default_match_max = EXP_MATCH_MAX;
52
+int exp_default_match_max_changed = 0;
53
#define INIT_EXPECT_TIMEOUT_LIT "10" /* seconds */
54
#define INIT_EXPECT_TIMEOUT 10 /* seconds */
55
int exp_default_parity = TRUE;
56
@@ -1619,6 +1628,76 @@ expNullStrip(obj,offsetBytes)
60
+/* returns # of bytes until we see a newline at the end or EOF. */
63
+expReadNewLine(interp,esPtr,save_flags) /* INTL */
76
+ exp_size = expSizeGet(esPtr);
78
+ /* When we reach the limit, we will only read one char at a
80
+ if (esPtr->umsize >= EXP_MATCH_STEP_LIMIT)
85
+ if (exp_size + TCL_UTF_MAX >= esPtr->msize) {
86
+ if (esPtr->umsize >= EXP_MATCH_LIMIT) {
87
+ expDiagLogU("WARNING: interact buffer is full. probably your program\r\n");
88
+ expDiagLogU("is not interactive or has a very long output line. The\r\n");
89
+ expDiagLogU("current limit is " EXP_MATCH_LIMIT_QUOTE ".\r\n");
90
+ expDiagLogU("Dumping first half of buffer in order to continue\r\n");
91
+ expDiagLogU("Recommend you enlarge the buffer.\r\n");
92
+ exp_buffer_shuffle(interp,esPtr,save_flags,EXPECT_OUT,"expect");
96
+ esPtr->umsize += EXP_MATCH_INC;
101
+ full_size = esPtr->msize - (size / TCL_UTF_MAX);
102
+ size = Tcl_ReadChars(esPtr->channel,
108
+ /* We try again if there are more to read and we haven't
109
+ seen a newline at the end. */
110
+ if (size == full_size) {
111
+ str = Tcl_GetStringFromObj(esPtr->buffer, &size);
112
+ if (str[size - 1] != '\n')
117
+ /* It is even trickier. We got an error from read. We have
118
+ to recover from it. Let's make sure the size of
119
+ buffer is correct. It can be corrupted. */
120
+ str = Tcl_GetString(esPtr->buffer);
121
+ Tcl_SetObjLength(esPtr->buffer, strlen(str));
130
/* returns # of bytes read or (non-positive) error of form EXP_XXX */
131
/* returns 0 for end of file */
132
/* If timeout is non-zero, set an alarm before doing the read, else assume */
133
@@ -1633,6 +1712,8 @@ int save_flags;
135
int cc = EXP_TIMEOUT;
136
int size = expSizeGet(esPtr);
140
if (size + TCL_UTF_MAX >= esPtr->msize)
141
exp_buffer_shuffle(interp,esPtr,save_flags,EXPECT_OUT,"expect");
142
@@ -1649,11 +1730,43 @@ int save_flags;
147
+ /* FIXME: If we ask less than what is available in the tcl buffer
148
+ when tcl has seen EOF, we will throw away the remaining data
149
+ since the next read will get EOF. Since expect is line-oriented,
150
+ we exand our buffer to get EOF or the next newline at the end of
151
+ the input buffer. I don't know if it is the right fix. H.J. */
153
+ full_size = esPtr->msize - (size / TCL_UTF_MAX);
154
cc = Tcl_ReadChars(esPtr->channel,
156
- esPtr->msize - (size / TCL_UTF_MAX),
163
+ /* It gets very tricky. There are more to read. We will expand
164
+ our buffer and get EOF or a newline at the end unless the
165
+ buffer length has been changed. */
166
+ if (cc == full_size) {
168
+ str = Tcl_GetStringFromObj(esPtr->buffer, &size);
169
+ if (str[size - 1] != '\n') {
170
+ if (esPtr->umsize_changed) {
171
+ char buf[20]; /* big enough for 64bit int in hex. */
172
+ snprintf(buf,sizeof(buf),"0x%x", esPtr->umsize);
173
+ expDiagLogU("WARNING: interact buffer is not large enough to hold\r\n");
174
+ expDiagLogU("all output. probably your program is not interactive or\r\n");
175
+ expDiagLogU("has a very long output line. The current limit is ");
177
+ expDiagLogU(".\r\n");
180
+ cc = expReadNewLine(interp,esPtr,save_flags);
187
i_read_errno = errno;
190
@@ -1674,7 +1787,7 @@ int save_flags;
195
+ return count > 0 ? count : cc;
199
@@ -2751,8 +2864,14 @@ char **argv;
203
- if (Default) exp_default_match_max = size;
204
- else esPtr->umsize = size;
206
+ exp_default_match_max = size;
207
+ exp_default_match_max_changed = 1;
210
+ esPtr->umsize = size;
211
+ esPtr->umsize_changed = 1;