tech-userlevel archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

fflush(NULL) and mem streams (fmemopen(), open_*memstream())



An issue was recently dealt with wrt the POSIX spec, in respose to
a question whether fflush(NULL) is required to flush memory streams,
or only ones backed by files.

The response was to (plan to) change the wording to not require
memory streams be flushed on fflush(NULL).

That was until it was pointed out that the exact same question was
asked (ie: an issue was opened) in 2012, and then the exact opposite
conclusion was reached ... memory streams are (it said) intended to
be flushed by fflush(NULL).

The earlier response also said "the standard is clear" and didn't
change the wording in any material way (a clarification on another
point was made in an unrelaed section...) - which (to me anyway)
is obviously wrong, if 2 unrelated people raise the same issue
years apart, the standard cannot be considered "clear" even if
a careful study of every word in it ends up leaving only one possible
conclusion.    But that is beside the point here.

If there is anyone here who has a view on this issue (I don't) then
now would be a good time to present an argument.   If we don't
really care and flush memory streams along with the file backed
ones when fflush(NULL) is done, then that's fine.   If we would
prefer one or the other solution, we should say so now.

The arguments against fflush(NULL) affecting memory streams, are
that it can reduce the amount of bookkeeping needed (such streams
need not be linked into a list somewhere so they can be found, and
then removed again later), that fflush(NULL) is usually performed
only as a process is exiting, to make sure all data is written to the
files, which is irrelevant for mem streams (which vanish anyway),
and that if one thread had a mem stream locked, that could block
another thread from exiting for no particularly good reason (the
exiting thread persumably doing a fllush(NULL) on the way out).
[Do we actually do any inter-thread locking related to mem streams?]

The only argument I have seen in favour of having fflush(NULL)
affect mem streams, is that fflush(NULL) might be used for other
purposes, and as the standard (if interpreted carefully enough) does
currently require mem streams to be flushed along with the others,
so changing this could break currently conforming applications.

If there are any arguments, one way or the other, I would be happy
to pass them along.

kre



Home | Main Index | Thread Index | Old Index