From owner-freebsd-standards@freebsd.org Sun Feb 25 04:16:40 2018 Return-Path: Delivered-To: freebsd-standards@mailman.ysv.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mailman.ysv.freebsd.org (Postfix) with ESMTP id 1039DF008D9 for ; Sun, 25 Feb 2018 04:16:40 +0000 (UTC) (envelope-from marklmi26-fbsd@yahoo.com) Received: from sonic317-28.consmr.mail.bf2.yahoo.com (sonic317-28.consmr.mail.bf2.yahoo.com [74.6.129.83]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (Client did not present a certificate) by mx1.freebsd.org (Postfix) with ESMTPS id A880068569 for ; Sun, 25 Feb 2018 04:16:39 +0000 (UTC) (envelope-from marklmi26-fbsd@yahoo.com) X-YMail-OSG: VZE0io0VM1lDfcyX3dFNBerczClz.AtmOANfB773jEMDVcP3hrA.eAttLKhUYdW Aed26_8a4uWndigq82wV7LjXl8jrgp4dP.E7ZrsB82t2XybQnGfR8hsDcoTxzXZgLbNmAgQ9vdst xKKwOgFA6TgXhDdbO6wPmvwwaomYkXC2GWfIlJwQi9vdXXNnO07tXgG.B.XzymCMw5xcTsjoNCOW 1D5Xggk7IFEBCUQT9Mz0pPX_SHB5uUQf.s8vlMZEtqV0Sj._MuiEKmxqtPTLTT1qcSO_34ft1a8M mkYzCgAkowhq3ZVofb8tjWjbJbhJroyjQaCxYhCY98CP7W3FD6lPr9BQCRhld5PX54lIUrueh0qg eeB8Z9eO2qiMvXgsOPWxUPftE13sGi3bb7Fb9MmRWyHfkFEOM9dhioazmWDZYP5atiaqQQFoysOP .rPmuafWYKtrwR7AG8IcT4oKA1WhX3BIZnEQqSTRyKZNQqsEAdsWCAp.y4R5jnxfn Received: from sonic.gate.mail.ne1.yahoo.com by sonic317.consmr.mail.bf2.yahoo.com with HTTP; Sun, 25 Feb 2018 04:16:39 +0000 Received: from smtp103.rhel.mail.bf1.yahoo.com (EHLO [192.168.1.25]) ([98.139.230.213]) by smtp411.mail.bf1.yahoo.com (JAMES SMTP Server ) with ESMTPA ID 2506173844fd19f52721971e29959e28; Sun, 25 Feb 2018 03:56:22 +0000 (UTC) Content-Type: text/plain; charset=us-ascii Mime-Version: 1.0 (Mac OS X Mail 11.2 \(3445.5.20\)) Subject: Re: Marking select(2) as restrict From: Mark Millard In-Reply-To: Date: Sat, 24 Feb 2018 19:56:20 -0800 Cc: FreeBSD Hackers , FreeBSD Standards Content-Transfer-Encoding: quoted-printable Message-Id: <9438AC5E-56B8-46E4-AECE-5C3A194F4D1E@yahoo.com> References: To: Eitan Adler X-Mailer: Apple Mail (2.3445.5.20) X-BeenThere: freebsd-standards@freebsd.org X-Mailman-Version: 2.1.25 Precedence: list List-Id: Standards compliance List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sun, 25 Feb 2018 04:16:40 -0000 On 2018-Feb-15, at 12:10 AM, Eitan Adler wrote: > Hi all, >=20 > POSIX requires that the fd_set arguments in select(2) be marked as > restrict. This patch attempts to implement that. >=20 > (a) Am I missing anything? > (b) Anything in particular to watch out for? > (c) Assuming an exp-run passes any reason not to commit? >=20 >=20 > Index: lib/libc/sys/select.2 > =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D > --- lib/libc/sys/select.2 (revision 329296) > +++ lib/libc/sys/select.2 (working copy) > @@ -39,7 +39,7 @@ > .Sh SYNOPSIS > .In sys/select.h > .Ft int > -.Fn select "int nfds" "fd_set *readfds" "fd_set *writefds" "fd_set > *exceptfds" "struct timeval *timeout" > +.Fn select "int nfds" "fd_set * restrict readfds" "fd_set * restrict > writefds" "fd_set * restrict exceptfds" "struct timeval *timeout" > .Fn FD_SET fd &fdset > .Fn FD_CLR fd &fdset > .Fn FD_ISSET fd &fdset > Index: lib/libc/sys/select.c > =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D > --- lib/libc/sys/select.c (revision 329296) > +++ lib/libc/sys/select.c (working copy) > @@ -41,7 +41,7 @@ __weak_reference(__sys_select, __select); >=20 > #pragma weak select > int > -select(int n, fd_set *rs, fd_set *ws, fd_set *es, struct timeval *t) > +select(int n, fd_set * restrict rs, fd_set * restrict ws, fd_set * > restrict es, struct timeval *t) > { >=20 > return (((int (*)(int, fd_set *, fd_set *, fd_set *, struct timeval = *)) > Index: sys/sys/select.h > =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D > --- sys/sys/select.h (revision 329296) > +++ sys/sys/select.h (working copy) > @@ -101,8 +101,7 @@ int pselect(int, fd_set *__restrict, fd_set *__res > const struct timespec *__restrict, const sigset_t *__restrict); > #ifndef _SELECT_DECLARED > #define _SELECT_DECLARED > -/* XXX missing restrict type-qualifier */ > -int select(int, fd_set *, fd_set *, fd_set *, struct timeval *); > +int select(int, fd_set *__restrict, fd_set *__restrict, fd_set > *__restrict, struct timeval *); > #endif > __END_DECLS > #endif /* !_KERNEL */ Going in a different direction: C++ . . . =46rom FreeBSD's cdefs.h : #if !(__GNUC__ =3D=3D 2 && __GNUC_MINOR__ =3D=3D 95) #if !defined(__STDC_VERSION__) || __STDC_VERSION__ < 199901 #define __restrict #else #define __restrict restrict #endif #endif It looks to me like C++ use of cdefs.h and then, say, select.h, could easily lead to __restrict being translated to no-text. C++11 does add __STDC_VERSION__ to the "implementation-defined value, if present" category. (Quoted material is from en.cppreference.com .) This would lead C++ to not give errors/warnings for violating the constraints involved in calling a newly Linux-like implementation of select (with C99-like restrict involved). It also means that if some C++ compilers have a __restrict (-like) extension that it is not being put to use for either code generation or for reporting violations of C99-like constraints. Of course if a C++11 or later targeting defines __STDC_VERSION__ with it being >=3D 199901 then the C++ compiler would see "restrict" (no quotes) after the substitution, likely giving a syntax error. (It is not a keyword in C++.) But these types of points also apply to existing uses of __restrict after cdefs.h use (unless I missed a level of conditionality that is relevant). But at least there is some history as evidence for these. Overall result: C++ apparently only gets run-time behavior as evidence for the use of the new content of select's implementation if this is changed: no reports of abusive calls as stands. =3D=3D=3D Mark Millard marklmi at yahoo.com ( markmi at dsl-only.net is going away in 2018-Feb, late)