Subject: Re: PATCH: refactor memstream for "print -v"
From: "Jun T." <[email-masked]>
To: [email-masked]
Date: Fri, 8 Jan 2016 21:32:53 +0900
List-Id: Zsh Workers List <zsh-workers.zsh.org>

2016/01/07 06:30, Bart Schaefer <[email-masked]> 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.