Two fixes for pretty-print.c for mingw-w64

Message ID 3d84c0e9-6684-e74b-08e5-afc4b57acee4@126.com
State New
Headers show
Series
  • Two fixes for pretty-print.c for mingw-w64
Related show

Commit Message

Liu Hao Aug. 14, 2018, 5:54 a.m.
The two patches attached have addressed two issues in the ANSI escape 
sequence translator I sent before.  Please review, and consider 
backporting these to gcc-8-branch.




commit 5e79ccaa625169fcaca5847feff0ee168cbad83f (HEAD -> makepkg)
Author: Liu Hao <lh_mouse@126.com>
Date:   Tue Aug 14 12:22:08 2018 +0800

     gcc/pretty-print.c: Make reverse video work for non-DBCS environments.

     `COMMON_LVB_REVERSE_VIDEO` only works for DBCS environments (such
     as CJK charsets). As it is unreliable, we swap the foreground and
     background by hand if this flag is set.

     Signed-off-by: Liu Hao <lh_mouse@126.com>


commit a250716957205fee0de3553f318d04b9bfc1f35f
Author: Liu Hao <lh_mouse@126.com>
Date:   Tue Aug 14 12:13:32 2018 +0800

     gcc/pretty-print.c: Do not call `_close()` on the handle returned 
by `_get_osfhandle()`.

     Microsoft documentation about `_get_osfhandle()` is misleading. It
     shouldn't have mentioned that the handle can be closed in such a
     way, as the handle is automatically closed when the associated
     `FILE *` or FD is closed. Under no circumstance does it make any
     sense to `_close()` it by hand.

     The non-debug versions of MSVCRT and UCRTBASE tolerate such errors,
     but with the debug version of UCRTBASE an assertion is triggered.

     Reference: 
https://docs.microsoft.com/en-us/cpp/c-runtime-library/reference/get-osfhandle
     Signed-off-by: Liu Hao <lh_mouse@126.com>





-- 
Best regards,
LH_Mouse
From a250716957205fee0de3553f318d04b9bfc1f35f Mon Sep 17 00:00:00 2001
From: Liu Hao <lh_mouse@126.com>
Date: Tue, 14 Aug 2018 12:13:32 +0800
Subject: [PATCH 1/2] gcc/pretty-print.c: Do not call `_close()` on the handle
 returned by `_get_osfhandle()`.

Microsoft documentation about `_get_osfhandle()` is misleading. It
shouldn't have mentioned that the handle can be closed in such a
way, as the handle is automatically closed when the associated
`FILE *` or FD is closed. Under no circumstance does it make any
sense to `_close()` it by hand.

The non-debug versions of MSVCRT and UCRTBASE tolerate such errors,
but with the debug version of UCRTBASE an assertion is triggered.

Reference: https://docs.microsoft.com/en-us/cpp/c-runtime-library/reference/get-osfhandle
Signed-off-by: Liu Hao <lh_mouse@126.com>
---
 gcc/pretty-print.c | 1 -
 1 file changed, 1 deletion(-)

Comments

Liu Hao Aug. 14, 2018, 5:55 a.m. | #1
在 2018/8/14 13:54, Liu Hao 写道:
> The two patches attached have addressed two issues in the ANSI escape 

> sequence translator I sent before.  Please review, and consider 

> backporting these to gcc-8-branch.

> 

> 

> 

> 


And here are SVN changelogs for these two patches, in this order:



* gcc/pretty-print.c (mingw_ansi_fputs): Do not call _close() on the handle
returned by _get_osf_handle().



* gcc/pretty-print.c (eat_esc_sequence): Swap the foreground and background
colors if the COMMON_LVB_REVERSE_VIDEO flag is set, and clear it thereafter,
as it only works for DBCS.



-- 
Best regards,
LH_Mouse
JonY Aug. 14, 2018, 9:49 a.m. | #2
On 08/14/2018 05:55 AM, Liu Hao wrote:
> 在 2018/8/14 13:54, Liu Hao 写道:

>> The two patches attached have addressed two issues in the ANSI escape

>> sequence translator I sent before.  Please review, and consider

>> backporting these to gcc-8-branch.

>>

>>

>>

>>

> 

> And here are SVN changelogs for these two patches, in this order:

> 

> 

> 

> * gcc/pretty-print.c (mingw_ansi_fputs): Do not call _close() on the handle

> returned by _get_osf_handle().

> 

> 

> 

> * gcc/pretty-print.c (eat_esc_sequence): Swap the foreground and background

> colors if the COMMON_LVB_REVERSE_VIDEO flag is set, and clear it

> thereafter,

> as it only works for DBCS.

> 

> 

> 


Patch and log looks OK.

Patch

diff --git a/gcc/pretty-print.c b/gcc/pretty-print.c
index 736af8f7735..31eb8893f2a 100644
--- a/gcc/pretty-print.c
+++ b/gcc/pretty-print.c
@@ -684,7 +684,6 @@  mingw_ansi_fputs (const char *str, FILE *fp)
     /* If it is not a console, write everything as-is.  */
     write_all (h, read, strlen (read));
 
-  _close ((intptr_t) h);
   return 1;
 }