From: Ramsay Jones <ramsay@ramsay1.demon.co.uk>
To: Christopher Li <sparse@chrisli.org>
Cc: Sparse Mailing-list <linux-sparse@vger.kernel.org>,
Thomas Graf <tgraf@suug.ch>
Subject: Re: [PATCH 2/4] cgcc: avoid passing a sparse-only option to cc
Date: Thu, 23 Oct 2014 01:38:04 +0100 [thread overview]
Message-ID: <54484DEC.2010902@ramsay1.demon.co.uk> (raw)
In-Reply-To: <CANeU7Qk_H8fV_soAbtGjHXwKBw3BWJgABhNM+KFLmM-rVY4N8w@mail.gmail.com>
On 22/10/14 01:23, Christopher Li wrote:
> On Sun, Oct 19, 2014 at 10:21 PM, Ramsay Jones
> <ramsay@ramsay1.demon.co.uk> wrote:
>> Sorry for the late reply, it's been a busy few days. ;-)
>>
>> On 16/10/14 02:45, Christopher Li wrote:
>>> Hi,
>>>
>>> I create a branch in the chrisl repo call "review-ramsay" for your new
>>> follow up patches.
>>> I plan to do incremental fix up if any on that branch. Then when we
>>> both happy about it,
>>> I will do rebase and smash the commit before push to master branch.
>>
>> Yes, I noticed the new branch - thanks!
>>
>> Did you have any thoughts regarding Josh Triplett's comments on the
>> "compile-i386.c: don't ignore return value of write(2)" patch?
>
> I am fine with either way. The current fix is fine.
I'm fine with this too. ;-)
> If you are up for
> a new xwrite function, that is of course fine as well.
Without putting too much thought into it, such a beast would probably
look something like this:
#include <stddef.h>
#include <unistd.h>
#include <errno.h>
ssize_t xwrite(int fd, const void *buf, size_t len)
{
const char *p = buf;
ssize_t count = 0;
while (len > 0) {
ssize_t nw = write(fd, p, len);
if (nw < 0) {
if (errno == EAGAIN || errno == EINTR)
continue; /* recoverable error */
return -1;
}
len -= nw;
p += nw;
count += nw;
}
return count;
}
Actually, I would need to think about what to do if write() returns
zero. Such a return is not an error, it simply didn't write anything.
Are we guaranteed that some progress will eventually be made, or
should there be another check for non-progress in the loop. dunno. :(
> Using printf()
> is not much an improvement because printf() can still return
> bytes less than the amount you requested.
Hmm, I don't understand this. _In general_, you don't know how many
bytes you are going to write before you call printf() and you don't
explicitly request any amount. Assuming no errors, which are indicated
with a negative return value, printf() returns the number of bytes
actually 'written'. The standard I/O routines, including all the internal
buffering, are much easier to use than the raw system calls (you don't
have to cater for short writes etc., like the code above, because the
standard library takes care of all of that for you).
My preference for the first patch (replacing calls to write with printf),
has little to do with this issue. I simply see no advantage in mixing
calls to the standard I/O library with write() system calls. (The call
to fflush(stdout) on line 889 has nothing to do with paranoia; it has to
do with correctness and is very much needed!)
Using printf() is more portable than write(). The emit_insn_atom() could
be greatly simplified by calling printf() directly rather than using
a sprintf/write combo. (not implemented in my patch). I would be very
surprised if using write() was any more efficient than printf(). I find
the code easier to comprehend without mixing I/O styles. So, once again,
what advantage does write() bestow?
Having said that, although I think the latest patch is perfectly fine, if
you would like me to try expanding on the above xwrite() idea, just let me
know.
ATB,
Ramsay Jones
next prev parent reply other threads:[~2014-10-23 0:38 UTC|newest]
Thread overview: 9+ messages / expand[flat|nested] mbox.gz Atom feed top
2014-10-11 19:57 [PATCH 2/4] cgcc: avoid passing a sparse-only option to cc Ramsay Jones
2014-10-15 14:23 ` Christopher Li
2014-10-15 17:33 ` Ramsay Jones
2014-10-16 1:45 ` Christopher Li
2014-10-19 14:21 ` Ramsay Jones
2014-10-22 0:23 ` Christopher Li
2014-10-23 0:38 ` Ramsay Jones [this message]
2014-10-25 4:14 ` Christopher Li
2014-10-25 12:32 ` Ramsay Jones
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=54484DEC.2010902@ramsay1.demon.co.uk \
--to=ramsay@ramsay1.demon.co.uk \
--cc=linux-sparse@vger.kernel.org \
--cc=sparse@chrisli.org \
--cc=tgraf@suug.ch \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
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).