Skip to content

[Embedding] clarify how to mix native IO of C/C++ programs and Julia's libuv IO #60003

@zengmao

Description

@zengmao

Initializing the Julia runtime, i.e. calling jl_init(), changes the behavior of stdio streams due to Julia's use of libuv. Some documentation is here:
https://docs.julialang.org/en/v1/devdocs/stdio/

If the C program that calls Julia also performs IO itself, e.g. with scanf and printf, how to avoid conflicts? How about C++ programs using std::iostream? Clarifying these questions would be valuable in e.g. the manual section on embedding Julia:
https://docs.julialang.org/en/v1/manual/embedding/

I previously posted on Discourse to point out bugs that can arise in a C program in the presence of such conflicts. I didn't get a complete solution, though I proposed a solution when all IO is performed with std::iostream:
https://discourse.julialang.org/t/c-program-embedding-julia-works-in-terminal-but-breaks-in-pipes/86973

P.S. For pure C programs, it seems that one solution is avoiding directly using stdio and only using jl_printf and jl_stderr_stream. This requires changing the IO code in the entire program.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions