From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 2155) id 3B1FC3858D35; Tue, 4 Jul 2023 14:33:03 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 3B1FC3858D35 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1688481183; bh=zP2b4xmENHIcOa0yvHXlpWC8B2k9854duKyhBU/hkzI=; h=From:To:Subject:Date:From; b=d4utiAYnL+tUYg6G8SlPjld96iAnIMrub+q6+rVKixwfoIwoY0IHdrRIHX3XcVxpA Mi3vdtvkAtswU23RYgVp78TlDq8WQWSgwew1XPt8/AU+K0Hb3ShlJny0PKRSDlcEty En7rmgmH6M5GNaheYi/SiwwuVFG8TlJabImSQzUY= Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable From: Corinna Vinschen To: cygwin-cvs@sourceware.org Subject: [newlib-cygwin/main] Cygwin: Make safe for c89 compilations X-Act-Checkin: newlib-cygwin X-Git-Author: Mark Geisert X-Git-Refname: refs/heads/main X-Git-Oldrev: bfb16b0edef49b8e694bcb1b419bfcb5a0a3dfac X-Git-Newrev: 6422e76637d3dfcb2fcf791bb92c9cc910dd33a5 Message-Id: <20230704143303.3B1FC3858D35@sourceware.org> Date: Tue, 4 Jul 2023 14:33:03 +0000 (GMT) List-Id: https://sourceware.org/git/gitweb.cgi?p=3Dnewlib-cygwin.git;h=3D6422e76637d= 3dfcb2fcf791bb92c9cc910dd33a5 commit 6422e76637d3dfcb2fcf791bb92c9cc910dd33a5 Author: Mark Geisert AuthorDate: Mon Jul 3 17:51:41 2023 -0700 Commit: Corinna Vinschen CommitDate: Tue Jul 4 15:39:12 2023 +0200 Cygwin: Make safe for c89 compilations =20 Four modifications to include/sys/cpuset.h: * Change C++-style comments to C-style also supported by C++ * Change "inline" to "__inline" on code lines * Add "#include " to make sure __inline is defined * Don't declare loop variables on for-loop init clauses =20 Tested by first reproducing the reported issue with home-grown test programs by compiling with gcc option "-std=3Dc89", then compiling again using the modified . Other "-std=3D" options tested too. =20 Addresses: https://cygwin.com/pipermail/cygwin-patches/2023q3/012308.ht= ml Fixes: 315e5fbd99ec ("Cygwin: Fix type mismatch on sys/cpuset.h") Signed-off-by: Mark Geisert Diff: --- winsup/cygwin/include/sys/cpuset.h | 49 +++++++++++++++++++++-------------= ---- winsup/cygwin/release/3.4.7 | 3 +++ 2 files changed, 30 insertions(+), 22 deletions(-) diff --git a/winsup/cygwin/include/sys/cpuset.h b/winsup/cygwin/include/sys= /cpuset.h index d83359fdf352..0c95134ff31a 100644 --- a/winsup/cygwin/include/sys/cpuset.h +++ b/winsup/cygwin/include/sys/cpuset.h @@ -9,14 +9,16 @@ details. */ #ifndef _SYS_CPUSET_H_ #define _SYS_CPUSET_H_ =20 +#include + #ifdef __cplusplus extern "C" { #endif =20 typedef __SIZE_TYPE__ __cpu_mask; -#define __CPU_SETSIZE 1024 // maximum number of logical processors tracked -#define __NCPUBITS (8 * sizeof (__cpu_mask)) // max size of processor gro= up -#define __CPU_GROUPMAX (__CPU_SETSIZE / __NCPUBITS) // maximum group numb= er +#define __CPU_SETSIZE 1024 /* maximum number of logical processors tracke= d */ +#define __NCPUBITS (8 * sizeof (__cpu_mask)) /* max size of processor gro= up */ +#define __CPU_GROUPMAX (__CPU_SETSIZE / __NCPUBITS) /* maximum group numb= er */ =20 #define __CPUELT(cpu) ((cpu) / __NCPUBITS) #define __CPUMASK(cpu) ((__cpu_mask) 1 << ((cpu) % __NCPUBITS)) @@ -32,21 +34,21 @@ int __sched_getaffinity_sys (pid_t, size_t, cpu_set_t *= ); /* These macros alloc or free dynamically-sized cpu sets of size 'num' cpu= s. Allocations are padded such that full-word operations can be done easil= y. */ #define CPU_ALLOC_SIZE(num) __cpuset_alloc_size (num) -static inline size_t +static __inline size_t __cpuset_alloc_size (int num) { return (size_t) (((num + __NCPUBITS - 1) / __NCPUBITS) * sizeof (__cpu_m= ask)); } =20 #define CPU_ALLOC(num) __cpuset_alloc (num) -static inline cpu_set_t * +static __inline cpu_set_t * __cpuset_alloc (int num) { return (cpu_set_t *) __builtin_malloc (CPU_ALLOC_SIZE(num)); } =20 #define CPU_FREE(set) __cpuset_free (set) -static inline void +static __inline void __cpuset_free (cpu_set_t *set) { __builtin_free (set); @@ -54,14 +56,14 @@ __cpuset_free (cpu_set_t *set) =20 /* These _S macros operate on dynamically-sized cpu sets of size 'siz' byt= es */ #define CPU_ZERO_S(siz, set) __cpuset_zero_s (siz, set) -static inline void +static __inline void __cpuset_zero_s (size_t siz, cpu_set_t *set) { (void) __builtin_memset (set, 0, siz); } =20 #define CPU_SET_S(cpu, siz, set) __cpuset_set_s (cpu, siz, set) -static inline void +static __inline void __cpuset_set_s (int cpu, size_t siz, cpu_set_t *set) { if (cpu >=3D 0 && cpu < 8 * siz) @@ -69,7 +71,7 @@ __cpuset_set_s (int cpu, size_t siz, cpu_set_t *set) } =20 #define CPU_CLR_S(cpu, siz, set) __cpuset_clr_s (cpu, siz, set) -static inline void +static __inline void __cpuset_clr_s (int cpu, size_t siz, cpu_set_t *set) { if (cpu >=3D 0 && cpu < 8 * siz) @@ -77,7 +79,7 @@ __cpuset_clr_s (int cpu, size_t siz, cpu_set_t *set) } =20 #define CPU_ISSET_S(cpu, siz, set) __cpuset_isset_s (cpu, siz, set) -static inline int +static __inline int __cpuset_isset_s (int cpu, size_t siz, cpu_set_t *set) { int res =3D 0; @@ -87,45 +89,48 @@ __cpuset_isset_s (int cpu, size_t siz, cpu_set_t *set) } =20 #define CPU_COUNT_S(siz, set) __cpuset_count_s (siz, set) -static inline int +static __inline int __cpuset_count_s (size_t siz, cpu_set_t *set) { - int res =3D 0; - for (int i =3D 0; i < siz / sizeof (__cpu_mask); i++) + int i, res =3D 0; + for (i =3D 0; i < siz / sizeof (__cpu_mask); i++) res +=3D __builtin_popcountl ((set)->__bits[i]); return res; } =20 #define CPU_AND_S(siz, dst, src1, src2) __cpuset_and_s (siz, dst, src1, sr= c2) -static inline void +static __inline void __cpuset_and_s (size_t siz, cpu_set_t *dst, cpu_set_t *src1, cpu_set_t *sr= c2) { - for (int i =3D 0; i < siz / sizeof (__cpu_mask); i++) + int i; + for (i =3D 0; i < siz / sizeof (__cpu_mask); i++) (dst)->__bits[i] =3D (src1)->__bits[i] & (src2)->__bits[i]; } =20 #define CPU_OR_S(siz, dst, src1, src2) __cpuset_or_s (siz, dst, src1, src2) -static inline void +static __inline void __cpuset_or_s (size_t siz, cpu_set_t *dst, cpu_set_t *src1, cpu_set_t *src= 2) { - for (int i =3D 0; i < siz / sizeof (__cpu_mask); i++) + int i; + for (i =3D 0; i < siz / sizeof (__cpu_mask); i++) (dst)->__bits[i] =3D (src1)->__bits[i] | (src2)->__bits[i]; } =20 #define CPU_XOR_S(siz, dst, src1, src2) __cpuset_xor_s (siz, dst, src1, sr= c2) -static inline void +static __inline void __cpuset_xor_s (size_t siz, cpu_set_t *dst, cpu_set_t *src1, cpu_set_t *sr= c2) { - for (int i =3D 0; i < siz / sizeof (__cpu_mask); i++) + int i; + for (i =3D 0; i < siz / sizeof (__cpu_mask); i++) (dst)->__bits[i] =3D (src1)->__bits[i] ^ (src2)->__bits[i]; } =20 #define CPU_EQUAL_S(siz, src1, src2) __cpuset_equal_s (siz, src1, src2) -static inline int +static __inline int __cpuset_equal_s (size_t siz, cpu_set_t *src1, cpu_set_t *src2) { - int res =3D 1; - for (int i =3D 0; res && i < siz / sizeof (__cpu_mask); i++) + int i, res =3D 1; + for (i =3D 0; res && i < siz / sizeof (__cpu_mask); i++) res &=3D (src1)->__bits[i] =3D=3D (src2)->__bits[i]; return res; } diff --git a/winsup/cygwin/release/3.4.7 b/winsup/cygwin/release/3.4.7 index 0e6922163aa3..923408ec2dce 100644 --- a/winsup/cygwin/release/3.4.7 +++ b/winsup/cygwin/release/3.4.7 @@ -25,3 +25,6 @@ Bug Fixes - Fix return code and errno set by renameat2, if oldfile and newfile refer to the same file, and the RENAME_NOREPLACE flag is set. Addresses: https://cygwin.com/pipermail/cygwin/2023-April/253514.html + +- Make safe for c89 compilations. + Addresses: https://cygwin.com/pipermail/cygwin-patches/2023q3/012308.html