public inbox for cygwin-patches@cygwin.com
 help / color / mirror / Atom feed
* [PATCH] Cygwin: Make <sys/cpuset.h> safe for c89 compilations
@ 2023-07-03  6:17 Mark Geisert
  2023-07-03  6:59 ` Brian Inglis
  0 siblings, 1 reply; 5+ messages in thread
From: Mark Geisert @ 2023-07-03  6:17 UTC (permalink / raw)
  To: cygwin-patches; +Cc: Mark Geisert

Three modifications to include/sys/cpuset.h:
* Change C++-style comments to C-style also supported by C++
* Change "inline" to "__inline" on code lines
* Don't declare loop variables on for-loop init clauses

Tested by first reproducing the reported issue with home-grown test
programs by compiling with gcc option "-std=c89", then compiling again
using the modified <sys/cpuset.h>. Other "-std=" options tested too.

Addresses: https://cygwin.com/pipermail/cygwin-patches/2023q3/012308.html
Fixes: 315e5fbd99ec ("Cygwin: Fix type mismatch on sys/cpuset.h")

---
 winsup/cygwin/include/sys/cpuset.h | 47 ++++++++++++++++--------------
 winsup/cygwin/release/3.4.7        |  3 ++
 2 files changed, 28 insertions(+), 22 deletions(-)

diff --git a/winsup/cygwin/include/sys/cpuset.h b/winsup/cygwin/include/sys/cpuset.h
index d83359fdf..01576b041 100644
--- a/winsup/cygwin/include/sys/cpuset.h
+++ b/winsup/cygwin/include/sys/cpuset.h
@@ -14,9 +14,9 @@ extern "C" {
 #endif
 
 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 group
-#define __CPU_GROUPMAX (__CPU_SETSIZE / __NCPUBITS)  // maximum group number
+#define __CPU_SETSIZE 1024  /* maximum number of logical processors tracked */
+#define __NCPUBITS (8 * sizeof (__cpu_mask))  /* max size of processor group */
+#define __CPU_GROUPMAX (__CPU_SETSIZE / __NCPUBITS)  /* maximum group number */
 
 #define __CPUELT(cpu)  ((cpu) / __NCPUBITS)
 #define __CPUMASK(cpu) ((__cpu_mask) 1 << ((cpu) % __NCPUBITS))
@@ -32,21 +32,21 @@ int __sched_getaffinity_sys (pid_t, size_t, cpu_set_t *);
 /* These macros alloc or free dynamically-sized cpu sets of size 'num' cpus.
    Allocations are padded such that full-word operations can be done easily. */
 #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_mask));
 }
 
 #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));
 }
 
 #define CPU_FREE(set) __cpuset_free (set)
-static inline void
+static __inline void
 __cpuset_free (cpu_set_t *set)
 {
   __builtin_free (set);
@@ -54,14 +54,14 @@ __cpuset_free (cpu_set_t *set)
 
 /* These _S macros operate on dynamically-sized cpu sets of size 'siz' bytes */
 #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);
 }
 
 #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 >= 0 && cpu < 8 * siz)
@@ -69,7 +69,7 @@ __cpuset_set_s (int cpu, size_t siz, cpu_set_t *set)
 }
 
 #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 >= 0 && cpu < 8 * siz)
@@ -77,7 +77,7 @@ __cpuset_clr_s (int cpu, size_t siz, cpu_set_t *set)
 }
 
 #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 = 0;
@@ -87,45 +87,48 @@ __cpuset_isset_s (int cpu, size_t siz, cpu_set_t *set)
 }
 
 #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 = 0;
-  for (int i = 0; i < siz / sizeof (__cpu_mask); i++)
+  int i, res = 0;
+  for (i = 0; i < siz / sizeof (__cpu_mask); i++)
     res += __builtin_popcountl ((set)->__bits[i]);
   return res;
 }
 
 #define CPU_AND_S(siz, dst, src1, src2) __cpuset_and_s (siz, dst, src1, src2)
-static inline void
+static __inline void
 __cpuset_and_s (size_t siz, cpu_set_t *dst, cpu_set_t *src1, cpu_set_t *src2)
 {
-  for (int i = 0; i < siz / sizeof (__cpu_mask); i++)
+  int i;
+  for (i = 0; i < siz / sizeof (__cpu_mask); i++)
     (dst)->__bits[i] = (src1)->__bits[i] & (src2)->__bits[i];
 }
 
 #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 *src2)
 {
-  for (int i = 0; i < siz / sizeof (__cpu_mask); i++)
+  int i;
+  for (i = 0; i < siz / sizeof (__cpu_mask); i++)
     (dst)->__bits[i] = (src1)->__bits[i] | (src2)->__bits[i];
 }
 
 #define CPU_XOR_S(siz, dst, src1, src2) __cpuset_xor_s (siz, dst, src1, src2)
-static inline void
+static __inline void
 __cpuset_xor_s (size_t siz, cpu_set_t *dst, cpu_set_t *src1, cpu_set_t *src2)
 {
-  for (int i = 0; i < siz / sizeof (__cpu_mask); i++)
+  int i;
+  for (i = 0; i < siz / sizeof (__cpu_mask); i++)
     (dst)->__bits[i] = (src1)->__bits[i] ^ (src2)->__bits[i];
 }
 
 #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 = 1;
-  for (int i = 0; res && i < siz / sizeof (__cpu_mask); i++)
+  int i, res = 1;
+  for (i = 0; res && i < siz / sizeof (__cpu_mask); i++)
     res &= (src1)->__bits[i] == (src2)->__bits[i];
   return res;
 }
diff --git a/winsup/cygwin/release/3.4.7 b/winsup/cygwin/release/3.4.7
index 0e6922163..923408ec2 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 <sys/cpuset.h> safe for c89 compilations.
+  Addresses: https://cygwin.com/pipermail/cygwin-patches/2023q3/012308.html
-- 
2.39.0


^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH] Cygwin: Make <sys/cpuset.h> safe for c89 compilations
  2023-07-03  6:17 [PATCH] Cygwin: Make <sys/cpuset.h> safe for c89 compilations Mark Geisert
@ 2023-07-03  6:59 ` Brian Inglis
  2023-07-03  9:27   ` Mark Geisert
  0 siblings, 1 reply; 5+ messages in thread
From: Brian Inglis @ 2023-07-03  6:59 UTC (permalink / raw)
  To: cygwin-patches

On 2023-07-03 00:17, Mark Geisert wrote:
> Three modifications to include/sys/cpuset.h:
> * Change C++-style comments to C-style also supported by C++
> * Change "inline" to "__inline" on code lines
> * Don't declare loop variables on for-loop init clauses
> 
> Tested by first reproducing the reported issue with home-grown test
> programs by compiling with gcc option "-std=c89", then compiling again
> using the modified <sys/cpuset.h>. Other "-std=" options tested too.
> 
> Addresses: https://cygwin.com/pipermail/cygwin-patches/2023q3/012308.html
> Fixes: 315e5fbd99ec ("Cygwin: Fix type mismatch on sys/cpuset.h")
> 
> ---
>   winsup/cygwin/include/sys/cpuset.h | 47 ++++++++++++++++--------------
>   winsup/cygwin/release/3.4.7        |  3 ++
>   2 files changed, 28 insertions(+), 22 deletions(-)
> 
> diff --git a/winsup/cygwin/include/sys/cpuset.h b/winsup/cygwin/include/sys/cpuset.h
> index d83359fdf..01576b041 100644
> --- a/winsup/cygwin/include/sys/cpuset.h
> +++ b/winsup/cygwin/include/sys/cpuset.h
> @@ -14,9 +14,9 @@ extern "C" {
>   #endif
>   
>   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 group
> -#define __CPU_GROUPMAX (__CPU_SETSIZE / __NCPUBITS)  // maximum group number
> +#define __CPU_SETSIZE 1024  /* maximum number of logical processors tracked */
> +#define __NCPUBITS (8 * sizeof (__cpu_mask))  /* max size of processor group */
> +#define __CPU_GROUPMAX (__CPU_SETSIZE / __NCPUBITS)  /* maximum group number */
>   
>   #define __CPUELT(cpu)  ((cpu) / __NCPUBITS)
>   #define __CPUMASK(cpu) ((__cpu_mask) 1 << ((cpu) % __NCPUBITS))
> @@ -32,21 +32,21 @@ int __sched_getaffinity_sys (pid_t, size_t, cpu_set_t *);
>   /* These macros alloc or free dynamically-sized cpu sets of size 'num' cpus.
>      Allocations are padded such that full-word operations can be done easily. */
>   #define CPU_ALLOC_SIZE(num) __cpuset_alloc_size (num)

Does this patch need __inline defined e.g.

   +#include <sys/cdefs.h>

did you perhaps include this directly in your test cases?

> -static inline size_t
> +static __inline size_t
...
> diff --git a/winsup/cygwin/release/3.4.7 b/winsup/cygwin/release/3.4.7
> index 0e6922163..923408ec2 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 <sys/cpuset.h> safe for c89 compilations.
> +  Addresses: https://cygwin.com/pipermail/cygwin-patches/2023q3/012308.html

-- 
Take care. Thanks, Brian Inglis              Calgary, Alberta, Canada

La perfection est atteinte                   Perfection is achieved
non pas lorsqu'il n'y a plus rien à ajouter  not when there is no more to add
mais lorsqu'il n'y a plus rien à retirer     but when there is no more to cut
                                 -- Antoine de Saint-Exupéry

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH] Cygwin: Make <sys/cpuset.h> safe for c89 compilations
  2023-07-03  6:59 ` Brian Inglis
@ 2023-07-03  9:27   ` Mark Geisert
  2023-07-03 10:56     ` Corinna Vinschen
  0 siblings, 1 reply; 5+ messages in thread
From: Mark Geisert @ 2023-07-03  9:27 UTC (permalink / raw)
  To: cygwin-patches

Hi Brian,

Brian Inglis wrote:
> On 2023-07-03 00:17, Mark Geisert wrote:
>> Three modifications to include/sys/cpuset.h:
>> * Change C++-style comments to C-style also supported by C++
>> * Change "inline" to "__inline" on code lines
>> * Don't declare loop variables on for-loop init clauses
>>
>> Tested by first reproducing the reported issue with home-grown test
>> programs by compiling with gcc option "-std=c89", then compiling again
>> using the modified <sys/cpuset.h>. Other "-std=" options tested too.
>>
>> Addresses: https://cygwin.com/pipermail/cygwin-patches/2023q3/012308.html
>> Fixes: 315e5fbd99ec ("Cygwin: Fix type mismatch on sys/cpuset.h")
>>
>> ---
>>   winsup/cygwin/include/sys/cpuset.h | 47 ++++++++++++++++--------------
>>   winsup/cygwin/release/3.4.7        |  3 ++
>>   2 files changed, 28 insertions(+), 22 deletions(-)
>>
>> diff --git a/winsup/cygwin/include/sys/cpuset.h 
>> b/winsup/cygwin/include/sys/cpuset.h
>> index d83359fdf..01576b041 100644
>> --- a/winsup/cygwin/include/sys/cpuset.h
>> +++ b/winsup/cygwin/include/sys/cpuset.h
>> @@ -14,9 +14,9 @@ extern "C" {
>>   #endif
>>   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 group
>> -#define __CPU_GROUPMAX (__CPU_SETSIZE / __NCPUBITS)  // maximum group number
>> +#define __CPU_SETSIZE 1024  /* maximum number of logical processors tracked */
>> +#define __NCPUBITS (8 * sizeof (__cpu_mask))  /* max size of processor group */
>> +#define __CPU_GROUPMAX (__CPU_SETSIZE / __NCPUBITS)  /* maximum group number */
>>   #define __CPUELT(cpu)  ((cpu) / __NCPUBITS)
>>   #define __CPUMASK(cpu) ((__cpu_mask) 1 << ((cpu) % __NCPUBITS))
>> @@ -32,21 +32,21 @@ int __sched_getaffinity_sys (pid_t, size_t, cpu_set_t *);
>>   /* These macros alloc or free dynamically-sized cpu sets of size 'num' cpus.
>>      Allocations are padded such that full-word operations can be done easily. */
>>   #define CPU_ALLOC_SIZE(num) __cpuset_alloc_size (num)
> 
> Does this patch need __inline defined e.g.
> 
>    +#include <sys/cdefs.h>
> 
> did you perhaps include this directly in your test cases?
> 
>> -static inline size_t
>> +static __inline size_t
> ...

No, not directly.  The test case with the shortest list of #includes has:
#define _GNU_SOURCE
#include <assert.h>
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <sys/cpuset.h>
#include <sched.h>

So it's apparently defined by one of those or some sub-include.  But indeed it's 
not safe to depend on that so I will try harder to figure out what other 
occurrences of __inline in the Cygwin source tree are depending on for the definition.
Thanks,

..mark

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH] Cygwin: Make <sys/cpuset.h> safe for c89 compilations
  2023-07-03  9:27   ` Mark Geisert
@ 2023-07-03 10:56     ` Corinna Vinschen
  2023-07-04  0:44       ` Mark Geisert
  0 siblings, 1 reply; 5+ messages in thread
From: Corinna Vinschen @ 2023-07-03 10:56 UTC (permalink / raw)
  To: Mark Geisert; +Cc: cygwin-patches

Hi Mark,

On Jul  3 02:27, Mark Geisert wrote:
> Hi Brian,
> 
> Brian Inglis wrote:
> > On 2023-07-03 00:17, Mark Geisert wrote:
> > > Three modifications to include/sys/cpuset.h:
> > > * Change C++-style comments to C-style also supported by C++
> > > * Change "inline" to "__inline" on code lines
> > > * Don't declare loop variables on for-loop init clauses
> > > 
> > > Tested by first reproducing the reported issue with home-grown test
> > > programs by compiling with gcc option "-std=c89", then compiling again
> > > using the modified <sys/cpuset.h>. Other "-std=" options tested too.
> > > 
> > > Addresses: https://cygwin.com/pipermail/cygwin-patches/2023q3/012308.html
> > > Fixes: 315e5fbd99ec ("Cygwin: Fix type mismatch on sys/cpuset.h")

Signed-off-by?

> > Does this patch need __inline defined e.g.
> > 
> >    +#include <sys/cdefs.h>
> > 
> > did you perhaps include this directly in your test cases?
> > 
> > > -static inline size_t
> > > +static __inline size_t
> > ...
> 
> No, not directly.  The test case with the shortest list of #includes has:
> #define _GNU_SOURCE
> #include <assert.h>
> #include <stdio.h>
> #include <stdlib.h>
> #include <unistd.h>
> #include <sys/cpuset.h>
> #include <sched.h>
> 
> So it's apparently defined by one of those or some sub-include.  But indeed
> it's not safe to depend on that so I will try harder to figure out what
> other occurrences of __inline in the Cygwin source tree are depending on for
> the definition.
> Thanks,

Great.


Thanks,
Corinna

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH] Cygwin: Make <sys/cpuset.h> safe for c89 compilations
  2023-07-03 10:56     ` Corinna Vinschen
@ 2023-07-04  0:44       ` Mark Geisert
  0 siblings, 0 replies; 5+ messages in thread
From: Mark Geisert @ 2023-07-04  0:44 UTC (permalink / raw)
  To: cygwin-patches

Hi Corinna,

Corinna Vinschen wrote:
> On Jul  3 02:27, Mark Geisert wrote:
>> Brian Inglis wrote:
>>> On 2023-07-03 00:17, Mark Geisert wrote:
>>>> Three modifications to include/sys/cpuset.h:
>>>> * Change C++-style comments to C-style also supported by C++
>>>> * Change "inline" to "__inline" on code lines
>>>> * Don't declare loop variables on for-loop init clauses
>>>>
>>>> Tested by first reproducing the reported issue with home-grown test
>>>> programs by compiling with gcc option "-std=c89", then compiling again
>>>> using the modified <sys/cpuset.h>. Other "-std=" options tested too.
>>>>
>>>> Addresses: https://cygwin.com/pipermail/cygwin-patches/2023q3/012308.html
>>>> Fixes: 315e5fbd99ec ("Cygwin: Fix type mismatch on sys/cpuset.h")
> 
> Signed-off-by?

Eh, I was unsure if submitter or reviewer provides this.  Submitter it is.

>>> Does this patch need __inline defined e.g.
>>>
>>>     +#include <sys/cdefs.h>
>>>
>>> did you perhaps include this directly in your test cases?
>>>
>>>> -static inline size_t
>>>> +static __inline size_t
>>> ...
>>
>> No, not directly.  The test case with the shortest list of #includes has:
>> #define _GNU_SOURCE
>> #include <assert.h>
>> #include <stdio.h>
>> #include <stdlib.h>
>> #include <unistd.h>
>> #include <sys/cpuset.h>
>> #include <sched.h>
>>
>> So it's apparently defined by one of those or some sub-include.  But indeed
>> it's not safe to depend on that so I will try harder to figure out what
>> other occurrences of __inline in the Cygwin source tree are depending on for
>> the definition.

In this specific case <stdio.h> includes <sys/cdefs.h>.  I figure one can't depend 
on what's included, or in what order.  So as Brian suggested, I've added an 
"#include <sys/cdefs.h>".  Not every site of __inline within the Cygwin source 
tree does this; I guess those will be fixed if/when reported as a problem.

v2 patch for 3.4.7 is on its way in.  If it's OK I'll then submit it for 3.3.6.
Thanks all for the review comments,

..mark




^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2023-07-04  0:44 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-07-03  6:17 [PATCH] Cygwin: Make <sys/cpuset.h> safe for c89 compilations Mark Geisert
2023-07-03  6:59 ` Brian Inglis
2023-07-03  9:27   ` Mark Geisert
2023-07-03 10:56     ` Corinna Vinschen
2023-07-04  0:44       ` Mark Geisert

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).