Annotation of pkgsrc/lang/python39/patches/patch-Python_bootstrap__hash.c, revision 1.1

1.1     ! sjmulder    1: $NetBSD$
        !             2: 
        !             3: Support for macOS 11 and Apple Silicon (ARM). Backported from:
        !             4: https://github.com/python/cpython/pull/22855
        !             5: 
        !             6: --- Python/bootstrap_hash.c.orig       2020-10-05 15:07:58.000000000 +0000
        !             7: +++ Python/bootstrap_hash.c
        !             8: @@ -25,6 +25,16 @@
        !             9:  #  include <sanitizer/msan_interface.h>
        !            10:  #endif
        !            11:  
        !            12: +#if defined(__APPLE__) && defined(__has_builtin) 
        !            13: +#  if __has_builtin(__builtin_available)
        !            14: +#    define HAVE_GETENTRYPY_GETRANDOM_RUNTIME __builtin_available(macOS 10.12, iOS 10.10, tvOS 10.0, watchOS 3.0, *)
        !            15: +#  endif
        !            16: +#endif
        !            17: +#ifndef HAVE_GETENTRYPY_GETRANDOM_RUNTIME
        !            18: +#  define HAVE_GETENTRYPY_GETRANDOM_RUNTIME 1
        !            19: +#endif
        !            20: +
        !            21: +
        !            22:  #ifdef Py_DEBUG
        !            23:  int _Py_HashSecret_Initialized = 0;
        !            24:  #else
        !            25: @@ -208,6 +218,16 @@ py_getrandom(void *buffer, Py_ssize_t si
        !            26:       error.
        !            27:  
        !            28:     getentropy() is retried if it failed with EINTR: interrupted by a signal. */
        !            29: +
        !            30: +#if defined(__APPLE__) && defined(__has_attribute) && __has_attribute(availability)
        !            31: +static int
        !            32: +py_getentropy(char *buffer, Py_ssize_t size, int raise) 
        !            33: +        __attribute__((availability(macos,introduced=10.12)))
        !            34: +        __attribute__((availability(ios,introduced=10.0)))
        !            35: +        __attribute__((availability(tvos,introduced=10.0)))
        !            36: +        __attribute__((availability(watchos,introduced=3.0)));
        !            37: +#endif
        !            38: +
        !            39:  static int
        !            40:  py_getentropy(char *buffer, Py_ssize_t size, int raise)
        !            41:  {
        !            42: @@ -498,19 +518,21 @@ pyurandom(void *buffer, Py_ssize_t size,
        !            43:  #else
        !            44:  
        !            45:  #if defined(PY_GETRANDOM) || defined(PY_GETENTROPY)
        !            46: +    if (HAVE_GETENTRYPY_GETRANDOM_RUNTIME) {
        !            47:  #ifdef PY_GETRANDOM
        !            48: -    res = py_getrandom(buffer, size, blocking, raise);
        !            49: +        res = py_getrandom(buffer, size, blocking, raise);
        !            50:  #else
        !            51: -    res = py_getentropy(buffer, size, raise);
        !            52: +        res = py_getentropy(buffer, size, raise);
        !            53:  #endif
        !            54: -    if (res < 0) {
        !            55: -        return -1;
        !            56: -    }
        !            57: -    if (res == 1) {
        !            58: -        return 0;
        !            59: -    }
        !            60: -    /* getrandom() or getentropy() function is not available: failed with
        !            61: -       ENOSYS or EPERM. Fall back on reading from /dev/urandom. */
        !            62: +        if (res < 0) {
        !            63: +            return -1;
        !            64: +        }
        !            65: +        if (res == 1) {
        !            66: +            return 0;
        !            67: +        }
        !            68: +        /* getrandom() or getentropy() function is not available: failed with
        !            69: +           ENOSYS or EPERM. Fall back on reading from /dev/urandom. */
        !            70: +        } /* end of availability block */
        !            71:  #endif
        !            72:  
        !            73:      return dev_urandom(buffer, size, raise);

CVSweb <webmaster@jp.NetBSD.org>