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.133.124]) by sourceware.org (Postfix) with ESMTPS id A102B384F021 for ; Thu, 19 May 2022 12:02:52 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org A102B384F021 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=1652961772; h=from:from:reply-to:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:mime-version:mime-version: content-type:content-type:in-reply-to:in-reply-to: references:references; bh=46qI1lEQqgxOqFS05kmG+ULlogpmftc7ownH1siw8js=; b=BlEICutpOHaRoX7Ei5IJb2ouO21IocCXr4VEu5N/yMGQChNoZ5xngBUV7ZG78jcddj15qF hk5FpQx3qes0tSecfbefZEmbh/sLziic+h/NOtZw5Adub1I7uB6AKXU5PZS8a6hERpL4ZR w/vLahnidKo37g1dWnql9PYGFXZhgME= Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-632-cz2aBzQEPUOCQmqo5XYg1g-1; Thu, 19 May 2022 08:02:51 -0400 X-MC-Unique: cz2aBzQEPUOCQmqo5XYg1g-1 Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.rdu2.redhat.com [10.11.54.5]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 0772285A5AA for ; Thu, 19 May 2022 12:02:51 +0000 (UTC) Received: from calimero.vinschen.de (unknown [10.36.112.7]) by smtp.corp.redhat.com (Postfix) with ESMTPS id D805F7B7C for ; Thu, 19 May 2022 12:02:50 +0000 (UTC) Received: by calimero.vinschen.de (Postfix, from userid 500) id B62B3A807DB; Thu, 19 May 2022 14:02:49 +0200 (CEST) Date: Thu, 19 May 2022 14:02:49 +0200 From: Corinna Vinschen To: newlib@sourceware.org Subject: Re: [PATCH] Fix __fp_lock_all() and __fp_unlock_all() Message-ID: Reply-To: newlib@sourceware.org Mail-Followup-To: newlib@sourceware.org References: <20220518171307.53663-1-sebastian.huber@embedded-brains.de> MIME-Version: 1.0 In-Reply-To: <20220518171307.53663-1-sebastian.huber@embedded-brains.de> X-Scanned-By: MIMEDefang 2.79 on 10.11.54.5 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=vinschen@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Type: text/plain; charset=utf-8 Content-Disposition: inline X-Spam-Status: No, score=-11.3 required=5.0 tests=BAYES_00, DKIMWL_WL_HIGH, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, RCVD_IN_DNSWL_LOW, SPF_HELO_NONE, SPF_NONE, TXREP, T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org 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: Thu, 19 May 2022 12:02:58 -0000 On May 18 19:13, Sebastian Huber wrote: > For _REENT_GLOBAL_STDIO_STREAMS, lock/unlock all FILE objects. In the > repository, this function is only used by Cygwin during process forks. Since > Cygwin enabled _REENT_GLOBAL_STDIO_STREAMS recently, without this fix no FILE > object at all was locked. > --- > newlib/libc/stdio/findfp.c | 4 ++++ > 1 file changed, 4 insertions(+) > > diff --git a/newlib/libc/stdio/findfp.c b/newlib/libc/stdio/findfp.c > index 6933ff1db..a39082387 100644 > --- a/newlib/libc/stdio/findfp.c > +++ b/newlib/libc/stdio/findfp.c > @@ -333,6 +333,8 @@ __fp_lock_all (void) > #ifndef _REENT_GLOBAL_STDIO_STREAMS > ptr = _REENT; > (void) _fwalk_sglue (ptr, __fp_lock, &ptr->__sglue); > +#else > + (void) _fwalk_sglue (NULL, __fp_lock, &__sglue); > #endif The resulting __fp_lock_all/__fp_unlock_all functions look a bit weird to me, codewise. Counter-proposal: diff --git a/newlib/libc/stdio/findfp.c b/newlib/libc/stdio/findfp.c index 118637a18f5b..ebfbf0976de5 100644 --- a/newlib/libc/stdio/findfp.c +++ b/newlib/libc/stdio/findfp.c @@ -329,31 +329,24 @@ __fp_unlock (struct _reent * ptr __unused, FILE * fp) return 0; } +#ifdef _REENT_GLOBAL_STDIO_STREAMS +# define _PTR NULL +# define _GLUE __sglue +#else +# define _PTR _REENT +# define _GLUE _PTR->__sglue +#endif + void __fp_lock_all (void) { -#ifndef _REENT_GLOBAL_STDIO_STREAMS - struct _reent *ptr; -#endif - - __sfp_lock_acquire (); - -#ifndef _REENT_GLOBAL_STDIO_STREAMS - ptr = _REENT; - (void) _fwalk_sglue (ptr, __fp_lock, &ptr->__sglue); -#endif + _fwalk_sglue (_PTR, __fp_lock, &_GLUE); } void __fp_unlock_all (void) { -#ifndef _REENT_GLOBAL_STDIO_STREAMS - struct _reent *ptr; - - ptr = _REENT; - (void) _fwalk_sglue (ptr, __fp_unlock, &ptr->__sglue); -#endif - + _fwalk_sglue (_PTR, __fp_unlock, &_GLUE); __sfp_lock_release (); } #endif What do you think? Thanks, Corinna