bug-gnulib
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: getting EBADF on MSVC


From: Bruno Haible
Subject: Re: getting EBADF on MSVC
Date: Tue, 20 Sep 2011 03:19:08 +0200
User-agent: KMail/1.13.6 (Linux/2.6.37.6-0.5-desktop; KDE/4.6.0; x86_64; ; )

Paul Eggert wrote:
> Emacs doesn't indent code properly when
> those macros are used.  For example, if I put the cursor at the start
> of the next line and type TAB, Emacs indents the next line by two more
> than it should.  If I put a semicolon after DONE_MSVC_INVAL, Emacs
> indents properly.

Indeed, Emacs and vim both indent better when the semicolon is present.
Whereas for the indenter of kate and Eclipse, it makes no difference.

I'm therefore adding the semicolon:


2011-09-19  Bruno Haible  <address@hidden>

        msvc-inval: Require a semicolon after DONE_MSVC_INVAL.
        * lib/msvc-inval.h (TRY_MSVC_INVAL, DONE_MSVC_INVAL): Wrap in a
        do...while(0).
        * lib/dup2.c (rpl_dup2): Add a semicolon after DONE_MSVC_INVAL.
        Suggested by Paul Eggert.

--- lib/dup2.c.orig     Tue Sep 20 03:16:07 2011
+++ lib/dup2.c  Tue Sep 20 03:07:54 2011
@@ -57,7 +57,7 @@
         {
           handle = INVALID_HANDLE_VALUE;
         }
-      DONE_MSVC_INVAL
+      DONE_MSVC_INVAL;
 
       if (handle == INVALID_HANDLE_VALUE)
         {
@@ -88,7 +88,7 @@
       result = -1;
       errno = EBADF;
     }
-  DONE_MSVC_INVAL
+  DONE_MSVC_INVAL;
 
 # ifdef __linux__
   /* Correct a Linux return value.
--- lib/msvc-inval.h.orig       Tue Sep 20 03:16:07 2011
+++ lib/msvc-inval.h    Tue Sep 20 03:11:06 2011
@@ -36,7 +36,7 @@
          <Code that handles an invalid parameter notification
           but does not do 'return', 'break', 'continue', nor 'goto'.>
        }
-     DONE_MSVC_INVAL
+     DONE_MSVC_INVAL;
 
    This entire block expands to a single statement.
  */
@@ -79,15 +79,17 @@
 #  endif
 
 #  define TRY_MSVC_INVAL \
-     {                                                                         
\
-       gl_msvc_inval_ensure_handler ();                                        
\
-       __try
+     do                                                                        
\
+       {                                                                       
\
+         gl_msvc_inval_ensure_handler ();                                      
\
+         __try
 #  define CATCH_MSVC_INVAL \
-       __except (GetExceptionCode () == STATUS_GNULIB_INVALID_PARAMETER        
\
-                 ? EXCEPTION_EXECUTE_HANDLER                                   
\
-                 : EXCEPTION_CONTINUE_SEARCH)
+         __except (GetExceptionCode () == STATUS_GNULIB_INVALID_PARAMETER      
\
+                   ? EXCEPTION_EXECUTE_HANDLER                                 
\
+                   : EXCEPTION_CONTINUE_SEARCH)
 #  define DONE_MSVC_INVAL \
-     }
+       }                                                                       
\
+     while (0)
 
 # else
 /* Any compiler.
@@ -119,27 +121,29 @@
 #  endif
 
 #  define TRY_MSVC_INVAL \
-     {                                                                         
\
-       _invalid_parameter_handler orig_handler;                                
\
-       /* First, initialize gl_msvc_inval_restart.  */                         
\
-       if (setjmp (gl_msvc_inval_restart) == 0)                                
\
-         {                                                                     
\
-           /* Then, enable gl_msvc_invalid_parameter_handler.  */              
\
-           orig_handler =                                                      
\
-             _set_invalid_parameter_handler 
(gl_msvc_invalid_parameter_handler);
+     do                                                                        
\
+       {                                                                       
\
+         _invalid_parameter_handler orig_handler;                              
\
+         /* First, initialize gl_msvc_inval_restart.  */                       
\
+         if (setjmp (gl_msvc_inval_restart) == 0)                              
\
+           {                                                                   
\
+             /* Then, enable gl_msvc_invalid_parameter_handler.  */            
\
+             orig_handler =                                                    
\
+               _set_invalid_parameter_handler 
(gl_msvc_invalid_parameter_handler);
 #  define CATCH_MSVC_INVAL \
-           /* Execution completed.                                             
\
-              Disable gl_msvc_invalid_parameter_handler.  */                   
\
-           _set_invalid_parameter_handler (orig_handler);                      
\
-         }                                                                     
\
-       else                                                                    
\
-         {                                                                     
\
-           /* Execution triggered an invalid parameter notification.           
\
-              Disable gl_msvc_invalid_parameter_handler.  */                   
\
-           _set_invalid_parameter_handler (orig_handler);
+             /* Execution completed.                                           
\
+                Disable gl_msvc_invalid_parameter_handler.  */                 
\
+             _set_invalid_parameter_handler (orig_handler);                    
\
+           }                                                                   
\
+         else                                                                  
\
+           {                                                                   
\
+             /* Execution triggered an invalid parameter notification.         
\
+                Disable gl_msvc_invalid_parameter_handler.  */                 
\
+             _set_invalid_parameter_handler (orig_handler);
 #  define DONE_MSVC_INVAL \
-         }                                                                     
\
-     }
+           }                                                                   
\
+       }                                                                       
\
+     while (0)
 
 # endif
 
@@ -148,9 +152,15 @@
 
 /* The braces here avoid GCC warnings like
    "warning: suggest explicit braces to avoid ambiguous `else'".  */
-# define TRY_MSVC_INVAL { if (1)
-# define CATCH_MSVC_INVAL else
-# define DONE_MSVC_INVAL }
+# define TRY_MSVC_INVAL \
+    do                                                                         
\
+      {                                                                        
\
+        if (1)
+# define CATCH_MSVC_INVAL \
+        else
+# define DONE_MSVC_INVAL \
+      }                                                                        
\
+    while (0)
 
 #endif
 
-- 
In memoriam James A. Garfield <http://en.wikipedia.org/wiki/James_A._Garfield>



reply via email to

[Prev in Thread] Current Thread [Next in Thread]