-
Notifications
You must be signed in to change notification settings - Fork 36
Fix execution in silent mode #407
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #407 +/- ##
==========================================
+ Coverage 82.05% 82.65% +0.60%
==========================================
Files 21 21
Lines 858 859 +1
Branches 89 89
==========================================
+ Hits 704 710 +6
+ Misses 154 149 -5
🚀 New features to boost your workflow:
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
clang-tidy made some suggestions
| auto cout_strbuf = std::cout.rdbuf(); | ||
| auto cerr_strbuf = std::cerr.rdbuf(); | ||
|
|
||
| std::unique_ptr<xnull> nullbuf; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
warning: no header providing "std::unique_ptr" is directly included [misc-include-cleaner]
src/xinterpreter.cpp:21:
- #ifndef EMSCRIPTEN
+ #include <memory>
+ #ifndef EMSCRIPTEN| auto null = xnull(); | ||
| std::cout.rdbuf(&null); | ||
| std::cerr.rdbuf(&null); | ||
| nullbuf = std::make_unique<xnull>(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
warning: no header providing "std::make_unique" is directly included [misc-include-cleaner]
nullbuf = std::make_unique<xnull>();
^There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think we can always allocate xnull before checking for the config.silent property and redirect only if this is needed. That would avoid a dynamic allocation here. Also we could take the opportunity of fixing this issue to write a small RAII object to perform the redirection.
Description
@JohanMabille and I were discussing that xeus-cpp might not be respecting how execution works in silent mode.
To confirm this I forced
config.silentas true from the xeus side. Probably the statementconfig.silent = truecan be added at the top of theexecute_request_implto verify this.In silent mode on upstream I see the kernel segfaults.

Problem
The temporary
xnullobject used whenconfig.silent = truewas destroyed at the end of the if-block, leavingstd::coutandstd::cerrwith dangling streambuf pointers. This caused signal 11 (segmentation fault) on any subsequent flush or write.Solution
Prevent segmentation fault in silent execution mode by managing the lifetime of the xnull stream buffer with a std::unique_ptr. Now works as expected
Type of change
Please tick all options which are relevant.