View Single Post
Old 03-24-2017, 01:30 PM   #39
KevinH
Sigil Developer
KevinH ought to be getting tired of karma fortunes by now.KevinH ought to be getting tired of karma fortunes by now.KevinH ought to be getting tired of karma fortunes by now.KevinH ought to be getting tired of karma fortunes by now.KevinH ought to be getting tired of karma fortunes by now.KevinH ought to be getting tired of karma fortunes by now.KevinH ought to be getting tired of karma fortunes by now.KevinH ought to be getting tired of karma fortunes by now.KevinH ought to be getting tired of karma fortunes by now.KevinH ought to be getting tired of karma fortunes by now.KevinH ought to be getting tired of karma fortunes by now.
 
Posts: 7,644
Karma: 5433388
Join Date: Nov 2009
Device: many
For the record ...

I filed a bug with Apple's developer site ...

The following testcase shows that the newly added function in sys/random.h is not in any way detectable as only being available on 10.12.

When compiled with XCode 8 on OSX 10.12

clang -mmacosx-version-min=10.9 -Werror=partial-availability -o testcase testcase.c

will compile and run on 10.12 but will fail with missing symbols on all earlier releases.

testcase.c
Code:
#include <sys/types.h>
#include <stdio.h>
#include <sys/random.h>

int main(int argc, char **argv)
{
  unsigned x;
  if (getentropy(&x, sizeof(x)) < 0)
    perror("getentropy");
  else
    printf("%u\n", x);
  return 0;
}
If getentropy in sys/random.h was properly protected by an availability macro such as testcase2.c

testcase2.c
Code:
#include <sys/types.h>
#include <stdio.h>
#include <AvailabilityMacros.h>

extern int getentropy(void* buffer, size_t size) AVAILABLE_MAC_OS_X_VERSION_10_12_AND_LATER;

int main(int argc, char **argv)
{
  unsigned x;
  if (getentropy(&x, sizeof(x)) < 0)
    perror("getentropy");
  else
    printf("%u\n", x);
  return 0;
}
The above compile would properly detect that getentropy did not exists in earlier version of OSX.

Code:
kbhend$ clang -mmacosx-version-min=10.9 -Werror=partial-availability -o testcase2 testcase2.c
testcase2.c:14:7: error: 'getentropy' is partial: introduced in macOS 10.12 [-Werror,-Wpartial-availability]
  if (getentropy(&x, sizeof(x)) < 0)
      ^
testcase2.c:9:12: note: 'getentropy' has been explicitly marked partial here
extern int getentropy(void* buffer, size_t size) AVAILABLE_MAC_OS_X_VERSION_10_12_AND_LATER;
           ^
testcase2.c:14:7: note: explicitly redeclare 'getentropy' to silence this warning
  if (getentropy(&x, sizeof(x)) < 0)
      ^
1 error generated.

If Apple can fix bugs like this, then we can fix Python's configure.ac/configure to more properly handle this case and not just to claim that it exists just because it is run on OSX 10.12.

Please note that we can NOT use the linker flags -Wl,-no_weak_imports to detect this case at link time as Python properly handles and uses weak symbols with #pragma weak properly used with statvfs, fstatvfs, lchown, and inet_aton so using weak symbols is needed.

Just wanted all of this out there in case in a few months I forget all of this.
KevinH is online now   Reply With Quote