public inbox for cygwin@cygwin.com
 help / color / mirror / Atom feed
From: Jacob Niehus <jacob.niehus@gmail.com>
To: cygwin@cygwin.com
Subject: cygclang.dll breaks terminal output when used in Python bindings
Date: Fri, 24 Oct 2014 20:43:00 -0000	[thread overview]
Message-ID: <CACvCDBp9DstQR87zPWjz+FD=S3Ob4M7f5+28om+u_O+WCtqj8Q@mail.gmail.com> (raw)

I use a Vim plugin called clang_complete for C/C++ code completion which
interfaces with Clang using Clang's python bindings. After updating Cygwin,
the terminal output of Vim is garbled as soon as the plugin uses the Clang
Python bindings.

I tracked down the exact revision (188615) of LLVM/Clang which cause the
problem and the diff for that revision is at the bottom of this message.
Basically it changes the way it looks up terminal capabilities in such a way
that it think Cygwin can't display colors which causes it to change terminal
output settings.

I was able to fix the problem by installing the libncurses-devel package and
recompiling LLVM/Clang. Should libncurses-devel be a dependency of libclang or
is there another way to fix this problem?

Thanks,
Jacob Niehus

--- lib/Support/Unix/Process.inc        (revision 188614)
+++ lib/Support/Unix/Process.inc        (revision 188615)
@@ -240,10 +240,12 @@
 }

 #ifdef HAVE_TERMINFO
-// We manually declare these two extern functions because finding the correct
+// We manually declare these extern functions because finding the correct
 // headers from various terminfo, curses, or other sources is harder than
 // writing their specs down.
 extern "C" int setupterm(char *term, int filedes, int *errret);
+extern "C" struct term *set_curterm(struct term *termp);
+extern "C" int del_curterm(struct term *termp);
 extern "C" int tigetnum(char *capname);
 #endif

@@ -272,7 +274,15 @@
   //
   // The 'tigetnum' routine returns -2 or -1 on errors, and might return 0 if
   // the terminfo says that no colors are supported.
-  if (tigetnum(const_cast<char *>("colors")) > 0)
+  bool HasColors = tigetnum(const_cast<char *>("colors")) > 0;
+
+  // Now extract the structure allocated by setupterm and free its memory
+  // through a really silly dance.
+  struct term *termp = set_curterm((struct term *)0);
+  (void)del_curterm(termp); // Drop any errors here.
+
+  // Return true if we found a color capabilities for the current terminal.
+  if (HasColors)
     return true;
 #endif

--
Problem reports:       http://cygwin.com/problems.html
FAQ:                   http://cygwin.com/faq/
Documentation:         http://cygwin.com/docs.html
Unsubscribe info:      http://cygwin.com/ml/#unsubscribe-simple

             reply	other threads:[~2014-10-24 20:43 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2014-10-24 20:43 Jacob Niehus [this message]
2014-10-26 20:22 ` Jacob Niehus

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to='CACvCDBp9DstQR87zPWjz+FD=S3Ob4M7f5+28om+u_O+WCtqj8Q@mail.gmail.com' \
    --to=jacob.niehus@gmail.com \
    --cc=cygwin@cygwin.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).