~ubuntu-branches/ubuntu/trusty/expect/trusty

« back to all changes in this revision

Viewing changes to debian/patches/03-spawn.patch

  • Committer: Bazaar Package Importer
  • Author(s): Sergei Golovan
  • Date: 2011-08-17 21:50:29 UTC
  • mfrom: (1.1.6 upstream)
  • Revision ID: james.westby@ubuntu.com-20110817215029-0cfarscc630tfc5v
Tags: 5.45-1
* New upstream release.
* Removed unnecessary patches.
* Removed the expectk package because expectk was dropped from the upstream
  distribution. See NEWS.Debian for possible workarounds.
* Updated package to standards version 3.9.2 (no changes needed).

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
Author: HJ Lu <hjl@lucon.org>
2
 
Description: Fixes problems when running GCCs testsuite (Closes: #156854).
3
 
 
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 */
13
 
     expAdjust(esPtr);
14
 
 
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 *));
20
 
 
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 
38
 
 #include "tcldbg.h"
39
 
 #endif
40
 
 
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"
48
 
+
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)
57
 
     return newsize;
58
 
 }
59
 
 
60
 
+/* returns # of bytes until we see a newline at the end or EOF.  */
61
 
+/*ARGSUSED*/
62
 
+static int
63
 
+expReadNewLine(interp,esPtr,save_flags) /* INTL */
64
 
+Tcl_Interp *interp;
65
 
+ExpState *esPtr;
66
 
+int save_flags;
67
 
+{
68
 
+    int size;
69
 
+    int exp_size;
70
 
+    int full_size;
71
 
+    int count;
72
 
+    char *str;
73
 
+
74
 
+    count = 0;
75
 
+    for (;;) {
76
 
+       exp_size = expSizeGet(esPtr);
77
 
+
78
 
+       /* When we reach the limit, we will only read one char at a
79
 
+          time.  */
80
 
+       if (esPtr->umsize >= EXP_MATCH_STEP_LIMIT)
81
 
+           size = TCL_UTF_MAX;
82
 
+       else
83
 
+           size = exp_size;
84
 
+
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");
93
 
+               return count;
94
 
+           }
95
 
+           else {
96
 
+               esPtr->umsize += EXP_MATCH_INC;
97
 
+               expAdjust(esPtr);
98
 
+           }
99
 
+       }
100
 
+
101
 
+       full_size = esPtr->msize - (size / TCL_UTF_MAX);
102
 
+       size = Tcl_ReadChars(esPtr->channel,
103
 
+                       esPtr->buffer,
104
 
+                       full_size,
105
 
+                       1 /* append */);
106
 
+       if (size > 0) {
107
 
+           count += size;
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')
113
 
+                   continue;
114
 
+           }
115
 
+       }
116
 
+       else {
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));
122
 
+       }
123
 
+
124
 
+       break;
125
 
+    }
126
 
+
127
 
+    return count;
128
 
+}
129
 
+
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;
134
 
 {
135
 
     int cc = EXP_TIMEOUT;
136
 
     int size = expSizeGet(esPtr);
137
 
+    int full_size;
138
 
+    int count;
139
 
 
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;
143
 
     }
144
 
 #endif
145
 
 
146
 
-    
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. */
152
 
+    count = 0;
153
 
+    full_size = esPtr->msize - (size / TCL_UTF_MAX);
154
 
     cc = Tcl_ReadChars(esPtr->channel,
155
 
-           esPtr->buffer,
156
 
-           esPtr->msize - (size / TCL_UTF_MAX),
157
 
-           1 /* append */);
158
 
+               esPtr->buffer,
159
 
+               full_size,
160
 
+               1 /* append */);
161
 
+    if (cc > 0) {
162
 
+       count += cc;
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) {
167
 
+           char *str;
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 ");
176
 
+                   expDiagLogU(buf);
177
 
+                   expDiagLogU(".\r\n");
178
 
+               }
179
 
+               else {
180
 
+                   cc = expReadNewLine(interp,esPtr,save_flags);
181
 
+                   if (cc > 0)
182
 
+                       count += cc;
183
 
+               }
184
 
+           }
185
 
+       }
186
 
+    }
187
 
     i_read_errno = errno;
188
 
 
189
 
 #ifdef SIMPLE_EVENT
190
 
@@ -1674,7 +1787,7 @@ int save_flags;
191
 
        }
192
 
     }
193
 
 #endif
194
 
-    return cc; 
195
 
+    return count > 0 ? count : cc;
196
 
 }
197
 
 
198
 
 /*
199
 
@@ -2751,8 +2864,14 @@ char **argv;
200
 
        return(TCL_ERROR);
201
 
     }
202
 
 
203
 
-    if (Default) exp_default_match_max = size;
204
 
-    else esPtr->umsize = size;
205
 
+    if (Default) {
206
 
+       exp_default_match_max = size;
207
 
+       exp_default_match_max_changed = 1;
208
 
+    }
209
 
+    else {
210
 
+       esPtr->umsize = size;
211
 
+       esPtr->umsize_changed = 1;
212
 
+    }
213
 
 
214
 
     return(TCL_OK);
215
 
 }