Quuxplusone / LLVMBugzillaTest

0 stars 0 forks source link

LLVM messing up NCurses-based applications #22980

Open Quuxplusone opened 9 years ago

Quuxplusone commented 9 years ago
Bugzilla Link PR22981
Status NEW
Importance P normal
Reported by Xavier Mendez (me@jmendeth.com)
Reported on 2015-03-22 06:57:58 -0700
Last modified on 2015-12-15 02:15:43 -0800
Version 3.5
Hardware PC Linux
CC chandlerc@gmail.com, dblaikie@gmail.com, llvm-bugs@lists.llvm.org, maciej.gajewski0@gmail.com, me@jmendeth.com
Fixed by commit(s)
Attachments
Blocks
Blocked by
See also

When trying to use the Clang Python bindings inside bpython, every time I loaded a TranslationUnit from source, bpython segfaulted.

I've found the problem to be in llvm::sys::Process::FileDescriptorHasColors(int). It uses terminfo to check if the file descriptor has colors, but instead of restoring the cur_term variable to its original value, it sets it to NULL. When control returns to the NCurses app (bpython), it crashes because no current terminal is set.

This is the first time I ever deal with LLVM or NCurses code, so I might be wrong. I did a search to see if this had been reported before, but I didn't find anything.

To reproduce, fire up bpython and enter:

import clang.cindex
clang.cindex.TranslationUnit.from_source("path to some C file")

You need the Clang Python bindings installed, of course.

Quuxplusone commented 8 years ago
I experience the same in C++ application. Just run this code:

#include <ncursesw/ncurses.h>

#include <clang-c/Index.h>

int main(int argc, char** argv)
{
    if (argc < 2) return 1;
    ::initscr();

    CXIndex clang_idx = clang_createIndex(0, 0);
    CXTranslationUnit clang_tu = nullptr;

    clang_tu = clang_parseTranslationUnit(
            clang_idx,
            /*argv[1]*/ nullptr,
            argv, argc, // cmndline
            nullptr, 0, // unsaved data
            clang_defaultEditingTranslationUnitOptions());

    ::endwin(); // this line will crash
        // it doesn't have to be endwin, it could be almost any other
        // curses call
}