git@vger.kernel.org mailing list mirror (one of many)
 help / color / mirror / code / Atom feed
From: Duy Nguyen <pclouds@gmail.com>
To: Junio C Hamano <gitster@pobox.com>
Cc: Dan McGregor <dkm560@usask.ca>,
	"McGregor, Dan" <dan.mcgregor@usask.ca>,
	"git@vger.kernel.org" <git@vger.kernel.org>
Subject: Re: [PATCH v2] git-compat-util: undefine fileno if defined
Date: Wed, 8 May 2019 17:09:05 +0700	[thread overview]
Message-ID: <CACsJy8BcyD199L4qGv6-TP-8HD+GS+ZDNN5jspkh5uVaWekkoQ@mail.gmail.com> (raw)
In-Reply-To: <xmqqk1f1gzgs.fsf@gitster-ct.c.googlers.com>

On Wed, May 8, 2019 at 2:47 PM Junio C Hamano <gitster@pobox.com> wrote:
>
> Dan McGregor <dkm560@usask.ca> writes:
>
> >>I don't think this is enough. At least fbsd defines this
> >>
> >>#define    fileno(p)    (!__isthreaded ? __sfileno(p) : (fileno)(p))
> >>
> >>so one of the two functions will be used depending on __isthreaded
> >>flag. Your forcing to use fileno, ignoring __sfileno, is technically
> >>not correct.
> >>
> >>For the record, at least fbsd also defines feof, ferror, clearerr,
> >>getc and putc in the same way. But at least I don't see how something
> >>like feof(fp++) could cause bad side effects.
> >>
> >>So, how about something like this? A teeny bit longer than your
> >>version, but I think it's easier to control long term.
> >
> > Yes, this looks pretty reasonable to me too.
>
> Sorry for pinging this ancient thread, but while reviewing the
> stalled topics, this one caught my attention.  The very original
> <20190201193004.88736-1-dan.mcgregor@usask.ca> said that the problem
> it wants to solve was that the code that passes (void*) parameter to
> fileno(), fflush() and rewind() misbehaved, as these are all macros
> on your system.
>
> We solved the problem for fileno() being a macro eventually with
> 18a4f6be ("git-compat-util: work around fileno(fp) that is a macro",
> 2019-02-12), but what about the other two?

I don't think the other two were the problem. Even in the mail you
pointed to, only fileno() is acknowledged the problem in the commit
message.

At least for BSDs fflush() and rewind() are not macros. BSDs optimize
a couple functions for the no-pthread case by inlining some short
expressions directly [1]. This works well for read-only functions such
as fileno(), feof(), ferror().. and pushing the limits a bit with
fputc() and fgetc(), but fflush() and rewind() are (I think) just too
complicated to do it this way.

[1] https://github.com/freebsd/freebsd/blob/master/include/stdio.h#L451-L519
[2] https://public-inbox.org/git/20190209023621.75255-1-dan.mcgregor@usask.ca/

> Here comes a weather-balloon to see if we should pursue tying this
> loose end.

Let's see if there are still problems with more exotic platforms. I'm
reluctant of adding unused compat/ code because to me compat/ is
scary. I often don't have the right systems to test whenever I need to
make changes in compat/
-- 
Duy

  reply	other threads:[~2019-05-08 10:09 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
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 [this message]
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=CACsJy8BcyD199L4qGv6-TP-8HD+GS+ZDNN5jspkh5uVaWekkoQ@mail.gmail.com \
    --to=pclouds@gmail.com \
    --cc=dan.mcgregor@usask.ca \
    --cc=dkm560@usask.ca \
    --cc=git@vger.kernel.org \
    --cc=gitster@pobox.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).