![]() |
|
Message-ID: <CO6PR11MB5602775A87077E4FA60FE745EDEEA@CO6PR11MB5602.namprd11.prod.outlook.com> Date: Thu, 9 Oct 2025 02:48:03 +0000 From: "Chen, Qi" <Qi.Chen@...driver.com> To: Rich Felker <dalias@...c.org> CC: "musl@...ts.openwall.com" <musl@...ts.openwall.com> Subject: RE: [PATCH] include/sched.h: fix _CPU_op_S to support expression such as '--i' Thanks for making things clear. Regards, Qi -----Original Message----- From: Rich Felker <dalias@...c.org> Sent: Tuesday, September 30, 2025 9:34 PM To: Chen, Qi <Qi.Chen@...driver.com> Cc: musl@...ts.openwall.com Subject: Re: [musl][PATCH] include/sched.h: fix _CPU_op_S to support expression such as '--i' On Tue, Sep 30, 2025 at 06:17:18PM +0800, Qi.Chen@...driver.com wrote: > From: Chen Qi <Qi.Chen@...driver.com> > > We need a local variable to hold the result of (i). Otherwise, when > this marco is as with expression such as '--i', we will get > compilation error as below: > > error: operation on 'i' may be undefined [-Werror=sequence-point] > > Signed-off-by: Chen Qi <Qi.Chen@...driver.com> > --- > include/sched.h | 4 ++-- > 1 file changed, 2 insertions(+), 2 deletions(-) > > diff --git a/include/sched.h b/include/sched.h index > 8c3b53f0..e7b81ca1 100644 > --- a/include/sched.h > +++ b/include/sched.h > @@ -89,8 +89,8 @@ int sched_getcpu(void); int > sched_getaffinity(pid_t, size_t, cpu_set_t *); int > sched_setaffinity(pid_t, size_t, const cpu_set_t *); > > -#define __CPU_op_S(i, size, set, op) ( (i)/8U >= (size) ? 0 : \ > - (((unsigned long *)(set))[(i)/8/sizeof(long)] op (1UL<<((i)%(8*sizeof(long))))) ) > +#define __CPU_op_S(i, size, set, op) ({size_t _i=(i); (_i)/8U >= (size) ? 0 : \ > + (((unsigned long *)(set))[(_i)/8/sizeof(long)] op > +(1UL<<((_i)%(8*sizeof(long))))); }) > > #define CPU_SET_S(i, size, set) __CPU_op_S(i, size, set, |=) #define > CPU_CLR_S(i, size, set) __CPU_op_S(i, size, set, &=~) > -- > 2.34.1 It is expected that interfaces that are specified to be macros may evaluate their arguments more than once. Code that passes an expression with side effects is erroneous. We do not use GNUC statement-expressions or otherwise gratuitously nonstandard things in the public headers, which are intended to work with essentially any C compiler.
Powered by blists - more mailing lists
Confused about mailing lists and their use? Read about mailing lists on Wikipedia and check out these guidelines on proper formatting of your messages.