public inbox for newlib@sourceware.org
 help / color / mirror / Atom feed
From: Corinna Vinschen <vinschen@redhat.com>
To: newlib@sourceware.org
Subject: Re: [PATCH v2] newlib: libc: Fix bugs in the commit 3d94e07c49b5.
Date: Thu, 16 Nov 2023 15:08:07 +0100	[thread overview]
Message-ID: <ZVYiR+8eqzNGHdvb@calimero.vinschen.de> (raw)
In-Reply-To: <ZVYdpvzK4kD0N1CG@calimero.vinschen.de>

On Nov 16 14:48, Corinna Vinschen wrote:
> On Nov 16 14:19, Corinna Vinschen wrote:
> > On Nov 16 21:27, Takashi Yano wrote:
> > > 2) __swbuf_r() has ORIENT (fp, -1) call, however, result is not checked.
> > 
> > Good catch.  Looks like setting the orientation at this point is
> > wrong.  __swbuf_r is called via the __sputc_r macro in stdio.h.
> > But __sputc_r is also called from __fputwc as well as, potentially,
> > from _fputws_r.
> > 
> > AFAICS, we already set the orientation from the calling functions
> > _putc_r (covering putchar, putc, fputc) and from _puts_r as
> > well as _fputs_r (covering puts, fputs).
> > 
> > On the wide-char side, we set the orientation from _fputwc_r
> > (covering putwchar, putwc, fputwc) and from _fputws_r (covering
> > fputws).
> > 
> > So I *think* we can safely remove the ORIENT call from __swbuf_r,
> > or did I miss some other way to call __swbuf_r?
> 
> Yes, I did.  The _getchar_unlocked and _putchar_unlocked macros as well
> as the __SINGLE_THREAD__ getc and putc macros(*).  I also missed the
> putc{har}_unlocked and getc{har}_unlocked functions.
> 
> They all call __sgetc_r or __sputs_r, both being macros in stdio.h.
> The underlying functions __srget_r and __swbuf_r are shared between
> byte and wide-char orientation functions.
> 
> Drat.  Looks like we really have to do the ORIENT stuff inside the
> __sgetc_r/__sputs_r macros...

That's not feasible.  The only way out as I see it is that we don't
share the underlying functions and macros between byte and wide-char
functions:

- _fputwc_r and _fputws_r must not call __sputc_r from stdio.h, they
  should get their own version.

- The underlying functions __srget_r and __swbuf_r have to be split into
  two functions each, or they have to get an additional parameter
  deciding how to set the orientation.

- In turn, we can remove most of the ORIENT calls in the calling functions.


Corinna


  reply	other threads:[~2023-11-16 14:08 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-11-10 16:09 Takashi Yano
2023-11-13 13:07 ` Corinna Vinschen
2023-11-15 16:31   ` Corinna Vinschen
2023-11-15 22:53     ` Brian Inglis
2023-11-16  9:34       ` Corinna Vinschen
2023-11-16 12:27     ` Takashi Yano
2023-11-16 13:19       ` Corinna Vinschen
2023-11-16 13:48         ` Corinna Vinschen
2023-11-16 14:08           ` Corinna Vinschen [this message]
2023-11-20 20:08             ` Corinna Vinschen

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=ZVYiR+8eqzNGHdvb@calimero.vinschen.de \
    --to=vinschen@redhat.com \
    --cc=newlib@sourceware.org \
    /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 read-only IMAP folder(s) and NNTP newsgroup(s).