vim7: macros specifying compound statements

classic Classic list List threaded Threaded
4 messages Options
Reply | Threaded
Open this post in threaded view
|

vim7: macros specifying compound statements

Walter Briscoe
The sequence "};" produces several lint reports like:
        EMSG_RET_NULL(IObuff);
                            ^
regexp.c(1533) : Warning 527: Unreachable code at token ';'

The cause is
#define EMSG_RET_NULL(m) { EMSG(m); rc_did_emsg = TRUE; return NULL; }

I would like to suggest that this tortured macro is safer as calls of it
has to be followed by a semicolon. The previous macro can sometimes be
so followed and sometimes not.
#define EMSG_RET_NULL(m) return ( EMSG(m), rc_did_emsg = TRUE, NULL )

I discount things like EMSG_RET_NULL(_("E52: Unmatched \\z(")), "help";
as unlikely to be written by anybody not trying to break code.

do { EMSG(m); rc_did_emsg = TRUE; return NULL; } while (0)
does not allow such intrusions but is likely to result in complaints
about "while (0)" being unreachable.

I suspect the following flags a redundant survivor:
Info 754: local structure member 'se_len' (line 2988, file regexp.c) not referenced

Do we need both regsave_T and save_se_T? Both had the same members.
The following patch is quiet and assumes "yes" answers my last question:

--- src/regexp.c.0      Thu Jun  2 05:24:04 2005
+++ src/regexp.c        Mon Jun  6 10:42:28 2005
@@ -322,9 +322,9 @@

 /* Used for an error (down from) vim_regcomp(): give the error message, set
  * rc_did_emsg and return NULL */
-#define EMSG_RET_NULL(m) { EMSG(m); rc_did_emsg = TRUE; return NULL; }
-#define EMSG_M_RET_NULL(m, c) { EMSG2(m, c ? "" : "\\"); rc_did_emsg = TRUE; return NULL; }
-#define EMSG_RET_FAIL(m) { EMSG(m); rc_did_emsg = TRUE; return FAIL; }
+#define EMSG_RET_NULL(m)      return ( EMSG(m), rc_did_emsg = TRUE, NULL )
+#define EMSG_M_RET_NULL(m, c) return ( EMSG2(m, c ? "" : "\\"), rc_did_emsg = TRUE, NULL )
+#define EMSG_RET_FAIL(m)      return ( EMSG(m), rc_did_emsg = TRUE, FAIL )
 #define EMSG_ONE_RET_NULL EMSG_M_RET_NULL(_("E369: invalid item in %s%%[]"), reg_magic == MAGIC_ALL)

 #define MAX_LIMIT      (32767L << 16L)
@@ -1246,20 +1246,20 @@
     {
 #ifdef FEAT_SYN_HL
        if (paren == REG_ZPAREN)
-           EMSG_RET_NULL(_("E52: Unmatched \\z("))
+           EMSG_RET_NULL(_("E52: Unmatched \\z("));
        else
 #endif
            if (paren == REG_NPAREN)
-           EMSG_M_RET_NULL(_("E53: Unmatched %s%%("), reg_magic == MAGIC_ALL)
+           EMSG_M_RET_NULL(_("E53: Unmatched %s%%("), reg_magic == MAGIC_ALL);
        else
-           EMSG_M_RET_NULL(_("E54: Unmatched %s("), reg_magic == MAGIC_ALL)
+           EMSG_M_RET_NULL(_("E54: Unmatched %s("), reg_magic == MAGIC_ALL);
     }
     else if (paren == REG_NOPAREN && peekchr() != NUL)
     {
        if (curchr == Magic(')'))
-           EMSG_M_RET_NULL(_("E55: Unmatched %s)"), reg_magic == MAGIC_ALL)
+           EMSG_M_RET_NULL(_("E55: Unmatched %s)"), reg_magic == MAGIC_ALL);
        else
-           EMSG_RET_NULL(_(e_trailing))        /* "Can't happen". */
+           EMSG_RET_NULL(_(e_trailing));       /* "Can't happen". */
        /* NOTREACHED */
     }
     /*
@@ -2985,7 +2985,6 @@
        char_u  *ptr;
        lpos_T  pos;
     } se_u;
-    int                se_len;
 } save_se_T;

 static char_u  *reg_getline __ARGS((linenr_T lnum));
--
Walter Briscoe
Reply | Threaded
Open this post in threaded view
|

Re: vim7: macros specifying compound statements

Nikolai Weibull
Walter Briscoe wrote:

> do { EMSG(m); rc_did_emsg = TRUE; return NULL; } while (0)
> does not allow such intrusions but is likely to result in complaints
> about "while (0)" being unreachable.

Hardly.  The contents of the do-while is reachable exactly once.  The
constant while statement will be optimized away by any decent compiler,
        nikolai

--
Nikolai Weibull: now available free of charge at http://bitwi.se/!
Born in Chicago, IL USA; currently residing in Gothenburg, Sweden.
main(){printf(&linux["\021%six\012\0"],(linux)["have"]+"fun"-97);}
Reply | Threaded
Open this post in threaded view
|

Re: vim7: macros specifying compound statements

Bram Moolenaar
In reply to this post by Walter Briscoe

Walter Briscoe wrote:

> The sequence "};" produces several lint reports like:
>         EMSG_RET_NULL(IObuff);
>                             ^
> regexp.c(1533) : Warning 527: Unreachable code at token ';'

That is a bogus warning, it's completely legal to have a ';' here and
it can't be something wrong in the code.

> The cause is
> #define EMSG_RET_NULL(m) { EMSG(m); rc_did_emsg = TRUE; return NULL; }
>
> I would like to suggest that this tortured macro is safer as calls of it
> has to be followed by a semicolon. The previous macro can sometimes be
> so followed and sometimes not.
> #define EMSG_RET_NULL(m) return ( EMSG(m), rc_did_emsg = TRUE, NULL )

That's a good solution.

> I suspect the following flags a redundant survivor:
> Info 754: local structure member 'se_len' (line 2988, file regexp.c)
> not referenced
>
> Do we need both regsave_T and save_se_T? Both had the same members.

It's good to have both, so that mistakes in saving one and restoring
another are detected.  I do think that se_len can be removed.

--
On the other hand, you have different fingers.
                                      -- Steven Wright

 /// Bram Moolenaar -- [hidden email] -- http://www.Moolenaar.net   \\\
///        Sponsor Vim, vote for features -- http://www.Vim.org/sponsor/ \\\
\\\              Project leader for A-A-P -- http://www.A-A-P.org        ///
 \\\     Buy LOTR 3 and help AIDS victims -- http://ICCF.nl/lotr.html   ///
Reply | Threaded
Open this post in threaded view
|

Re: vim7: macros specifying compound statements

John (Eljay) Love-Jensen
Hi everyone,

>#define EMSG_RET_NULL(m) { EMSG(m); rc_did_emsg = TRUE; return NULL; }

Change to...
#define EMSG_RET_NULL(m) do { EMSG(m); rc_did_emsg = TRUE; return NULL; } while(0)

HTH,
--Eljay