2018-04-19 0:01 GMT+03:00 Bram Moolenaar <[email protected]>:
>
> Patch 8.0.1735 (after 8.0.1723 and 8.0.1730)
> Problem: Flexible array member feature not supported by HP-UX. (John
> Marriott)
> Solution: Do not use the flexible array member feature of C99.
> Files: src/configure.ac, src/auto/configure, src/structs.h,
> src/getchar.c, runtime/doc/develop.txt
>
>
> *** ../vim-8.0.1734/src/configure.ac 2018-04-17 22:02:17.581386402 +0200
> --- src/configure.ac 2018-04-18 22:54:56.327241046 +0200
> ***************
> *** 36,49 ****
> dnl - flexible array member
> AC_MSG_CHECKING(if the compiler can handle Vim code)
> AC_TRY_COMPILE([#include <stdio.h>], [
> - struct with_flexible_member {
> - int count; // comment
> - char text[]; // another comment
> - };
> enum {
> ! one,
> ! two,
> ! three,
> };
> long long int a = 1;
> long long unsigned b = 2;
> --- 36,45 ----
> dnl - flexible array member
> AC_MSG_CHECKING(if the compiler can handle Vim code)
> AC_TRY_COMPILE([#include <stdio.h>], [
> enum {
> ! one, // one comment
> ! two, // two comments
> ! three, // three comments
> };
> long long int a = 1;
> long long unsigned b = 2;
> *** ../vim-8.0.1734/src/auto/configure 2018-04-17 22:02:17.585386375 +0200
> --- src/auto/configure 2018-04-18 22:54:59.907214537 +0200
> ***************
> *** 4188,4201 ****
> main ()
> {
>
> - struct with_flexible_member {
> - int count; // comment
> - char text[]; // another comment
> - };
> enum {
> ! one,
> ! two,
> ! three,
> };
> long long int a = 1;
> long long unsigned b = 2;
> --- 4188,4197 ----
> main ()
> {
>
> enum {
> ! one, // one comment
> ! two, // two comments
> ! three, // three comments
> };
> long long int a = 1;
> long long unsigned b = 2;
> *** ../vim-8.0.1734/src/structs.h 2018-04-17 20:14:35.831140930 +0200
> --- src/structs.h 2018-04-18 22:52:30.540326298 +0200
> ***************
> *** 511,517 ****
> struct buffblock
> {
> buffblock_T *b_next; /* pointer to next buffblock */
> ! char_u b_str[]; /* contents (flexible array) */
> };
>
> /*
> --- 511,517 ----
> struct buffblock
> {
> buffblock_T *b_next; /* pointer to next buffblock */
> ! char_u b_str[1]; /* contents (actually longer) */
Why not just stuff a macros here which will expand to 1 or nothing,
depending on configure check for flexible array members support?
_FORTIFY_SOURCE point still stands and macros name is a nice
replacement for “actually longer” comment.
> };
>
> /*
> ***************
> *** 519,525 ****
> */
> struct buffheader
> {
> ! buffblock_T *bh_first; /* first block of the list */
> buffblock_T *bh_curr; /* buffblock for appending */
> int bh_index; /* index for reading */
> int bh_space; /* space in bh_curr for appending */
> --- 519,525 ----
> */
> struct buffheader
> {
> ! buffblock_T bh_first; /* first (dummy) block of list */
> buffblock_T *bh_curr; /* buffblock for appending */
> int bh_index; /* index for reading */
> int bh_space; /* space in bh_curr for appending */
> *** ../vim-8.0.1734/src/getchar.c 2018-04-16 14:45:41.020162889 +0200
> --- src/getchar.c 2018-04-18 22:52:32.188313962 +0200
> ***************
> *** 40,48 ****
>
> #define MINIMAL_SIZE 20 /* minimal size for b_str */
>
> ! static buffheader_T redobuff = {NULL, NULL, 0, 0};
> ! static buffheader_T old_redobuff = {NULL, NULL, 0, 0};
> ! static buffheader_T recordbuff = {NULL, NULL, 0, 0};
>
> static int typeahead_char = 0; /* typeahead char that's not
> flushed */
>
> --- 40,48 ----
>
> #define MINIMAL_SIZE 20 /* minimal size for b_str */
>
> ! static buffheader_T redobuff = {{NULL, {NUL}}, NULL, 0, 0};
> ! static buffheader_T old_redobuff = {{NULL, {NUL}}, NULL, 0, 0};
> ! static buffheader_T recordbuff = {{NULL, {NUL}}, NULL, 0, 0};
>
> static int typeahead_char = 0; /* typeahead char that's not
> flushed */
>
> ***************
> *** 138,150 ****
> {
> buffblock_T *p, *np;
>
> ! for (p = buf->bh_first; p != NULL; p = np)
> {
> np = p->b_next;
> vim_free(p);
> }
> ! buf->bh_first = NULL;
> ! buf->bh_curr = NULL;
> }
>
> /*
> --- 138,149 ----
> {
> buffblock_T *p, *np;
>
> ! for (p = buf->bh_first.b_next; p != NULL; p = np)
> {
> np = p->b_next;
> vim_free(p);
> }
> ! buf->bh_first.b_next = NULL;
> }
>
> /*
> ***************
> *** 160,175 ****
> char_u *p = NULL;
> char_u *p2;
> char_u *str;
> ! buffblock_T *bp;
>
> /* compute the total length of the string */
> ! for (bp = buffer->bh_first; bp != NULL; bp = bp->b_next)
> count += (long_u)STRLEN(bp->b_str);
>
> if ((count || dozero) && (p = lalloc(count + 1, TRUE)) != NULL)
> {
> p2 = p;
> ! for (bp = buffer->bh_first; bp != NULL; bp = bp->b_next)
> for (str = bp->b_str; *str; )
> *p2++ = *str++;
> *p2 = NUL;
> --- 159,174 ----
> char_u *p = NULL;
> char_u *p2;
> char_u *str;
> ! buffblock_T *bp;
>
> /* compute the total length of the string */
> ! for (bp = buffer->bh_first.b_next; bp != NULL; bp = bp->b_next)
> count += (long_u)STRLEN(bp->b_str);
>
> if ((count || dozero) && (p = lalloc(count + 1, TRUE)) != NULL)
> {
> p2 = p;
> ! for (bp = buffer->bh_first.b_next; bp != NULL; bp = bp->b_next)
> for (str = bp->b_str; *str; )
> *p2++ = *str++;
> *p2 = NUL;
> ***************
> *** 233,249 ****
> long slen) /* length of "s" or -1 */
> {
> buffblock_T *p;
> ! long_u len;
>
> if (slen < 0)
> slen = (long)STRLEN(s);
> if (slen == 0) /* don't add empty strings */
> return;
>
> ! if (buf->bh_first == NULL) /* first add to list */
> {
> buf->bh_space = 0;
> ! buf->bh_curr = NULL;
> }
> else if (buf->bh_curr == NULL) /* buffer has already been read */
> {
> --- 232,248 ----
> long slen) /* length of "s" or -1 */
> {
> buffblock_T *p;
> ! long_u len;
>
> if (slen < 0)
> slen = (long)STRLEN(s);
> if (slen == 0) /* don't add empty strings */
> return;
>
> ! if (buf->bh_first.b_next == NULL) /* first add to list */
> {
> buf->bh_space = 0;
> ! buf->bh_curr = &(buf->bh_first);
> }
> else if (buf->bh_curr == NULL) /* buffer has already been read */
> {
> ***************
> *** 251,259 ****
> return;
> }
> else if (buf->bh_index != 0)
> ! mch_memmove(buf->bh_first->b_str,
> ! buf->bh_first->b_str + buf->bh_index,
> ! STRLEN(buf->bh_first->b_str + buf->bh_index) + 1);
> buf->bh_index = 0;
>
> if (buf->bh_space >= (int)slen)
> --- 250,258 ----
> return;
> }
> else if (buf->bh_index != 0)
> ! mch_memmove(buf->bh_first.b_next->b_str,
> ! buf->bh_first.b_next->b_str + buf->bh_index,
> ! STRLEN(buf->bh_first.b_next->b_str + buf->bh_index) + 1);
> buf->bh_index = 0;
>
> if (buf->bh_space >= (int)slen)
> ***************
> *** 268,292 ****
> len = MINIMAL_SIZE;
> else
> len = slen;
> ! p = (buffblock_T *)lalloc((long_u)(sizeof(buffblock_T) + len + 1),
> !
> TRUE);
> if (p == NULL)
> return; /* no space, just forget it */
> buf->bh_space = (int)(len - slen);
> vim_strncpy(p->b_str, s, (size_t)slen);
>
> ! if (buf->bh_curr == NULL)
> ! {
> ! p->b_next = NULL;
> ! buf->bh_first = p;
> ! buf->bh_curr = p;
> ! }
> ! else
> ! {
> ! p->b_next = buf->bh_curr->b_next;
> ! buf->bh_curr->b_next = p;
> ! buf->bh_curr = p;
> ! }
> }
> return;
> }
> --- 267,282 ----
> len = MINIMAL_SIZE;
> else
> len = slen;
> ! p = (buffblock_T *)lalloc((long_u)(sizeof(buffblock_T) + len),
> ! TRUE);
> if (p == NULL)
> return; /* no space, just forget it */
> buf->bh_space = (int)(len - slen);
> vim_strncpy(p->b_str, s, (size_t)slen);
>
> ! p->b_next = buf->bh_curr->b_next;
> ! buf->bh_curr->b_next = p;
> ! buf->bh_curr = p;
> }
> return;
> }
> ***************
> *** 358,367 ****
> }
>
> /* First read ahead buffer. Used for translated commands. */
> ! static buffheader_T readbuf1 = {NULL, NULL, 0, 0};
>
> /* Second read ahead buffer. Used for redo. */
> ! static buffheader_T readbuf2 = {NULL, NULL, 0, 0};
>
> /*
> * Get one byte from the read buffers. Use readbuf1 one first, use readbuf2
> --- 348,357 ----
> }
>
> /* First read ahead buffer. Used for translated commands. */
> ! static buffheader_T readbuf1 = {{NULL, {NUL}}, NULL, 0, 0};
>
> /* Second read ahead buffer. Used for redo. */
> ! static buffheader_T readbuf2 = {{NULL, {NUL}}, NULL, 0, 0};
>
> /*
> * Get one byte from the read buffers. Use readbuf1 one first, use readbuf2
> ***************
> *** 386,402 ****
> char_u c;
> buffblock_T *curr;
>
> ! if (buf->bh_first == NULL) /* buffer is empty */
> return NUL;
>
> ! curr = buf->bh_first;
> c = curr->b_str[buf->bh_index];
>
> if (advance)
> {
> if (curr->b_str[++buf->bh_index] == NUL)
> {
> ! buf->bh_first = curr->b_next;
> vim_free(curr);
> buf->bh_index = 0;
> }
> --- 376,392 ----
> char_u c;
> buffblock_T *curr;
>
> ! if (buf->bh_first.b_next == NULL) /* buffer is empty */
> return NUL;
>
> ! curr = buf->bh_first.b_next;
> c = curr->b_str[buf->bh_index];
>
> if (advance)
> {
> if (curr->b_str[++buf->bh_index] == NUL)
> {
> ! buf->bh_first.b_next = curr->b_next;
> vim_free(curr);
> buf->bh_index = 0;
> }
> ***************
> *** 410,423 ****
> static void
> start_stuff(void)
> {
> ! if (readbuf1.bh_first != NULL)
> {
> ! readbuf1.bh_curr = readbuf1.bh_first;
> readbuf1.bh_space = 0;
> }
> ! if (readbuf2.bh_first != NULL)
> {
> ! readbuf2.bh_curr = readbuf2.bh_first;
> readbuf2.bh_space = 0;
> }
> }
> --- 400,413 ----
> static void
> start_stuff(void)
> {
> ! if (readbuf1.bh_first.b_next != NULL)
> {
> ! readbuf1.bh_curr = &(readbuf1.bh_first);
> readbuf1.bh_space = 0;
> }
> ! if (readbuf2.bh_first.b_next != NULL)
> {
> ! readbuf2.bh_curr = &(readbuf2.bh_first);
> readbuf2.bh_space = 0;
> }
> }
> ***************
> *** 428,435 ****
> int
> stuff_empty(void)
> {
> ! return (readbuf1.bh_first == NULL
> ! && readbuf2.bh_first == NULL);
> }
>
> /*
> --- 418,425 ----
> int
> stuff_empty(void)
> {
> ! return (readbuf1.bh_first.b_next == NULL
> ! && readbuf2.bh_first.b_next == NULL);
> }
>
> /*
> ***************
> *** 439,445 ****
> int
> readbuf1_empty(void)
> {
> ! return (readbuf1.bh_first == NULL);
> }
>
> /*
> --- 429,435 ----
> int
> readbuf1_empty(void)
> {
> ! return (readbuf1.bh_first.b_next == NULL);
> }
>
> /*
> ***************
> *** 504,510 ****
> {
> free_buff(&old_redobuff);
> old_redobuff = redobuff;
> ! redobuff.bh_first = NULL;
> }
> }
>
> --- 494,500 ----
> {
> free_buff(&old_redobuff);
> old_redobuff = redobuff;
> ! redobuff.bh_first.b_next = NULL;
> }
> }
>
> ***************
> *** 519,525 ****
> {
> free_buff(&redobuff);
> redobuff = old_redobuff;
> ! old_redobuff.bh_first = NULL;
> start_stuff();
> while (read_readbuffers(TRUE) != NUL)
> ;
> --- 509,515 ----
> {
> free_buff(&redobuff);
> redobuff = old_redobuff;
> ! old_redobuff.bh_first.b_next = NULL;
> start_stuff();
> while (read_readbuffers(TRUE) != NUL)
> ;
> ***************
> *** 536,544 ****
> char_u *s;
>
> save_redo->sr_redobuff = redobuff;
> ! redobuff.bh_first = NULL;
> save_redo->sr_old_redobuff = old_redobuff;
> ! old_redobuff.bh_first = NULL;
>
> /* Make a copy, so that ":normal ." in a function works. */
> s = get_buffcont(&save_redo->sr_redobuff, FALSE);
> --- 526,534 ----
> char_u *s;
>
> save_redo->sr_redobuff = redobuff;
> ! redobuff.bh_first.b_next = NULL;
> save_redo->sr_old_redobuff = old_redobuff;
> ! old_redobuff.bh_first.b_next = NULL;
>
> /* Make a copy, so that ":normal ." in a function works. */
> s = get_buffcont(&save_redo->sr_redobuff, FALSE);
> ***************
> *** 757,765 ****
> if (init)
> {
> if (old_redo)
> ! bp = old_redobuff.bh_first;
> else
> ! bp = redobuff.bh_first;
> if (bp == NULL)
> return FAIL;
> p = bp->b_str;
> --- 747,755 ----
> if (init)
> {
> if (old_redo)
> ! bp = old_redobuff.bh_first.b_next;
> else
> ! bp = redobuff.bh_first.b_next;
> if (bp == NULL)
> return FAIL;
> p = bp->b_str;
> ***************
> *** 1382,1390 ****
> old_char = -1;
>
> tp->save_readbuf1 = readbuf1;
> ! readbuf1.bh_first = NULL;
> tp->save_readbuf2 = readbuf2;
> ! readbuf2.bh_first = NULL;
> # ifdef USE_INPUT_BUF
> tp->save_inputbuf = get_input_buf();
> # endif
> --- 1372,1380 ----
> old_char = -1;
>
> tp->save_readbuf1 = readbuf1;
> ! readbuf1.bh_first.b_next = NULL;
> tp->save_readbuf2 = readbuf2;
> ! readbuf2.bh_first.b_next = NULL;
> # ifdef USE_INPUT_BUF
> tp->save_inputbuf = get_input_buf();
> # endif
> *** ../vim-8.0.1734/runtime/doc/develop.txt 2018-04-17 22:02:17.589386346
> +0200
> --- runtime/doc/develop.txt 2018-04-18 22:49:13.589814701 +0200
> ***************
> *** 209,224 ****
> "long long" is allowed and can be expected to be 64 bits. Use %lld in
> printf
> formats. Also "long long unsigned" with %llu.
>
> - Flexible array members ~
> -
> - This is an array without size, used as the last member of a struct. Vim
> used
> - to have an array of size one, which causes trouble with FORTIFY_SOURCE.
> Using
> - an "unsized array" is the intended use, we will change all of them.
> - struct some_stuff {
> - size_t length;
> - char payload[]; // will have size "length"
> - };
> -
> Not to be used ~
>
> These C99 features are not to be used, because not enough compilers support
> --- 209,214 ----
> ***************
> *** 228,233 ****
> --- 218,224 ----
> - Variable length arrays (even in C11 this is an optional feature).
> - _Bool and _Complex types.
> - "inline" (it's hardly ever needed, let the optimizer do its work)
> + - flexible array members: Not supported by HP-UX C compiler (John Marriott)
>
>
> USE OF COMMON FUNCTIONS
> *style-functions*
> *** ../vim-8.0.1734/src/version.c 2018-04-18 22:18:18.895174155 +0200
> --- src/version.c 2018-04-18 22:58:46.725545670 +0200
> ***************
> *** 764,765 ****
> --- 764,767 ----
> { /* Add new patch number below this line */
> + /**/
> + 1735,
> /**/
>
> --
> hundred-and-one symptoms of being an internet addict:
> 221. Your wife melts your keyboard in the oven.
>
> /// Bram Moolenaar -- [email protected] -- http://www.Moolenaar.net \\\
> /// sponsor Vim, vote for features -- http://www.Vim.org/sponsor/ \\\
> \\\ an exciting new programming language -- http://www.Zimbu.org ///
> \\\ help me help AIDS victims -- http://ICCF-Holland.org ///
>
> --
> --
> You received this message from the "vim_dev" maillist.
> Do not top-post! Type your reply below the text you are replying to.
> For more information, visit http://www.vim.org/maillist.php
>
> ---
> You received this message because you are subscribed to the Google Groups
> "vim_dev" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to [email protected].
> For more options, visit https://groups.google.com/d/optout.
--
--
You received this message from the "vim_dev" maillist.
Do not top-post! Type your reply below the text you are replying to.
For more information, visit http://www.vim.org/maillist.php
---
You received this message because you are subscribed to the Google Groups
"vim_dev" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
For more options, visit https://groups.google.com/d/optout.