Skip to content
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

RFC: add flush_cstdio function #3949

Merged
merged 1 commit into from
Aug 7, 2013
Merged

Conversation

stevengj
Copy link
Member

@stevengj stevengj commented Aug 6, 2013

This adds flush_cstdio() function, which calls fflush(stdout) and fflush(stderr) in C. This is needed in order to flush any output from external C code.

(For example, I need this in IJulia in order to make sure external printf output is captured after evaluating an input cell.)

@vtjnash
Copy link
Member

vtjnash commented Aug 6, 2013

This might be incorrect, since the stream may be (should be?) non-blocking at the time: http://pubs.opengroup.org/onlinepubs/009696799/functions/fflush.html
@loladiro ping

It's possible you could write this directly in julia:
ccall(:fflush, Cint, (Ptr{Void},), cglobal(@osx? :__stdoutp : :stdout)))
but this would be broken on windows, where stdout is defined as &__iob_func()[1] and stderr is defined as &__iob_func()[2]

@Keno
Copy link
Member

Keno commented Aug 6, 2013

I intentionally don't put it into non-blocking mode since child processes may not know how to deal with that. I think it is reasonable to assume that the stream is blocking since anything else is bad form.

@stevengj
Copy link
Member Author

stevengj commented Aug 6, 2013

Good to hear that we open stdout/stderr in the usual blocking mode. Okay to merge, then?

(It could throw an exception on an error, but I have a hard time imagining a circumstance when anything useful could be done with such an exception from flush_cstdio.)

@@ -648,6 +648,12 @@ DLLEXPORT int jl_strtof(char *str, float *out)

// showing --------------------------------------------------------------------

void jl_flush_cstdio()
{
fflush(stdout);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

indentation

@vtjnash
Copy link
Member

vtjnash commented Aug 7, 2013

OK. I thought libuv was doing it, but a review of the code reveals that it only does for internal (not spawn-safe) pipes and all sockets. Normal pipes and TTY's are fine (as are normal files).

(edit) LGTM. OK to merge.

@vtjnash
Copy link
Member

vtjnash commented Aug 7, 2013

@loladiro on a related note, can you put together a flush(::UVStream) function which blocks the task until all pending writes are finished?

@Keno
Copy link
Member

Keno commented Aug 7, 2013

@vtjnash I'll see what I can do.

@stevengj
Copy link
Member Author

stevengj commented Aug 7, 2013

Fixed indentation.

stevengj added a commit that referenced this pull request Aug 7, 2013
RFC: add flush_cstdio function
@stevengj stevengj merged commit 528dd2c into JuliaLang:master Aug 7, 2013
@stevengj stevengj mentioned this pull request Aug 8, 2013
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.

3 participants