Zsh Mailing List Archive
Messages sorted by: Reverse Date, Date, Thread, Author

Re: PATCH: refactor memstream for "print -v"



2016/01/07 06:30, Bart Schaefer <schaefer@xxxxxxxxxxxxxxxx> wrote:

> I suppose that this:
> 
>    ((COUNT = fread(BUF, 1, count, FOUT)) == count)
> 
> could correctly be replaced with
> 
>    (count == (count = fread(BUF, 1, count, FOUT)))

So you want to save the return value of fread() for debugging purpose?
I coundn't think of such a possibility.

The macro seems to work on OSX, but clang gives the following warning:

builtin.c:4435:36: warning: unsequenced modification and access to 'count' [-Wunsequenced]
        if (IS_MSTREAM(fout) && (rcount = READ_MSTREAM(buf,fout)) == -1)
                                          ^~~~~~~~~~~~~~~~~~~~~~
builtin.c:4066:15: note: expanded from macro 'READ_MSTREAM'
      ((count = fread(BUF, 1, count, FOUT)) == count)) ? count : (size_t)-1)
              ^                                ~~~~~

Anyway, I feel the macro is too complicated, so how about either

(a) revert to the original READ_MSTREAM (with (size_t)-1)
(b) give up saving the return value of fread()
   ( .... && (count == fread(BUF, 1, count ,FOUT))) ? count : (size_t)-1 )
(c) write a function (not a macro) read_mstream()

Sorry for taking your time.


Messages sorted by: Reverse Date, Date, Thread, Author