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

2018-08-14 Thread JonY
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.




signature.asc
Description: OpenPGP digital signature


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

2018-08-13 Thread Liu Hao

在 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



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

2018-08-13 Thread 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.





commit 5e79ccaa625169fcaca5847feff0ee168cbad83f (HEAD -> makepkg)
Author: Liu Hao 
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 

commit a250716957205fee0de3553f318d04b9bfc1f35f
Author: Liu Hao 
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 




--
Best regards,
LH_Mouse
From a250716957205fee0de3553f318d04b9bfc1f35f Mon Sep 17 00:00:00 2001
From: Liu Hao 
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 
---
 gcc/pretty-print.c | 1 -
 1 file changed, 1 deletion(-)

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;
 }
 
-- 
2.18.0

From 5e79ccaa625169fcaca5847feff0ee168cbad83f Mon Sep 17 00:00:00 2001
From: Liu Hao 
Date: Tue, 14 Aug 2018 12:22:08 +0800
Subject: [PATCH 2/2] 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 
---
 gcc/pretty-print.c | 10 ++
 1 file changed, 10 insertions(+)

diff --git a/gcc/pretty-print.c b/gcc/pretty-print.c
index 31eb8893f2a..02967d05f75 100644
--- a/gcc/pretty-print.c
+++ b/gcc/pretty-print.c
@@ -640,6 +640,16 @@ sgr_set_it:
{
  attrib_add |= sb.wAttributes & ~attrib_rm;
}
+  if (attrib_add & COMMON_LVB_REVERSE_VIDEO)
+   {
+ /* COMMON_LVB_REVERSE_VIDEO is only effective for DBCS.
+  * Swap foreground and background colors by hand.
+  */
+ attrib_add = (attrib_add & 0xFF00)
+   | ((attrib_add & 0x00F0) >> 4)
+   | ((attrib_add & 0x000F) << 4);
+ attrib_add &= ~COMMON_LVB_REVERSE_VIDEO;
+   }
   SetConsoleTextAttribute (h, attrib_add);
   break;
 }
-- 
2.18.0