From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by sourceware.org (Postfix) with ESMTPS id 270FA385E449 for ; Wed, 30 Mar 2022 19:34:41 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 270FA385E449 Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=redhat.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=redhat.com DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1648668880; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to:references:references; bh=Fs5jeFBjZXPLUjTnXuOK+LXn3jCeQb7c+L0VEO2IvLQ=; b=TV3Coxe9Pm+vN8AKnVYBFV1bzyxkJYnacuPB8gw0rEL3331WHs828UhKoRuXf+WnY3+mb3 Gdh1jwwkTcQJEjirNlbPpHfx26Ynz9485fOhPn7isv+SeZhzRN0yaPzcDICkAqH/QxO1wA X8sguDhh159QLUNnjRw1kdbceuOSka8= Received: from mail-yb1-f197.google.com (mail-yb1-f197.google.com [209.85.219.197]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-213-9jR4S_dlM0mDXFVYxyTlRA-1; Wed, 30 Mar 2022 15:34:39 -0400 X-MC-Unique: 9jR4S_dlM0mDXFVYxyTlRA-1 Received: by mail-yb1-f197.google.com with SMTP id j6-20020a25ec06000000b00633c6f3e072so16301405ybh.12 for ; Wed, 30 Mar 2022 12:34:39 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=Fs5jeFBjZXPLUjTnXuOK+LXn3jCeQb7c+L0VEO2IvLQ=; b=0InB+D88ATSnuEctIZBiWQiYMVDiAOv83UssVtqT1GXjqCtn4ZgtpQsg0Zqyib4VFN XIkGih1cAEDFE7b8vxo4pqejR1ta8hvHpspAO8y9v1itJrBspJ3rsmLSR8n1pie7U2se v2AalUFLIgvgCP2mYqKltcailTD9jUk4sxCHYVL45BwWHtWAXcoZoK/Zx3Duenp1tSsc d+79RThnZVu+X5yW+oYV+e4b6IHW1lIjOX/X4G80jgxLzV9xZZ8uwhOhHB0kNIsomUpl Fn8WLtMhDt09iZHlMqBRO1nD0U4PYvw6sB6k3++U0qNg1t1IDvGSuAINBaMTtG3ko/dV N4Rg== X-Gm-Message-State: AOAM531H7Wdz34ewziJyrq8BjkJjBibdEL90Ji5dGqGjr88tUksHcd53 J7woa7YV6NPN2fTNAdd/innWHQ0usJzcZQPcuWkJAWBe4SC2TuUCjxfEc8QQzm7YOS4ew4B02Ea QznGN4pwODeMOlBFBvYHed2Owm2DOM/Q= X-Received: by 2002:a5b:f42:0:b0:633:7ad6:78b0 with SMTP id y2-20020a5b0f42000000b006337ad678b0mr1259510ybr.156.1648668878698; Wed, 30 Mar 2022 12:34:38 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyNiqZHVdV/MOGRfonnz/oZY/EEWRTI/jA5rlALZhdOwKvoqAUwDPtGoPvqj2RLti2Qhz9ibOROEaKWAJE43Hw= X-Received: by 2002:a5b:f42:0:b0:633:7ad6:78b0 with SMTP id y2-20020a5b0f42000000b006337ad678b0mr1259492ybr.156.1648668878429; Wed, 30 Mar 2022 12:34:38 -0700 (PDT) MIME-Version: 1.0 References: <20220330095745.72802-1-sebastian.huber@embedded-brains.de> In-Reply-To: <20220330095745.72802-1-sebastian.huber@embedded-brains.de> From: Jeff Johnston Date: Wed, 30 Mar 2022 15:34:27 -0400 Message-ID: Subject: Re: [PATCH 1/2] Replace _fwalk() calls with _fwalk_reent() To: Sebastian Huber Cc: Newlib Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=jjohnstn@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com X-Spam-Status: No, score=-10.8 required=5.0 tests=BAYES_00, DKIMWL_WL_HIGH, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, HTML_MESSAGE, RCVD_IN_DNSWL_LOW, RCVD_IN_MSPIKE_H4, RCVD_IN_MSPIKE_WL, SPF_HELO_NONE, SPF_NONE, TXREP, T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.4 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on server2.sourceware.org Content-Type: text/plain; charset="UTF-8" X-Content-Filtered-By: Mailman/MimeDel 2.1.29 X-BeenThere: newlib@sourceware.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Newlib mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 30 Mar 2022 19:34:43 -0000 Looks fine. -- Jeff J. On Wed, Mar 30, 2022 at 5:58 AM Sebastian Huber < sebastian.huber@embedded-brains.de> wrote: > Remove the _fwalk() implementation to avoid duplicated code with > _fwalk_reent(). > --- > newlib/libc/stdio/findfp.c | 16 ++++++++-------- > newlib/libc/stdio/fwalk.c | 26 -------------------------- > newlib/libc/stdio/local.h | 1 - > newlib/libc/stdio/refill.c | 8 ++++---- > winsup/cygwin/syscalls.cc | 6 +++--- > 5 files changed, 15 insertions(+), 42 deletions(-) > > diff --git a/newlib/libc/stdio/findfp.c b/newlib/libc/stdio/findfp.c > index 9877c1f2c..7bb48e014 100644 > --- a/newlib/libc/stdio/findfp.c > +++ b/newlib/libc/stdio/findfp.c > @@ -323,20 +323,20 @@ __sinit_lock_release (void) > > /* Walkable file locking routine. */ > static int > -__fp_lock (FILE * ptr) > +__fp_lock (struct _reent * ptr __unused, FILE * fp) > { > - if (!(ptr->_flags2 & __SNLK)) > - _flockfile (ptr); > + if (!(fp->_flags2 & __SNLK)) > + _flockfile (fp); > > return 0; > } > > /* Walkable file unlocking routine. */ > static int > -__fp_unlock (FILE * ptr) > +__fp_unlock (struct _reent * ptr __unused, FILE * fp) > { > - if (!(ptr->_flags2 & __SNLK)) > - _funlockfile (ptr); > + if (!(fp->_flags2 & __SNLK)) > + _funlockfile (fp); > > return 0; > } > @@ -346,13 +346,13 @@ __fp_lock_all (void) > { > __sfp_lock_acquire (); > > - (void) _fwalk (_REENT, __fp_lock); > + (void) _fwalk_reent (_REENT, __fp_lock); > } > > void > __fp_unlock_all (void) > { > - (void) _fwalk (_REENT, __fp_unlock); > + (void) _fwalk_reent (_REENT, __fp_unlock); > > __sfp_lock_release (); > } > diff --git a/newlib/libc/stdio/fwalk.c b/newlib/libc/stdio/fwalk.c > index 8040d5718..2cefcc40e 100644 > --- a/newlib/libc/stdio/fwalk.c > +++ b/newlib/libc/stdio/fwalk.c > @@ -27,32 +27,6 @@ static char sccsid[] = "%W% (Berkeley) %G%"; > #include > #include "local.h" > > -int > -_fwalk (struct _reent *ptr, > - register int (*function) (FILE *)) > -{ > - register FILE *fp; > - register int n, ret = 0; > - register struct _glue *g; > - > - /* > - * It should be safe to walk the list without locking it; > - * new nodes are only added to the end and none are ever > - * removed. > - * > - * Avoid locking this list while walking it or else you will > - * introduce a potential deadlock in [at least] refill.c. > - */ > - for (g = &ptr->__sglue; g != NULL; g = g->_next) > - for (fp = g->_iobs, n = g->_niobs; --n >= 0; fp++) > - if (fp->_flags != 0 && fp->_flags != 1 && fp->_file != -1) > - ret |= (*function) (fp); > - > - return ret; > -} > - > -/* Special version of __fwalk where the function pointer is a reentrant > - I/O function (e.g. _fclose_r). */ > int > _fwalk_reent (struct _reent *ptr, > register int (*reent_function) (struct _reent *, FILE *)) > diff --git a/newlib/libc/stdio/local.h b/newlib/libc/stdio/local.h > index f63c5fb10..09ccd6407 100644 > --- a/newlib/libc/stdio/local.h > +++ b/newlib/libc/stdio/local.h > @@ -183,7 +183,6 @@ extern void __sinit (struct _reent *); > extern void _cleanup_r (struct _reent *); > extern void __smakebuf_r (struct _reent *, FILE *); > extern int __swhatbuf_r (struct _reent *, FILE *, size_t *, int *); > -extern int _fwalk (struct _reent *, int (*)(FILE *)); > extern int _fwalk_reent (struct _reent *, int (*)(struct _reent *, > FILE *)); > struct _glue * __sfmoreglue (struct _reent *,int n); > extern int __submore (struct _reent *, FILE *); > diff --git a/newlib/libc/stdio/refill.c b/newlib/libc/stdio/refill.c > index ccedc7af7..31665bcd9 100644 > --- a/newlib/libc/stdio/refill.c > +++ b/newlib/libc/stdio/refill.c > @@ -23,10 +23,10 @@ > #include "local.h" > > static int > -lflush (FILE *fp) > +lflush (struct _reent * ptr __unused, FILE *fp) > { > if ((fp->_flags & (__SLBF | __SWR)) == (__SLBF | __SWR)) > - return fflush (fp); > + return _fflush_r (_REENT, fp); > return 0; > } > > @@ -102,10 +102,10 @@ __srefill_r (struct _reent * ptr, > */ > if (fp->_flags & (__SLBF | __SNBF)) > { > - /* Ignore this file in _fwalk to avoid potential deadlock. */ > + /* Ignore this file in _fwalk_reent to avoid potential deadlock. */ > short orig_flags = fp->_flags; > fp->_flags = 1; > - (void) _fwalk (_GLOBAL_REENT, lflush); > + (void) _fwalk_reent (_GLOBAL_REENT, lflush); > fp->_flags = orig_flags; > > /* Now flush this file without locking it. */ > diff --git a/winsup/cygwin/syscalls.cc b/winsup/cygwin/syscalls.cc > index 24ec01da8..1cecaa017 100644 > --- a/winsup/cygwin/syscalls.cc > +++ b/winsup/cygwin/syscalls.cc > @@ -3058,10 +3058,10 @@ _cygwin_istext_for_stdio (int fd) > } > > /* internal newlib function */ > -extern "C" int _fwalk (struct _reent *ptr, int (*function) (FILE *)); > +extern "C" int _fwalk_reent (struct _reent *ptr, int (*function) (struct > _reent *, FILE *)); > > static int > -setmode_helper (FILE *f) > +setmode_helper (struct _reent *ptr __unused, FILE *f) > { > if (fileno (f) != _my_tls.locals.setmode_file) > { > @@ -3137,7 +3137,7 @@ cygwin_setmode (int fd, int mode) > _my_tls.locals.setmode_mode = O_TEXT; > else > _my_tls.locals.setmode_mode = O_BINARY; > - _fwalk (_GLOBAL_REENT, setmode_helper); > + _fwalk_reent (_GLOBAL_REENT, setmode_helper); > } > return res; > } > -- > 2.34.1 > >