[clang] [libclang/python] Expose Rewriter to the python binding (PR #77269)

Craig Hesling via cfe-commits cfe-commits at lists.llvm.org
Mon Jan 22 23:23:34 PST 2024


linux4life798 wrote:

I don't think this needs to block this change, but another concern I have about this API is that it is writing to stdout from C++ intermixed with Python writing to its own buffered stdout. This means that the user may see inconsistent output. This is somewhat a deficiency of [libclang Rewrite API](https://clang.llvm.org/doxygen/Rewrite_8h.html), since there is only one specific function to "write the main file out" and that is through stdout.

In an attempt to keep the world consistent, we may want to consider flushing the Python stdout buffer (`sys.stdout.flush()`) before calling `clang_CXRewriter_writeMainFileToStdOut`. I would hope that `clang_CXRewriter_writeMainFileToStdOut` flushes its own C++ stdout buffer after writing the file contents, but I honestly haven't looked at the code.

https://github.com/llvm/llvm-project/pull/77269


More information about the cfe-commits mailing list