From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 31536 invoked by alias); 18 Oct 2019 20:44:47 -0000 Mailing-List: contact libc-alpha-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: libc-alpha-owner@sourceware.org Received: (qmail 31526 invoked by uid 89); 18 Oct 2019 20:44:46 -0000 Authentication-Results: sourceware.org; auth=none X-Spam-SWARE-Status: No, score=-7.1 required=5.0 tests=AWL,BAYES_00,RCVD_IN_DNSWL_LOW autolearn=ham version=3.3.1 spammy=H*i:sk:f395b08, H*f:sk:f395b08, H*MI:sk:f395b08, widely X-HELO: mail-out.m-online.net Date: Fri, 18 Oct 2019 20:44:00 -0000 From: Lukasz Majewski To: Paul Eggert Cc: GNU C Library Subject: Re: [PATCH 1/2] y2038: Helper macro to convert struct __timespec64 to struct timespec Message-ID: <20191018224433.2841fe8e@jawa> In-Reply-To: References: <20191018145720.11706-1-lukma@denx.de> MIME-Version: 1.0 Content-Type: multipart/signed; micalg=pgp-sha512; boundary="Sig_/cSi+glMiAA_HvaOTUWbl2f2"; protocol="application/pgp-signature" X-SW-Source: 2019-10/txt/msg00587.txt.bz2 --Sig_/cSi+glMiAA_HvaOTUWbl2f2 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: quoted-printable Content-length: 2465 Hi Paul, > On 10/18/19 7:57 AM, Lukasz Majewski wrote: >=20 > > +/* Check if a value lies with the valid nanoseconds range. */ > > +#define IS_VALID_NANOSECONDS(ns) ((ns) >=3D 0 && (ns) <=3D 999999999)= =20=20 >=20 > This should be a static or inline function; there's no need for the=20 > excessive power of a macro here. Ok. I can add this as an inline static function. >=20 > > +#define timespec64_to_timespec(ts64) > > \ > > + ({ > > \ > > + if (! IS_VALID_NANOSECONDS (ts64.tv_nsec)) > > \ > > + { > > \ > > + __set_errno (EINVAL); > > \ > > + return -1; > > \ > > + } > > \ > > + if (! in_time_t_range (ts64.tv_sec)) > > \ > > + { > > \ > > + __set_errno (EOVERFLOW); > > \ > > + return -1; > > \ > > + } > > \ > > + valid_timespec64_to_timespec (ts64); })=20=20 >=20 > This macro is too confusing. Instead, if there's a need for this sort > of thing, I suggest a static or inline function that returns true or > false (setting errno); My first attempt on this conversion helper was based on static inline function. Unfortunately, such approach has the issue with __set_errno(), which is not accessible in include/time.h (as it is defined in include/errno.h). Moreover, in the glibc the pattern with defining such macros is widely used - in e.g. math/math-narrow.h or in various sysdep.h headers. Last but not least - as Joseph pointed out in the other mail - maybe it would be just enough in this particular case to drop the IS_VALID_NANOSECONDS() check as this shall be done in the kernel (and if an error is detected the syscall would fail). The in_time_t_range() check for clock_getres is also problematic - as it would be required to have a _really_ bad clock with tv_sec to be overflowed. To sum up - for the clock_getres() conversion - I do opt for using valid_timespec64_to_timespec() (as it is already available in include/time.h) and drop this patch (but keeping the IS_VALID_NANOSECONDS() check in the form of static inline). > the caller can decide what to do if it returns > false. Best regards, Lukasz Majewski -- DENX Software Engineering GmbH, Managing Director: Wolfgang Denk HRB 165235 Munich, Office: Kirchenstr.5, D-82194 Groebenzell, Germany Phone: (+49)-8142-66989-59 Fax: (+49)-8142-66989-80 Email: lukma@denx.de --Sig_/cSi+glMiAA_HvaOTUWbl2f2 Content-Type: application/pgp-signature Content-Description: OpenPGP digital signature Content-length: 488 -----BEGIN PGP SIGNATURE----- iQEzBAEBCgAdFiEEgAyFJ+N6uu6+XupJAR8vZIA0zr0FAl2qJDEACgkQAR8vZIA0 zr3uZAgA20+nt78IVvU/wxKfKnGQx8kIEFjtKbdNiqiTIRYuxy8kIIfD6g81D48M QyErEGoscnBUD8zar9fHk6EDKR7gWPSYXy68sCm7vqBYOO/ortYtGd3sE+2vsiDG sSwjVWQzcSyAadHnE3pxPquJ4mz8iga1wWf2siSuRYQA8U9L87Sux3AE+EfYGHex JUWhsZqZ549VwSRYuqCai+5q9P/gRg/2zF+ph5OWH5Q33y++mA9au2W9DHT6d+l9 qSkBpHiny3+37QORjmLKF2ZtfxOvswXStBQFpzqSsywHEznyEjErxsF7k2shlK5R beoNhhhLuSRAlSEV+yVG7OkzYOEwIg== =M4tn -----END PGP SIGNATURE----- --Sig_/cSi+glMiAA_HvaOTUWbl2f2--