git@vger.kernel.org mailing list mirror (one of many)
 help / color / mirror / code / Atom feed
From: Duy Nguyen <pclouds@gmail.com>
To: Johannes Schindelin <Johannes.Schindelin@gmx.de>
Cc: Junio C Hamano <gitster@pobox.com>,
	Dan McGregor <dan.mcgregor@usask.ca>,
	Git Mailing List <git@vger.kernel.org>,
	Masaya Suzuki <masayasuzuki@google.com>
Subject: Re: [PATCH] http: cast result to FILE *
Date: Mon, 4 Feb 2019 19:13:06 +0700	[thread overview]
Message-ID: <CACsJy8BtaxMRTG4-r3iJfUuR9k-=r=4QTRxCkFt3k3p7826Z9A@mail.gmail.com> (raw)
In-Reply-To: <nycvar.QRO.7.76.6.1902041243220.41@tvgsbejvaqbjf.bet>

On Mon, Feb 4, 2019 at 6:44 PM Johannes Schindelin
<Johannes.Schindelin@gmx.de> wrote:
>
> Hi Duy,
>
> On Sat, 2 Feb 2019, Duy Nguyen wrote:
>
> > On Sat, Feb 2, 2019 at 4:21 AM Junio C Hamano <gitster@pobox.com> wrote:
> > >
> > > Dan McGregor <dan.mcgregor@usask.ca> writes:
> > >
> > > > Commit 8dd2e88a92 ("http: support file handles for HTTP_KEEP_ERROR",
> > > > 2019-01-10) introduced an implicit assumption that rewind, fileno, and
> > > > fflush are functions. At least on FreeBSD fileno is not, and as such
> > > > passing a void * failed.
> > >
> > > I am not strongly opposed to this patch,
> >
> > Even if this is needed, should it be done behind git-compat-util.h
> > instead? That way if fileno(void*) is used elsewhere, we don't have to
> > do the casting again.
>
> The disadvantage, of course, would be that other call sites would not
> benefit from a manual auditing whether the argument has side effects (and
> thus, whether a macro using the argument multiple times would result in
> very unexpected multiple side effects).

That's just a better reason to "fix" it in compat/. If you define a
git_fileno() function and map fileno to it, then you won't have to
deal with side effects of FreeBSD's fileno() macro. All evaluation
happens before git_fileno() is called.

> I'd rather not paper over this issue and thereby open even larger
> problems.
>
> Ciao,
> Dscho
>
> >
> > > but shouldn't you be filing
> > > a bug report against FreeBSD instead?  The implementation is free to
> > > define fileno(fh) as a macro, but it shouldn't force such a change
> > > to conformant programs.
> > >
> > > https://bugs.freebsd.org/bugzilla/show_bug.cgi?id=206146
> > >
> > > > Explicitly cast result to a FILE * when using standard functions that
> > > > may ultimately be macros.
> > > >
> > > > Signed-off-by: Dan McGregor <dan.mcgregor@usask.ca>
> > > > ---
> > > >  http.c | 6 +++---
> > > >  1 file changed, 3 insertions(+), 3 deletions(-)
> > > >
> > > > diff --git a/http.c b/http.c
> > > > index 954bebf684..8b9476b151 100644
> > > > --- a/http.c
> > > > +++ b/http.c
> > > > @@ -1996,12 +1996,12 @@ static int http_request_reauth(const char *url,
> > > >               strbuf_reset(result);
> > > >               break;
> > > >       case HTTP_REQUEST_FILE:
> > > > -             if (fflush(result)) {
> > > > +             if (fflush((FILE *)result)) {
> > > >                       error_errno("unable to flush a file");
> > > >                       return HTTP_START_FAILED;
> > > >               }
> > > > -             rewind(result);
> > > > -             if (ftruncate(fileno(result), 0) < 0) {
> > > > +             rewind((FILE *)result);
> > > > +             if (ftruncate(fileno((FILE *)result), 0) < 0) {
> > > >                       error_errno("unable to truncate a file");
> > > >                       return HTTP_START_FAILED;
> > > >               }
> >
> >
> >
> > --
> > Duy
> >



-- 
Duy

  reply	other threads:[~2019-02-04 12:13 UTC|newest]

Thread overview: 16+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-02-01 19:30 [PATCH] http: cast result to FILE * Dan McGregor
2019-02-01 21:17 ` Junio C Hamano
2019-02-02 11:21   ` Duy Nguyen
2019-02-04 11:44     ` Johannes Schindelin
2019-02-04 12:13       ` Duy Nguyen [this message]
2019-02-04 18:10         ` Junio C Hamano
2019-02-05  1:36           ` Dan McGregor
2019-02-09  2:36 ` [PATCH v2] git-compat-util: undefine fileno if defined Dan McGregor
2019-02-09 18:34   ` Junio C Hamano
2019-02-12 13:45   ` Duy Nguyen
2019-02-12 14:14     ` Duy Nguyen
2019-02-12 16:56     ` Junio C Hamano
2019-02-16  2:33     ` Dan McGregor
2019-05-08  7:46       ` Junio C Hamano
2019-05-08 10:09         ` Duy Nguyen
2019-05-08 10:16           ` Junio C Hamano

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

  List information: http://vger.kernel.org/majordomo-info.html

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to='CACsJy8BtaxMRTG4-r3iJfUuR9k-=r=4QTRxCkFt3k3p7826Z9A@mail.gmail.com' \
    --to=pclouds@gmail.com \
    --cc=Johannes.Schindelin@gmx.de \
    --cc=dan.mcgregor@usask.ca \
    --cc=git@vger.kernel.org \
    --cc=gitster@pobox.com \
    --cc=masayasuzuki@google.com \
    /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.
Code repositories for project(s) associated with this public inbox

	https://80x24.org/mirrors/git.git

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 read-only IMAP folder(s) and NNTP newsgroup(s).