[MacPorts] #54068: mozjs17 @17.0.0_5 won't build (on PPC Tiger, Mac OS X 10.4.11) because sys/sysctl.h does not provide _SC_NPROCESSORS_ONLN but HW_NCPU

MacPorts noreply at macports.org
Wed May 3 22:35:00 UTC 2017

#54068: mozjs17  @17.0.0_5 won't build (on PPC Tiger, Mac OS X 10.4.11) because
sys/sysctl.h does not provide _SC_NPROCESSORS_ONLN but HW_NCPU
  Reporter:  ballapete  |      Owner:  juanrgar
      Type:  defect     |     Status:  assigned
  Priority:  Normal     |  Milestone:
 Component:  ports      |    Version:  2.4.1
Resolution:             |   Keywords:  haspatch
      Port:  mozjs17    |

Comment (by kencu):

 I tried sysconf(HW_NCPU) on my Tiger machine with 2 processors, but
 sysconf(HW_NCPU) returns 100 processors, so although it does compile, it
 does not return proper values, which is no surprise because sysconf does
 not understand HW_NCPU as a selector to return the number of CPUs, even
 though it does compile it. Previously, most people who fixed this function
 for Tiger just returned `1` processor and forgot about it, which is
 practical enough, if inaccurate. But I had a few minutes today, so I came
 up with something that might be useful.

 let's say you have a generic program using the sysconf function which
 fails on Tiger, like this:
 #include <unistd.h>
 #include <stdio.h>

 int main() {
    printf("number of cpus %d \n\n", (int)sysconf(_SC_NPROCESSORS_ONLN));

 A simple enough replacement function, which returns a long (as sysconf
 does) but with the proper number of processors and also defines
 _SC_NPROCESSORS_ONLN to fix the define error on Tiger, makes the editing
 reasonably easily:

 /*  Tiger replacement function */
 #include <sys/sysctl.h>

 long tigersysconf(int name){
   if (name == _SC_NPROCESSORS_ONLN) {
     int nm[2];
     size_t len = 4;
     uint32_t count;

     nm[0] = CTL_HW; nm[1] = HW_AVAILCPU;
     sysctl(nm, 2, &count, &len, NULL, 0);

     if (count < 1) {
       nm[1] = HW_NCPU;
       sysctl(nm, 2, &count, &len, NULL, 0);
       if (count < 1) { count = 1; }
     return (long)count;
   return -1;
 } /*  end of Tiger replacement function */

 so you would paste that Tiger replacement function up near the top of the
 source file, and change the function call from this
 to this - just one single simple edit in the source:
 and this works correctly.

 tigerg5:~/testnumproc cunningh$ gcc -o testsysnumproc testsysnumproc.c
 tigerg5:~/testnumproc cunningh$ ./testsysnumproc
 number of cpus 2

 This could either be set up as a simple  patch to be included only on
 Tiger, or wrapped up in `#ifdef __APPLE__` etc preprocessor guards for
 permanent inclusion in the source file. I didn't paste that version in
 here, as it looks like spaghetti code with all the ifdefs, and I didn't
 want to distract from how simple this fix really is.

 I just used this on a fix to repair a broken build of gcc6 on Tiger Intel
 i386, and it seems to work OK.

Ticket URL: <https://trac.macports.org/ticket/54068#comment:7>
MacPorts <https://www.macports.org/>
Ports system for macOS

More information about the macports-tickets mailing list