caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
* Corrupt output of printf
@ 2009-01-22 17:22 Dawid Toton
  2009-01-23 11:20 ` [Caml-list] (Not) corrupt " Dawid Toton
  0 siblings, 1 reply; 5+ messages in thread
From: Dawid Toton @ 2009-01-22 17:22 UTC (permalink / raw)
  To: caml-list

I have a program, which output is produced only with Printf.printf .
This inner part is executed by another one (outer) using Unix.system . 
The outer executable uses print_endline before and after the inner is run.

 From time to time the output of the inner program is corrupt.

Printf.printf seemingly devours parts of single lines, as in these 
examples (all lines should have the same structure):

156 In: 5.483000, 1.500000, 1.760000
157 Sb: 5.008000, 1.494000, 1.500000
158 In: 4.498000, 1.494000, 0.750000
159160 Sb: 5.003000, 1.503000, 0.508000

Another one:

138 In: 5.000000, 0.000000, 0.253000
139 In: 5.001000, 1.000140 Sb: 5.500000, 0.000000, 0.000000
141 Sb: 5.500000, 1.000000, 0.000000

This isn't easily reproducible as it happens rarely; subsequent runs are OK.

Could anybody find a possible cause of this behavior?

Dawid


^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [Caml-list] (Not) corrupt output of printf
  2009-01-22 17:22 Corrupt output of printf Dawid Toton
@ 2009-01-23 11:20 ` Dawid Toton
  2009-01-23 13:16   ` Richard Jones
  0 siblings, 1 reply; 5+ messages in thread
From: Dawid Toton @ 2009-01-23 11:20 UTC (permalink / raw)
  To: caml-list

This was actually a bug in GNOME Terminal... sorry for the noise.

Dawid


^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [Caml-list] (Not) corrupt output of printf
  2009-01-23 11:20 ` [Caml-list] (Not) corrupt " Dawid Toton
@ 2009-01-23 13:16   ` Richard Jones
  2009-01-23 14:20     ` Dawid Toton
  0 siblings, 1 reply; 5+ messages in thread
From: Richard Jones @ 2009-01-23 13:16 UTC (permalink / raw)
  To: Dawid Toton; +Cc: caml-list

On Fri, Jan 23, 2009 at 11:20:35AM +0000, Dawid Toton wrote:
> This was actually a bug in GNOME Terminal... sorry for the noise.

Weird ... I was going to suggeest it was because you weren't flushing
the output after each print statement.  I usually do:

  printf "something\n%!"

(the %! forces a flush of the output channel).

Rich.

-- 
Richard Jones
Red Hat


^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [Caml-list] (Not) corrupt output of printf
  2009-01-23 13:16   ` Richard Jones
@ 2009-01-23 14:20     ` Dawid Toton
  2009-01-23 15:53       ` Eric Cooper
  0 siblings, 1 reply; 5+ messages in thread
From: Dawid Toton @ 2009-01-23 14:20 UTC (permalink / raw)
  To: caml-list


> Weird ... I was going to suggeest it was because you weren't flushing
> the output after each print statement.  

This raises important question:
Let's see the output as a sequence of bytes (there's no time).
Assuming that the process exits normally and incompatible printing 
functions are not mixed:
is there a guarantee (in OCaml library) that the flush operation doesn't 
affect the output?

For me it's obvious that the output shouldn't depend on the presence of 
flush operations. If otherwise - needs to be explicitly stated.

(Of course I'm not considering the one special flush action done when 
closing a stream, but it's tied to the closing function.)

Dawid


^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [Caml-list] (Not) corrupt output of printf
  2009-01-23 14:20     ` Dawid Toton
@ 2009-01-23 15:53       ` Eric Cooper
  0 siblings, 0 replies; 5+ messages in thread
From: Eric Cooper @ 2009-01-23 15:53 UTC (permalink / raw)
  To: caml-list

On Fri, Jan 23, 2009 at 02:20:41PM +0000, Dawid Toton wrote:
> Let's see the output as a sequence of bytes (there's no time).
> Assuming that the process exits normally and incompatible printing  
> functions are not mixed:
> is there a guarantee (in OCaml library) that the flush operation doesn't  
> affect the output?

The flush operation only relates to the time at which the write
occurs (i.e., flush may make it occur sooner than it would otherwise).
So if you're ignoring the time element (and error cases like writing
to a full disk or a broken pipe), it's unobservable.

But if the output is part of a larger interactive system -- prompting
a user for input, or engaging in a 2-way protocol with another process
-- then flushing can be essential for correct behavior.

-- 
Eric Cooper             e c c @ c m u . e d u


^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2009-01-23 15:53 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2009-01-22 17:22 Corrupt output of printf Dawid Toton
2009-01-23 11:20 ` [Caml-list] (Not) corrupt " Dawid Toton
2009-01-23 13:16   ` Richard Jones
2009-01-23 14:20     ` Dawid Toton
2009-01-23 15:53       ` Eric Cooper

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).