Skip to content

Commit 285e335

Browse files
committed
patch 8.0.1735: flexible array member feature not supported by HP-UX
Problem: Flexible array member feature not supported by HP-UX. (John Marriott) Solution: Do not use the flexible array member feature of C99.
1 parent f98a39c commit 285e335

File tree

6 files changed

+50
-75
lines changed

6 files changed

+50
-75
lines changed

runtime/doc/develop.txt

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -209,16 +209,6 @@ Types ~
209209
"long long" is allowed and can be expected to be 64 bits. Use %lld in printf
210210
formats. Also "long long unsigned" with %llu.
211211

212-
Flexible array members ~
213-
214-
This is an array without size, used as the last member of a struct. Vim used
215-
to have an array of size one, which causes trouble with FORTIFY_SOURCE. Using
216-
an "unsized array" is the intended use, we will change all of them.
217-
struct some_stuff {
218-
size_t length;
219-
char payload[]; // will have size "length"
220-
};
221-
222212
Not to be used ~
223213

224214
These C99 features are not to be used, because not enough compilers support
@@ -228,6 +218,7 @@ them:
228218
- Variable length arrays (even in C11 this is an optional feature).
229219
- _Bool and _Complex types.
230220
- "inline" (it's hardly ever needed, let the optimizer do its work)
221+
- flexible array members: Not supported by HP-UX C compiler (John Marriott)
231222

232223

233224
USE OF COMMON FUNCTIONS *style-functions*

src/auto/configure

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4188,14 +4188,10 @@ int
41884188
main ()
41894189
{
41904190
4191-
struct with_flexible_member {
4192-
int count; // comment
4193-
char text[]; // another comment
4194-
};
41954191
enum {
4196-
one,
4197-
two,
4198-
three,
4192+
one, // one comment
4193+
two, // two comments
4194+
three, // three comments
41994195
};
42004196
long long int a = 1;
42014197
long long unsigned b = 2;

src/configure.ac

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -36,14 +36,10 @@ dnl - "long long int" and "long long unsigned"
3636
dnl - flexible array member
3737
AC_MSG_CHECKING(if the compiler can handle Vim code)
3838
AC_TRY_COMPILE([#include <stdio.h>], [
39-
struct with_flexible_member {
40-
int count; // comment
41-
char text[]; // another comment
42-
};
4339
enum {
44-
one,
45-
two,
46-
three,
40+
one, // one comment
41+
two, // two comments
42+
three, // three comments
4743
};
4844
long long int a = 1;
4945
long long unsigned b = 2;

src/getchar.c

Lines changed: 39 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -40,9 +40,9 @@
4040

4141
#define MINIMAL_SIZE 20 /* minimal size for b_str */
4242

43-
static buffheader_T redobuff = {NULL, NULL, 0, 0};
44-
static buffheader_T old_redobuff = {NULL, NULL, 0, 0};
45-
static buffheader_T recordbuff = {NULL, NULL, 0, 0};
43+
static buffheader_T redobuff = {{NULL, {NUL}}, NULL, 0, 0};
44+
static buffheader_T old_redobuff = {{NULL, {NUL}}, NULL, 0, 0};
45+
static buffheader_T recordbuff = {{NULL, {NUL}}, NULL, 0, 0};
4646

4747
static int typeahead_char = 0; /* typeahead char that's not flushed */
4848

@@ -138,13 +138,12 @@ free_buff(buffheader_T *buf)
138138
{
139139
buffblock_T *p, *np;
140140

141-
for (p = buf->bh_first; p != NULL; p = np)
141+
for (p = buf->bh_first.b_next; p != NULL; p = np)
142142
{
143143
np = p->b_next;
144144
vim_free(p);
145145
}
146-
buf->bh_first = NULL;
147-
buf->bh_curr = NULL;
146+
buf->bh_first.b_next = NULL;
148147
}
149148

150149
/*
@@ -160,16 +159,16 @@ get_buffcont(
160159
char_u *p = NULL;
161160
char_u *p2;
162161
char_u *str;
163-
buffblock_T *bp;
162+
buffblock_T *bp;
164163

165164
/* compute the total length of the string */
166-
for (bp = buffer->bh_first; bp != NULL; bp = bp->b_next)
165+
for (bp = buffer->bh_first.b_next; bp != NULL; bp = bp->b_next)
167166
count += (long_u)STRLEN(bp->b_str);
168167

169168
if ((count || dozero) && (p = lalloc(count + 1, TRUE)) != NULL)
170169
{
171170
p2 = p;
172-
for (bp = buffer->bh_first; bp != NULL; bp = bp->b_next)
171+
for (bp = buffer->bh_first.b_next; bp != NULL; bp = bp->b_next)
173172
for (str = bp->b_str; *str; )
174173
*p2++ = *str++;
175174
*p2 = NUL;
@@ -233,27 +232,27 @@ add_buff(
233232
long slen) /* length of "s" or -1 */
234233
{
235234
buffblock_T *p;
236-
long_u len;
235+
long_u len;
237236

238237
if (slen < 0)
239238
slen = (long)STRLEN(s);
240239
if (slen == 0) /* don't add empty strings */
241240
return;
242241

243-
if (buf->bh_first == NULL) /* first add to list */
242+
if (buf->bh_first.b_next == NULL) /* first add to list */
244243
{
245244
buf->bh_space = 0;
246-
buf->bh_curr = NULL;
245+
buf->bh_curr = &(buf->bh_first);
247246
}
248247
else if (buf->bh_curr == NULL) /* buffer has already been read */
249248
{
250249
IEMSG(_("E222: Add to read buffer"));
251250
return;
252251
}
253252
else if (buf->bh_index != 0)
254-
mch_memmove(buf->bh_first->b_str,
255-
buf->bh_first->b_str + buf->bh_index,
256-
STRLEN(buf->bh_first->b_str + buf->bh_index) + 1);
253+
mch_memmove(buf->bh_first.b_next->b_str,
254+
buf->bh_first.b_next->b_str + buf->bh_index,
255+
STRLEN(buf->bh_first.b_next->b_str + buf->bh_index) + 1);
257256
buf->bh_index = 0;
258257

259258
if (buf->bh_space >= (int)slen)
@@ -268,25 +267,16 @@ add_buff(
268267
len = MINIMAL_SIZE;
269268
else
270269
len = slen;
271-
p = (buffblock_T *)lalloc((long_u)(sizeof(buffblock_T) + len + 1),
272-
TRUE);
270+
p = (buffblock_T *)lalloc((long_u)(sizeof(buffblock_T) + len),
271+
TRUE);
273272
if (p == NULL)
274273
return; /* no space, just forget it */
275274
buf->bh_space = (int)(len - slen);
276275
vim_strncpy(p->b_str, s, (size_t)slen);
277276

278-
if (buf->bh_curr == NULL)
279-
{
280-
p->b_next = NULL;
281-
buf->bh_first = p;
282-
buf->bh_curr = p;
283-
}
284-
else
285-
{
286-
p->b_next = buf->bh_curr->b_next;
287-
buf->bh_curr->b_next = p;
288-
buf->bh_curr = p;
289-
}
277+
p->b_next = buf->bh_curr->b_next;
278+
buf->bh_curr->b_next = p;
279+
buf->bh_curr = p;
290280
}
291281
return;
292282
}
@@ -358,10 +348,10 @@ add_char_buff(buffheader_T *buf, int c)
358348
}
359349

360350
/* First read ahead buffer. Used for translated commands. */
361-
static buffheader_T readbuf1 = {NULL, NULL, 0, 0};
351+
static buffheader_T readbuf1 = {{NULL, {NUL}}, NULL, 0, 0};
362352

363353
/* Second read ahead buffer. Used for redo. */
364-
static buffheader_T readbuf2 = {NULL, NULL, 0, 0};
354+
static buffheader_T readbuf2 = {{NULL, {NUL}}, NULL, 0, 0};
365355

366356
/*
367357
* Get one byte from the read buffers. Use readbuf1 one first, use readbuf2
@@ -386,17 +376,17 @@ read_readbuf(buffheader_T *buf, int advance)
386376
char_u c;
387377
buffblock_T *curr;
388378

389-
if (buf->bh_first == NULL) /* buffer is empty */
379+
if (buf->bh_first.b_next == NULL) /* buffer is empty */
390380
return NUL;
391381

392-
curr = buf->bh_first;
382+
curr = buf->bh_first.b_next;
393383
c = curr->b_str[buf->bh_index];
394384

395385
if (advance)
396386
{
397387
if (curr->b_str[++buf->bh_index] == NUL)
398388
{
399-
buf->bh_first = curr->b_next;
389+
buf->bh_first.b_next = curr->b_next;
400390
vim_free(curr);
401391
buf->bh_index = 0;
402392
}
@@ -410,14 +400,14 @@ read_readbuf(buffheader_T *buf, int advance)
410400
static void
411401
start_stuff(void)
412402
{
413-
if (readbuf1.bh_first != NULL)
403+
if (readbuf1.bh_first.b_next != NULL)
414404
{
415-
readbuf1.bh_curr = readbuf1.bh_first;
405+
readbuf1.bh_curr = &(readbuf1.bh_first);
416406
readbuf1.bh_space = 0;
417407
}
418-
if (readbuf2.bh_first != NULL)
408+
if (readbuf2.bh_first.b_next != NULL)
419409
{
420-
readbuf2.bh_curr = readbuf2.bh_first;
410+
readbuf2.bh_curr = &(readbuf2.bh_first);
421411
readbuf2.bh_space = 0;
422412
}
423413
}
@@ -428,8 +418,8 @@ start_stuff(void)
428418
int
429419
stuff_empty(void)
430420
{
431-
return (readbuf1.bh_first == NULL
432-
&& readbuf2.bh_first == NULL);
421+
return (readbuf1.bh_first.b_next == NULL
422+
&& readbuf2.bh_first.b_next == NULL);
433423
}
434424

435425
/*
@@ -439,7 +429,7 @@ stuff_empty(void)
439429
int
440430
readbuf1_empty(void)
441431
{
442-
return (readbuf1.bh_first == NULL);
432+
return (readbuf1.bh_first.b_next == NULL);
443433
}
444434

445435
/*
@@ -504,7 +494,7 @@ ResetRedobuff(void)
504494
{
505495
free_buff(&old_redobuff);
506496
old_redobuff = redobuff;
507-
redobuff.bh_first = NULL;
497+
redobuff.bh_first.b_next = NULL;
508498
}
509499
}
510500

@@ -519,7 +509,7 @@ CancelRedo(void)
519509
{
520510
free_buff(&redobuff);
521511
redobuff = old_redobuff;
522-
old_redobuff.bh_first = NULL;
512+
old_redobuff.bh_first.b_next = NULL;
523513
start_stuff();
524514
while (read_readbuffers(TRUE) != NUL)
525515
;
@@ -536,9 +526,9 @@ saveRedobuff(save_redo_T *save_redo)
536526
char_u *s;
537527

538528
save_redo->sr_redobuff = redobuff;
539-
redobuff.bh_first = NULL;
529+
redobuff.bh_first.b_next = NULL;
540530
save_redo->sr_old_redobuff = old_redobuff;
541-
old_redobuff.bh_first = NULL;
531+
old_redobuff.bh_first.b_next = NULL;
542532

543533
/* Make a copy, so that ":normal ." in a function works. */
544534
s = get_buffcont(&save_redo->sr_redobuff, FALSE);
@@ -757,9 +747,9 @@ read_redo(int init, int old_redo)
757747
if (init)
758748
{
759749
if (old_redo)
760-
bp = old_redobuff.bh_first;
750+
bp = old_redobuff.bh_first.b_next;
761751
else
762-
bp = redobuff.bh_first;
752+
bp = redobuff.bh_first.b_next;
763753
if (bp == NULL)
764754
return FAIL;
765755
p = bp->b_str;
@@ -1382,9 +1372,9 @@ save_typeahead(tasave_T *tp)
13821372
old_char = -1;
13831373

13841374
tp->save_readbuf1 = readbuf1;
1385-
readbuf1.bh_first = NULL;
1375+
readbuf1.bh_first.b_next = NULL;
13861376
tp->save_readbuf2 = readbuf2;
1387-
readbuf2.bh_first = NULL;
1377+
readbuf2.bh_first.b_next = NULL;
13881378
# ifdef USE_INPUT_BUF
13891379
tp->save_inputbuf = get_input_buf();
13901380
# endif

src/structs.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -511,15 +511,15 @@ typedef struct buffheader buffheader_T;
511511
struct buffblock
512512
{
513513
buffblock_T *b_next; /* pointer to next buffblock */
514-
char_u b_str[]; /* contents (flexible array) */
514+
char_u b_str[1]; /* contents (actually longer) */
515515
};
516516

517517
/*
518518
* header used for the stuff buffer and the redo buffer
519519
*/
520520
struct buffheader
521521
{
522-
buffblock_T *bh_first; /* first block of the list */
522+
buffblock_T bh_first; /* first (dummy) block of list */
523523
buffblock_T *bh_curr; /* buffblock for appending */
524524
int bh_index; /* index for reading */
525525
int bh_space; /* space in bh_curr for appending */

src/version.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -762,6 +762,8 @@ static char *(features[]) =
762762

763763
static int included_patches[] =
764764
{ /* Add new patch number below this line */
765+
/**/
766+
1735,
765767
/**/
766768
1734,
767769
/**/

0 commit comments

Comments
 (0)