diff mbox series

[2/2] libada: Check for the presence of _SC_NPROCESSORS_ONLN

Message ID alpine.LFD.2.21.2011151545390.4064799@eddie.linux-mips.org
State Superseded
Headers show
Series Fixes for old version NetBSD targets | expand

Commit Message

Maciej W. Rozycki Nov. 15, 2020, 5:44 p.m. UTC
Check for the presence of _SC_NPROCESSORS_ONLN rather than using it 
unconditionally with `sysconf', fixing a compilation error:

adaint.c: In function '__gnat_number_of_cpus':
adaint.c:2398:26: error: '_SC_NPROCESSORS_ONLN' undeclared (first use in this function)
 2398 |   cores = (int) sysconf (_SC_NPROCESSORS_ONLN);
      |                          ^~~~~~~~~~~~~~~~~~~~
adaint.c:2398:26: note: each undeclared identifier is reported only once for each function it appears in

at least with with VAX/NetBSD 1.6.2.  Assume _SC_NPROCESSORS_ONLN is a 
macro and use #ifdef like in other places across GCC sources.

	gcc/ada/
	* adaint.c (__gnat_number_of_cpus): Check for the presence of 
	_SC_NPROCESSORS_ONLN before using it.
---
NB we could probably replace the list of OS #ifdefs with just a check for 
_SC_NPROCESSORS_ONLN, making use of it automagically with any new OS that 
supports it, as from the length of the list has grown up to I gather the 
`sysconf' API for this variable has become a semi-established standard now 
even though not actually listed by the relevant standards.
---
 gcc/ada/adaint.c |    2 ++
 1 file changed, 2 insertions(+)

gcc-netbsd-libada-sc-nprocessors-onln.diff

Comments

Arnaud Charlet Nov. 15, 2020, 7:11 p.m. UTC | #1
> 	gcc/ada/
> 	* adaint.c (__gnat_number_of_cpus): Check for the presence of 
> 	_SC_NPROCESSORS_ONLN before using it.
> ---
> NB we could probably replace the list of OS #ifdefs with just a check for 
> _SC_NPROCESSORS_ONLN, making use of it automagically with any new OS that 
> supports it, as from the length of the list has grown up to I gather the 
> `sysconf' API for this variable has become a semi-established standard now 
> even though not actually listed by the relevant standards.

Indeed, so a better patch would be to use

#if defined (_SC_NPROCESSORS_ONLN)

instead as you noted, so let's do that.

Arno
diff mbox series

Patch

Index: gcc/gcc/ada/adaint.c
===================================================================
--- gcc.orig/gcc/ada/adaint.c
+++ gcc/gcc/ada/adaint.c
@@ -2479,7 +2479,9 @@  __gnat_number_of_cpus (void)
 #if defined (__linux__) || defined (__sun__) || defined (_AIX) \
   || defined (__APPLE__) || defined (__FreeBSD__) || defined (__OpenBSD__) \
   || defined (__DragonFly__) || defined (__NetBSD__)
+#ifdef _SC_NPROCESSORS_ONLN
   cores = (int) sysconf (_SC_NPROCESSORS_ONLN);
+#endif
 
 #elif defined (__QNX__)
   cores = (int) _syspage_ptr->num_cpu;