• Sam Gross's avatar
    [0.29] Use atomic reference counting in MemoryView in more cases (GH-4912) (GH-4915) · f1748bb8
    Sam Gross authored
    This fixes a few issues in MemoryView_C.c to allow atomic reference
    counting to be used in more cases.
    
     - Enable GNU atomics for `__GNUC__` >= 5. Previously, GCC 5.0, 6.0, X.0
       versions used lock-based reference counting due to an incorrect preprocessor check.
    
     - Typo in `__GNUC_PATCHLEVEL__` macro (missing underscores)
    
     - Enable atomics in MSVC and fix returned values. InterlockedExchangeAdd
       returns the *initial* value (like __sync_fetch_and_add).
       InterlockedIncrement returned the *resulting* value (post increment),
       which would have been incorrect if MSVC atomics had been enabled.
    
    Also avoids allocating a lock in MemoryView when atomics are available,
    which additionally fixes a thread-safety issue in the "nogil" CPython fork.
    
    * Use _InterlockedExchangeAdd intrinsic
    
    The InterlockedExchangeSubtract function isn't available in older
    versions of MSVC, while InterlockedExchangeAdd is available since
    Windows XP.
    
    The intrinsic variant (with the underscore prefix) avoids needing to
    include the entire Windows.h header.
    
    * Only use MSVC atomics when compiling for the "nogil" CPython fork
      to prevent potential breakage of existing Windows setups.
    f1748bb8
fused_redeclare_T3111.pyx 918 Bytes