Skip to content

Conversation

@anutosh491
Copy link
Collaborator

Description

Fixes #381

Type of change

Please tick all options which are relevant.

  • Bug fix
  • New feature
  • Added/removed dependencies
  • Required documentation updates

@anutosh491
Copy link
Collaborator Author

The Problem here

C++ error output via std::cerr appeared correctly because xeus-cpp redirects the iostream buffers to its xoutput_buffer. However, C-level error output via fprintf(stderr, ...) did not appear. Only printf(...) and fprintf(stdout, ...) worked, because StreamRedirectRAII forwarded the captured stdout stream but silently dropped the captured stderr stream during normal execution.

Hence causing this

image

@codecov-commenter
Copy link

codecov-commenter commented Nov 6, 2025

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 82.05%. Comparing base (9a4af34) to head (10d6693).

Additional details and impacted files

Impacted file tree graph

@@            Coverage Diff             @@
##             main     #402      +/-   ##
==========================================
- Coverage   82.29%   82.05%   -0.25%     
==========================================
  Files          21       21              
  Lines         853      858       +5     
  Branches       87       89       +2     
==========================================
+ Hits          702      704       +2     
- Misses        151      154       +3     
Files with missing lines Coverage Δ
src/xinterpreter.cpp 90.85% <100.00%> (+0.28%) ⬆️

... and 1 file with indirect coverage changes

Files with missing lines Coverage Δ
src/xinterpreter.cpp 90.85% <100.00%> (+0.28%) ⬆️

... and 1 file with indirect coverage changes

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

Copy link
Contributor

@github-actions github-actions bot left a 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

@anutosh491
Copy link
Collaborator Author

Fix introduced

  • StreamRedirectRAII now:

    • accepts two references (out, err)
    • begins capture in the correct order (stdout → stderr)
    • ends capture in LIFO order (stderr → stdout)
    • forwards neither inside the destructor
  • execute_request_impl now:

    • emits the captured out → std::cout and captured err → std::cerr once
    • flushes them immediately.

This fixes what we want

image

And C++ based streams worked already

image

@mcbarton
Copy link
Collaborator

mcbarton commented Nov 6, 2025

I have checked this PR, and it does solve the problem. @anutosh491 make the clang tidy and clang format workflows happy, and I will approve and take in.

@anutosh491
Copy link
Collaborator Author

I have checked this PR, and it does solve the problem. @anutosh491 make the clang tidy and clang format workflows happy, and I will approve and take in.

Thank you, I shall do that soon (afk for sometime)

We technically need to track that we should test such fixes in favour of the C Kernel whenever we end up with a framework for that. I haven't gone through all the discussion but as far as I remember, cppinterop needs to provide us with a utility to differentiate between C++ and C snippets isn't it ?

@mcbarton
Copy link
Collaborator

mcbarton commented Nov 6, 2025

I have checked this PR, and it does solve the problem. @anutosh491 make the clang tidy and clang format workflows happy, and I will approve and take in.

Thank you, I shall do that soon (afk for sometime)

We technically need to track that we should test such fixes in favour of the C Kernel whenever we end up with a framework for that. I haven't gone through all the discussion but as far as I remember, cppinterop needs to provide us with a utility to differentiate between C++ and C snippets isn't it ?

Yes, that is exactly what needs to be done to enable c kernel tests. I have already tested the other small change which would be needed in test_xcpp_kernel.py to run the c kernel tests. If you mention all the things you think the c kernel tests should be testing in the issue already open about adding c tests #394 then I can add them once the cppinterop utility is available.

Copy link
Contributor

@github-actions github-actions bot left a 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

@anutosh491
Copy link
Collaborator Author

Technically this change was made in favour of the C Kernel, but I guess we can check some redirection through a simple test like this through tests that cater to our C++ kernel.

Fails on masters but now works as can be seen through the CI.

(xeus-cpp) anutosh491@Anutoshs-MacBook-Air test % ./test_xeus_cpp 
[doctest] doctest version is "2.4.12"
[doctest] run with "--help" for options
Failed to detect the resource-dir
clang version 20.1.7
Target: arm64-apple-darwin24.5.0
Thread model: posix
InstalledDir: /Users/anutosh491/work/xeus-cpp/build/test
ignoring nonexistent directory "/Users/anutosh491/work/xeus-cpp/build/test/../include/c++/v1"
 "/Users/anutosh491/work/xeus-cpp/build/test/test_xeus_cpp" -cc1 -triple arm64-apple-macosx15.0.0 -Wundef-prefix=TARGET_OS_ -Werror=undef-prefix -Wdeprecated-objc-isa-usage -Werror=deprecated-objc-isa-usage -E -disable-free -clear-ast-before-backend -disable-llvm-verifier -discard-value-names -main-file-name "<<< inputs >>>" -mrelocation-model pic -pic-level 2 -pic-is-pie -mframe-pointer=non-leaf -ffp-contract=on -fno-rounding-math -funwind-tables=1 -target-sdk-version=15.2 -fcompatibility-qualified-id-block-type-checking -fvisibility-inlines-hidden-static-local-var -fdefine-target-os-macros -fno-modulemap-allow-subdirectory-search -target-cpu apple-m1 -target-feature +zcm -target-feature +zcz -target-feature +v8.4a -target-feature +aes -target-feature +altnzcv -target-feature +ccdp -target-feature +ccpp -target-feature +complxnum -target-feature +crc -target-feature +dotprod -target-feature +flagm -target-feature +fp-armv8 -target-feature +fp16fml -target-feature +fptoint -target-feature +fullfp16 -target-feature +jsconv -target-feature +lse -target-feature +neon -target-feature +pauth -target-feature +perfmon -target-feature +predres -target-feature +ras -target-feature +rcpc -target-feature +rdm -target-feature +sb -target-feature +sha2 -target-feature +sha3 -target-feature +specrestrict -target-feature +ssbs -target-abi darwinpcs -debugger-tuning=lldb -fdebug-compilation-dir=/Users/anutosh491/work/xeus-cpp/build/test -target-linker-version 951.9 -v -fcoverage-compilation-dir=/Users/anutosh491/work/xeus-cpp/build/test -resource-dir /Users/anutosh491/micromamba/envs/xeus-cpp -isystem /Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/usr/include/c++/v1 -isystem /Library/Developer/CommandLineTools/usr/lib/clang/16/include -isystem /Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/usr/include -isystem /Library/Developer/CommandLineTools/usr/include -isystem "/Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/System/Library/Frameworks (framework directory)" -isysroot /Library/Developer/CommandLineTools/SDKs/MacOSX.sdk -internal-isystem /Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/usr/include/c++/v1 -internal-isystem /Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/usr/local/include -internal-isystem /Users/anutosh491/micromamba/envs/xeus-cpp/include -internal-externc-isystem /Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/usr/include -std=c++14 -fdeprecated-macro -ferror-limit 19 -stack-protector 1 -fblocks -fencode-extended-block-signature -fregister-global-dtors-with-atexit -fgnuc-version=4.2.1 -fskip-odr-check-in-gmf -fcxx-exceptions -fexceptions -fmax-type-align=16 -fcolor-diagnostics -fincremental-extensions -D__GCC_HAVE_DWARF2_CFI_ASM=1 -o - -x c++ "<<< inputs >>>"
clang -cc1 version 20.1.7 based upon LLVM 20.1.7 default target arm64-apple-darwin24.5.0
ignoring nonexistent directory "/Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/System/Library/Frameworks (framework directory)"
ignoring nonexistent directory "/Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/usr/local/include"
ignoring nonexistent directory "/Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/System/Library/SubFrameworks"
ignoring nonexistent directory "/Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/Library/Frameworks"
ignoring duplicate directory "/Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/usr/include/c++/v1"
ignoring duplicate directory "/Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/usr/include"
#include "..." search starts here:
#include <...> search starts here:
 /Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/usr/include/c++/v1
 /Library/Developer/CommandLineTools/usr/lib/clang/16/include
 /Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/usr/include
 /Library/Developer/CommandLineTools/usr/include
 /Users/anutosh491/micromamba/envs/xeus-cpp/include
 /Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/System/Library/Frameworks (framework directory)
End of search list.
===============================================================================
[doctest] test cases: 1 | 0 passed | 1 failed | 0 skipped
[doctest] assertions: 3 | 2 passed | 1 failed |
[doctest] Status: FAILURE!

@anutosh491
Copy link
Collaborator Author

Last commit satisfies clang format but if it's over the top, can be reverted.

@anutosh491
Copy link
Collaborator Author

cc @davy39 @dannluciano

Possibly this fix can help y'all. Hence bringing to your notice

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

fprintf(stderr, …) doesn't work in C wasm kernel

3 participants