]> git.pld-linux.org Git - packages/gawk.git/blob - gawk-3.1.5-freewstr.patch
- patches from fedora
[packages/gawk.git] / gawk-3.1.5-freewstr.patch
1 --- gawk-3.1.5/field.c.freewstr 2007-01-15 11:02:51.000000000 +0100
2 +++ gawk-3.1.5/field.c  2007-01-15 11:21:56.000000000 +0100
3 @@ -155,6 +155,7 @@
4         ofs = force_string(OFS_node->var_value);
5         ofslen = ofs->stlen;
6         for (i = NF; i > 0; i--) {
7 +               free_wstr(fields_arr[i]);
8                 tmp = fields_arr[i];
9                 tmp = force_string(tmp);
10                 tlen += tmp->stlen;
11 @@ -922,7 +923,7 @@
12         FIELDWIDTHS[0] = 0;
13         for (i = 1; ; i++) {
14                 unsigned long int tmp;
15 -               if (i >= fw_alloc) {
16 +               if (i + 1 >= fw_alloc) {
17                         fw_alloc *= 2;
18                         erealloc(FIELDWIDTHS, int *, fw_alloc * sizeof(int), "set_FIELDWIDTHS");
19                 }
20 --- gawk-3.1.5/builtin.c.freewstr       2005-07-26 20:07:43.000000000 +0200
21 +++ gawk-3.1.5/builtin.c        2007-01-15 11:12:52.000000000 +0100
22 @@ -2089,9 +2089,9 @@
23                         }
24  
25                         free(buf);
26 -                       if (wc_indices != NULL)
27 -                               free(wc_indices);
28                 }
29 +               if (wc_indices != NULL)
30 +                       free(wc_indices);
31         } else {                /* match failed */
32                 rstart = 0;
33                 rlength = -1;
34 @@ -2462,6 +2462,8 @@
35         free(t->stptr);
36         t->stptr = buf;
37         t->stlen = textlen;
38 +       free_wstr(t);
39 +       t->flags &= ~(NUMCUR|NUMBER);
40  
41         free_temp(s);
42         if (matches > 0 && lhs) {
43 @@ -2471,7 +2473,6 @@
44                 }
45                 if (after_assign != NULL)
46                         (*after_assign)();
47 -               t->flags &= ~(NUMCUR|NUMBER);
48         }
49         if (mb_indices != NULL)
50                 free(mb_indices);
51 --- gawk-3.1.5/awk.h.freewstr   2005-07-26 20:07:43.000000000 +0200
52 +++ gawk-3.1.5/awk.h    2007-01-15 11:02:51.000000000 +0100
53 @@ -1166,6 +1166,9 @@
54  #define force_wstring(n)       str2wstr(n, NULL)
55  extern const wchar_t *wstrstr P((const wchar_t *haystack, size_t hs_len, const wchar_t *needle, size_t needle_len));
56  extern const wchar_t *wcasestrstr P((const wchar_t *haystack, size_t hs_len, const wchar_t *needle, size_t needle_len));
57 +extern void free_wstr P((NODE *n));
58 +#else
59 +#define free_wstr(NODE)        /* empty */
60  #endif
61  /* re.c */
62  extern Regexp *make_regexp P((const char *s, size_t len, int ignorecase, int dfa));
63 --- gawk-3.1.5/node.c.freewstr  2007-01-15 11:02:51.000000000 +0100
64 +++ gawk-3.1.5/node.c   2007-01-15 11:33:44.000000000 +0100
65 @@ -96,6 +96,7 @@
66                 if (! do_traditional && isnondecimal(cp, TRUE)) {
67                         n->numbr = nondec2awknum(cp, cpend - cp);
68                         n->flags |= NUMCUR;
69 +                       ptr = cpend;
70                         goto finish;
71                 }
72         }
73 @@ -218,15 +219,7 @@
74  no_malloc:
75         s->stref = 1;
76         s->flags |= STRCUR;
77 -#if defined MBS_SUPPORT
78 -       if ((s->flags & WSTRCUR) != 0) {
79 -               assert(s->wstptr != NULL);
80 -               free(s->wstptr);
81 -               s->wstptr = NULL;
82 -               s->wstlen = 0;
83 -               s->flags &= ~WSTRCUR;
84 -       }
85 -#endif
86 +       free_wstr(s);
87         return s;
88  }
89  
90 @@ -289,8 +282,14 @@
91         *r = *n;
92         r->flags &= ~(PERM|TEMP|FIELD);
93         r->flags |= MALLOC;
94 -#if defined MBS_SUPPORT
95 +#ifdef MBS_SUPPORT
96 +       /*
97 +        * DON'T call free_wstr(r) here!
98 +        * r->wstptr still points at n->wstptr's value, and we
99 +        * don't want to free it!
100 +        */
101         r->wstptr = NULL;
102 +       r->wstlen = 0;
103  #endif /* defined MBS_SUPPORT */
104         if (n->type == Node_val && (n->flags & STRCUR) != 0) {
105                 r->stref = 1;
106 @@ -346,11 +345,7 @@
107         r->stref = 1;
108         r->stptr = NULL;
109         r->stlen = 0;
110 -#if defined MBS_SUPPORT
111 -       r->wstptr = NULL;
112 -       r->wstlen = 0;
113 -       r->flags &= ~WSTRCUR;
114 -#endif /* MBS_SUPPORT */
115 +       free_wstr(r);
116  #endif /* GAWKDEBUG */
117         return r;
118  }
119 @@ -365,10 +360,11 @@
120         getnode(r);
121         r->type = Node_val;
122         r->flags = (STRING|STRCUR|MALLOC);
123 -#if defined MBS_SUPPORT
124 +#ifdef MBS_SUPPORT
125         r->wstptr = NULL;
126         r->wstlen = 0;
127 -#endif
128 +#endif /* defined MBS_SUPPORT */
129 +
130         if (flags & ALREADY_MALLOCED)
131                 r->stptr = s;
132         else {
133 @@ -512,20 +508,13 @@
134                                 return;
135                         }
136                         free(tmp->stptr);
137 -#if defined MBS_SUPPORT
138 -                       if (tmp->wstptr != NULL) {
139 -                               assert((tmp->flags & WSTRCUR) != 0);
140 -                               free(tmp->wstptr);
141 -                       }
142 -                       tmp->flags &= ~WSTRCUR;
143 -                       tmp->wstptr = NULL;
144 -                       tmp->wstlen = 0;
145 -#endif
146 +                       free_wstr(tmp);
147                 }
148                 freenode(tmp);
149                 return;
150         }
151         if ((tmp->flags & FIELD) != 0) {
152 +               free_wstr(tmp);
153                 freenode(tmp);
154                 return;
155         }
156 @@ -706,12 +695,8 @@
157                         return n;
158                 /* otherwise
159                         fall through and recompute to fill in the array */
160 -       }
161 -
162 -       if (n->wstptr != NULL) {
163 -               free(n->wstptr);
164 -               n->wstptr = NULL;
165 -               n->wstlen = 0;
166 +               if (n->wstptr != NULL) 
167 +                       free_wstr(n);
168         }
169  
170         /*
171 @@ -752,8 +737,8 @@
172                 case (size_t) -2:
173                 case (size_t) -1:
174                 case 0:
175 -                       goto done;
176 -
177 +                       count = 1;
178 +                       /* fall through */
179                 default:
180                         *wsp++ = wc;
181                         src_count -= count;
182 @@ -777,6 +762,20 @@
183         return n;
184  }
185  
186 +/* free_wstr --- release the wide string part of a node */
187 +
188 +void
189 +free_wstr(NODE *n)
190 +{
191 +       if ((n->flags & WSTRCUR) != 0) {
192 +               assert(n->wstptr != NULL);
193 +               free(n->wstptr);
194 +       }
195 +       n->wstptr = NULL;
196 +       n->wstlen = 0;
197 +       n->flags &= ~WSTRCUR;
198 +}
199 +
200  #if 0
201  static void
202  dump_wstr(FILE *fp, const wchar_t *str, size_t len)
203 --- gawk-3.1.5/dfa.c.freewstr   2007-01-15 11:13:19.000000000 +0100
204 +++ gawk-3.1.5/dfa.c    2007-01-15 11:17:44.000000000 +0100
205 @@ -516,7 +516,6 @@
206  
207    work_mbc->nchars = work_mbc->nranges = work_mbc->nch_classes = 0;
208    work_mbc->nequivs = work_mbc->ncoll_elems = 0;
209 -  work_mbc->chars = NULL;
210    work_mbc->ch_classes = NULL;
211    work_mbc->range_sts = work_mbc->range_ends = NULL;
212    work_mbc->equivs = work_mbc->coll_elems = NULL;
213 @@ -1602,8 +1601,8 @@
214    d->states[i].constraint = 0;
215    d->states[i].first_end = 0;
216  #ifdef MBS_SUPPORT
217 -  if (MB_CUR_MAX > 1)
218 -    d->states[i].mbps.nelem = 0;
219 +  d->states[i].mbps.nelem = 0;
220 +  d->states[i].mbps.elems = NULL;
221  #endif
222    for (j = 0; j < s->nelem; ++j)
223      if (d->tokens[s->elems[j].index] < 0)
224 @@ -3136,8 +3135,13 @@
225      }
226  #endif /* MBS_SUPPORT */
227  
228 -  for (i = 0; i < d->sindex; ++i)
229 +  for (i = 0; i < d->sindex; ++i) {
230      free((ptr_t) d->states[i].elems.elems);
231 +#ifdef MBS_SUPPORT
232 +    if (d->states[i].mbps.nelem > 0)
233 +      free((ptr_t) d->states[i].mbps.elems);
234 +#endif /* MBS_SUPPORT */
235 +  }
236    free((ptr_t) d->states);
237    for (i = 0; i < d->tindex; ++i)
238      if (d->follows[i].elems)
239 --- gawk-3.1.5/eval.c.freewstr  2007-01-15 11:02:51.000000000 +0100
240 +++ gawk-3.1.5/eval.c   2007-01-15 11:02:51.000000000 +0100
241 @@ -1176,13 +1176,7 @@
242                         memcpy(l->stptr + l->stlen, r->stptr, r->stlen);
243                         l->stlen += r->stlen;
244                         l->stptr[l->stlen] = '\0';
245 -#if defined MBS_SUPPORT
246 -                       if (r->wstptr != NULL)
247 -                               free(r->wstptr);
248 -                       r->wstptr = NULL;
249 -                       r->wstlen = 0;
250 -                       r->flags &= ~WSTRCUR;
251 -#endif /* MBS_SUPPORT */
252 +                       free_wstr(l);
253                 } else {
254                         char *nval;
255                         size_t nlen = l->stlen + r->stlen + 2;
This page took 0.05582 seconds and 3 git commands to generate.