Skip to content

BUG: Test failures with 1.26.0rc1 in conda-forge #24660

Description

@h-vetinari

Describe the issue:

While our CI for 1.26.0b1 was all green, for rc1 we have two issues in conda-forge/numpy-feedstock#297:
linux-aarch64 has two test failures that don't just seem like minor tolerance violations:

=========================== short test summary info ============================
FAILED linalg/tests/test_linalg.py::TestCholesky::test_basic_property[float32-shape3] - AssertionError: 
Not equal to tolerance rtol=1e-07, atol=0.00298023

[...]

Mismatched elements: 1617 / 2500 (64.7%)
Max absolute difference: 89.25262
Max relative difference: 2200.9631
 x: array([[ 4.406959e+01, -1.291737e+00, -6.148944e-01, ..., -9.883090e+00,
        -2.005572e+00,  7.965497e+00],
       [-1.291737e+00, -7.090253e+00,  1.104174e+00, ..., -9.404308e-03,...
 y: array([[ 44.06959 ,  -1.291737,  -0.614894, ...,  -1.707806,  -0.06027 ,
          3.596826],
       [ -1.291737,  50.031647,  -0.936252, ...,  -9.246351, -12.977635,...
FAILED linalg/tests/test_linalg.py::TestCholesky::test_basic_property[float32-shape4] - AssertionError: 
Not equal to tolerance rtol=1e-07, atol=0.000178814

[...]

Mismatched elements: 253 / 300 (84.3%)
Max absolute difference: 20.29966
Max relative difference: 237.33156
 x: array([[[10.734334, -4.876828, -3.155457, -4.599753,  2.103036,
         -1.243519,  3.030686, -4.149522,  0.      ,  0.      ],
        [-4.876828,  2.244246,  1.433589,  8.771067,  1.423618,...
 y: array([[[10.734333, -4.876828, -3.155457, -4.599753,  2.103036,
         -1.243519,  3.030686, -4.149522, -2.962044,  0.036255],
        [-4.876828,  8.896948,  3.812659, -0.037113, -1.047684,...
2 failed, 34361 passed, 1117 skipped, 33 xfailed, 4 xpassed, 31 warnings in 2741.47s (0:45:41)

and pypy on windows, which seems to have some issues with cython resp. f2py:

=========================== short test summary info ===========================
FAILED random/tests/test_extending.py::test_cython - subprocess.CalledProcess...
FAILED tests/test_scripts.py::test_pep338 - subprocess.CalledProcessError: Co...
ERROR core/tests/test_mem_policy.py::test_set_policy - RuntimeError: could no...
ERROR core/tests/test_mem_policy.py::test_default_policy_singleton - RuntimeE...
ERROR core/tests/test_mem_policy.py::test_policy_propagation - RuntimeError: ...
ERROR core/tests/test_mem_policy.py::test_context_locality - RuntimeError: co...
ERROR core/tests/test_mem_policy.py::test_thread_locality - RuntimeError: cou...
ERROR core/tests/test_mem_policy.py::test_owner_is_base - RuntimeError: could...
2 failed, 38142 passed, 671 skipped, 36 xfailed, 26 xpassed, 23 warnings, 6 errors in 1984.29s (0:33:04)

Reproduce the code example:

Run tests in conda-forge CI

Error message:

See above

Runtime information:

Test env aarch:

    _openmp_mutex:                             4.5-2_gnu                      conda-forge
    _sysroot_linux-aarch64_curr_repodata_hack: 4-h57d6b7b_13                  conda-forge
    attrs:                                     23.1.0-pyh71513ae_1            conda-forge
    backports.zoneinfo:                        0.2.1-py311hec3470c_7          conda-forge
    binutils_impl_linux-aarch64:               2.40-h870a726_0                conda-forge
    binutils_linux-aarch64:                    2.40-h94bbfa1_1                conda-forge
    bzip2:                                     1.0.8-hf897c2e_4               conda-forge
    ca-certificates:                           2023.7.22-hcefe29a_0           conda-forge
    click:                                     8.1.7-unix_pyh707e725_0        conda-forge
    colorama:                                  0.4.6-pyhd8ed1ab_0             conda-forge
    cython:                                    3.0.2-py311h8715677_0          conda-forge
    exceptiongroup:                            1.1.3-pyhd8ed1ab_0             conda-forge
    execnet:                                   2.0.2-pyhd8ed1ab_0             conda-forge
    gcc_impl_linux-aarch64:                    12.3.0-hcde2664_0              conda-forge
    gcc_linux-aarch64:                         12.3.0-h464a8f7_1              conda-forge
    gfortran_impl_linux-aarch64:               12.3.0-hb7244be_0              conda-forge
    gfortran_linux-aarch64:                    12.3.0-h1993883_1              conda-forge
    gxx_impl_linux-aarch64:                    12.3.0-hcde2664_0              conda-forge
    gxx_linux-aarch64:                         12.3.0-h21accf6_1              conda-forge
    hypothesis:                                6.84.2-pyha770c72_0            conda-forge
    iniconfig:                                 2.0.0-pyhd8ed1ab_0             conda-forge
    kernel-headers_linux-aarch64:              4.18.0-h5b4a56d_13             conda-forge
    ld_impl_linux-aarch64:                     2.40-h2d8c526_0                conda-forge
    libblas:                                   3.9.0-18_linuxaarch64_openblas conda-forge
    libcblas:                                  3.9.0-18_linuxaarch64_openblas conda-forge
    libexpat:                                  2.5.0-hd600fc2_1               conda-forge
    libffi:                                    3.4.2-h3557bc0_5               conda-forge
    libgcc-devel_linux-aarch64:                12.3.0-h8b5ab12_0              conda-forge
    libgcc-ng:                                 13.1.0-h2b4548d_0              conda-forge
    libgfortran-ng:                            13.1.0-he9431aa_0              conda-forge
    libgfortran5:                              13.1.0-h24e4805_0              conda-forge
    libgomp:                                   13.1.0-h2b4548d_0              conda-forge
    liblapack:                                 3.9.0-18_linuxaarch64_openblas conda-forge
    libnsl:                                    2.0.0-hf897c2e_0               conda-forge
    libopenblas:                               0.3.24-pthreads_h5a5ec62_0     conda-forge
    libsanitizer:                              12.3.0-h8ebda82_0              conda-forge
    libsqlite:                                 3.43.0-h194ca79_0              conda-forge
    libstdcxx-devel_linux-aarch64:             12.3.0-h8b5ab12_0              conda-forge
    libstdcxx-ng:                              13.1.0-h452befe_0              conda-forge
    libuuid:                                   2.38.1-hb4cce97_0              conda-forge
    libzlib:                                   1.2.13-h31becfc_5              conda-forge
    meson:                                     1.2.1-pyhd8ed1ab_0             conda-forge
    ncurses:                                   6.4-h2e1726e_0                 conda-forge
    ninja:                                     1.11.1-hdd96247_0              conda-forge
    numpy:                                     1.26.0rc1-py311h69ead2a_0      local
    openssl:                                   3.1.2-h31becfc_0               conda-forge
    packaging:                                 23.1-pyhd8ed1ab_0              conda-forge
    pluggy:                                    1.3.0-pyhd8ed1ab_0             conda-forge
    pytest:                                    7.4.1-pyhd8ed1ab_0             conda-forge
    pytest-timeout:                            2.1.0-pyhd8ed1ab_0             conda-forge
    pytest-xdist:                              3.3.1-pyhd8ed1ab_0             conda-forge
    python:                                    3.11.5-h43d1f9e_0_cpython      conda-forge
    python_abi:                                3.11-3_cp311                   conda-forge
    pytz:                                      2023.3.post1-pyhd8ed1ab_0      conda-forge
    readline:                                  8.2-h8fc344f_1                 conda-forge
    setuptools:                                59.8.0-py311hec3470c_1         conda-forge
    sortedcontainers:                          2.4.0-pyhd8ed1ab_0             conda-forge
    sysroot_linux-aarch64:                     2.17-h5b4a56d_13               conda-forge
    tk:                                        8.6.12-hd8af866_0              conda-forge
    tomli:                                     2.0.1-pyhd8ed1ab_0             conda-forge
    typing_extensions:                         4.7.1-pyha770c72_0             conda-forge
    tzdata:                                    2023c-h71feb2d_0               conda-forge
    xz:                                        5.2.6-h9cdd2b7_0               conda-forge

Test env pypy on windows

    attrs:              23.1.0-pyh71513ae_1         conda-forge
    backports.zoneinfo: 0.2.1-py39h0d475fb_7        conda-forge
    bzip2:              1.0.8-h8ffe710_4            conda-forge
    ca-certificates:    2023.7.22-h56e8100_0        conda-forge
    click:              8.1.7-win_pyh7428d3b_0      conda-forge
    colorama:           0.4.6-pyhd8ed1ab_0          conda-forge
    cython:             3.0.2-py39h3665ca7_0        conda-forge
    exceptiongroup:     1.1.3-pyhd8ed1ab_0          conda-forge
    execnet:            2.0.2-pyhd8ed1ab_0          conda-forge
    expat:              2.5.0-h63175ca_1            conda-forge
    hypothesis:         6.84.2-pyha770c72_0         conda-forge
    iniconfig:          2.0.0-pyhd8ed1ab_0          conda-forge
    intel-openmp:       2023.2.0-h57928b3_49496     conda-forge
    libblas:            3.9.0-18_win64_mkl          conda-forge
    libcblas:           3.9.0-18_win64_mkl          conda-forge
    libexpat:           2.5.0-h63175ca_1            conda-forge
    libffi:             3.4.2-h8ffe710_5            conda-forge
    libhwloc:           2.9.2-default_haede6df_1009 conda-forge
    libiconv:           1.17-h8ffe710_0             conda-forge
    liblapack:          3.9.0-18_win64_mkl          conda-forge
    libsqlite:          3.43.0-hcfcfb64_0           conda-forge
    libxml2:            2.11.5-hc3477c8_1           conda-forge
    libzlib:            1.2.13-hcfcfb64_5           conda-forge
    meson:              1.2.1-pyhd8ed1ab_0          conda-forge
    mkl:                2022.1.0-h6a75c08_874       conda-forge
    ninja:              1.11.1-h91493d7_0           conda-forge
    numpy:              1.26.0rc1-py39h821adfb_0    local
    openssl:            3.1.2-hcfcfb64_0            conda-forge
    packaging:          23.1-pyhd8ed1ab_0           conda-forge
    pluggy:             1.3.0-pyhd8ed1ab_0          conda-forge
    pthreads-win32:     2.9.1-hfa6e2cd_3            conda-forge
    pypy3.9:            7.3.12-h994e1e7_4           conda-forge
    pytest:             7.4.1-pyhd8ed1ab_0          conda-forge
    pytest-timeout:     2.1.0-pyhd8ed1ab_0          conda-forge
    pytest-xdist:       3.3.1-pyhd8ed1ab_0          conda-forge
    python:             3.9.17-0_73_pypy            conda-forge
    python_abi:         3.9-3_pypy39_pp73           conda-forge
    pytz:               2023.3.post1-pyhd8ed1ab_0   conda-forge
    setuptools:         59.8.0-py39h0d475fb_1       conda-forge
    sortedcontainers:   2.4.0-pyhd8ed1ab_0          conda-forge
    sqlite:             3.43.0-hcfcfb64_0           conda-forge
    tbb:                2021.10.0-h91493d7_0        conda-forge
    tk:                 8.6.12-h8ffe710_0           conda-forge
    tomli:              2.0.1-pyhd8ed1ab_0          conda-forge
    typing_extensions:  4.7.1-pyha770c72_0          conda-forge
    tzdata:             2023c-h71feb2d_0            conda-forge
    ucrt:               10.0.22621.0-h57928b3_0     conda-forge
    vc:                 14.3-h64f974e_17            conda-forge
    vc14_runtime:       14.36.32532-hfdfe4a8_17     conda-forge
    vs2015_runtime:     14.36.32532-h05e6639_17     conda-forge
    xz:                 5.2.6-h8d14728_0            conda-forge
    zlib:               1.2.13-hcfcfb64_5           conda-forge

Context for the issue:

No response

Activity

  1. h-vetinari commented on Sep 7, 2023

    @h-vetinari
    ContributorAuthor
    Full error log linux-aarch
    =================================== FAILURES ===================================
    _______________ TestCholesky.test_basic_property[float32-shape3] _______________
    [gw0] linux -- Python 3.11.5 $PREFIX/bin/python
    
    self = <numpy.linalg.tests.test_linalg.TestCholesky object at 0x5521f13e50>
    shape = (50, 50), dtype = <class 'numpy.float32'>
    
        @pytest.mark.parametrize(
            'shape', [(1, 1), (2, 2), (3, 3), (50, 50), (3, 10, 10)]
        )
        @pytest.mark.parametrize(
            'dtype', (np.float32, np.float64, np.complex64, np.complex128)
        )
        def test_basic_property(self, shape, dtype):
            # Check A = L L^H
            np.random.seed(1)
            a = np.random.randn(*shape)
            if np.issubdtype(dtype, np.complexfloating):
                a = a + 1j*np.random.randn(*shape)
        
            t = list(range(len(shape)))
            t[-2:] = -1, -2
        
            a = np.matmul(a.transpose(t).conj(), a)
            a = np.asarray(a, dtype=dtype)
        
            c = np.linalg.cholesky(a)
        
            b = np.matmul(c, c.transpose(t).conj())
            with np._no_nep50_warning():
                atol = 500 * a.shape[0] * np.finfo(dtype).eps
    >       assert_allclose(b, a, atol=atol, err_msg=f'{shape} {dtype}\n{a}\n{c}')
    
    a          = array([[ 44.06959   ,  -1.2917366 ,  -0.61489445, ...,  -1.7078063 ,
             -0.06026965,   3.5968263 ],
           [ -1....     [  3.5968263 ,  -0.22433573,  -2.8806841 , ...,   6.9285684 ,
            -11.654396  ,  47.500088  ]], dtype=float32)
    atol       = 0.0029802322387695312
    b          = array([[ 4.40695915e+01, -1.29173660e+00, -6.14894450e-01, ...,
            -9.88309002e+00, -2.00557160e+00,  7.96549654e...+00,  1.27451456e+00, -6.25594807e+00, ...,
             6.92856884e+00, -1.16543951e+01,  4.75000877e+01]], dtype=float32)
    c          = array([[ 6.638493  ,  0.        ,  0.        , ...,  0.        ,
             0.        ,  0.        ],
           [-0.1945828... ],
           [ 0.5418137 , -0.01681719, -0.3770223 , ..., -0.01939702,
             0.88379747,  1.6186445 ]], dtype=float32)
    dtype      = <class 'numpy.float32'>
    self       = <numpy.linalg.tests.test_linalg.TestCholesky object at 0x5521f13e50>
    shape      = (50, 50)
             = [-1, -2]
    
    ../_test_env_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_/lib/python3.11/site-packages/numpy/linalg/tests/test_linalg.py:1821: 
    _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 
    
    args = (<function assert_allclose.<locals>.compare at 0x5745c44d60>, array([[ 4.40695915e+01, -1.29173660e+00, -6.14894450e-0...    [  3.5968263 ,  -0.22433573,  -2.8806841 , ...,   6.9285684 ,
            -11.654396  ,  47.500088  ]], dtype=float32))
    kwds = {'equal_nan': True, 'err_msg': "(50, 50) <class 'numpy.float32'>\n[[ 44.06959     -1.2917366   -0.61489445 ...  -1.707...1939702  0.88379747\n   1.6186445 ]]", 'header': 'Not equal to tolerance rtol=1e-07, atol=0.00298023', 'verbose': True}
    
        @wraps(func)
        def inner(*args, **kwds):
            with self._recreate_cm():
    >           return func(*args, **kwds)
    E           AssertionError: 
    E           Not equal to tolerance rtol=1e-07, atol=0.00298023
    E           (50, 50) <class 'numpy.float32'>
    E           [[ 44.06959     -1.2917366   -0.61489445 ...  -1.7078063   -0.06026965
    E               3.5968263 ]
    E            [ -1.2917366   50.031647    -0.93625164 ...  -9.246351   -12.977635
    E              -0.22433573]
    E            [ -0.61489445  -0.93625164  56.479916   ...   3.1758978    6.96665
    E              -2.8806841 ]
    E            ...
    E            [ -1.7078063   -9.246351     3.1758978  ...  53.048283     6.9221125
    E               6.9285684 ]
    E            [ -0.06026965 -12.977635     6.96665    ...   6.9221125   49.258278
    E             -11.654396  ]
    E            [  3.5968263   -0.22433573  -2.8806841  ...   6.9285684  -11.654396
    E              47.500088  ]]
    E           [[ 6.638493    0.          0.         ...  0.          0.
    E              0.        ]
    E            [-0.1945828   7.070628    0.         ...  0.          0.
    E              0.        ]
    E            [-0.0926256  -0.13496326  7.5135293  ...  0.          0.
    E              0.        ]
    E            ...
    E            [-0.25725812 -1.3147925   0.3959019  ...  0.7488741   0.
    E              0.        ]
    E            [-0.00907881 -1.8356787   0.8941284  ... -0.11000964  0.70787036
    E              0.        ]
    E            [ 0.5418137  -0.01681719 -0.3770223  ... -0.01939702  0.88379747
    E              1.6186445 ]]
    E           Mismatched elements: 1617 / 2500 (64.7%)
    E           Max absolute difference: 89.25262
    E           Max relative difference: 2200.9631
    E            x: array([[ 4.406959e+01, -1.291737e+00, -6.148944e-01, ..., -9.883090e+00,
    E                   -2.005572e+00,  7.965497e+00],
    E                  [-1.291737e+00, -7.090253e+00,  1.104174e+00, ..., -9.404308e-03,...
    E            y: array([[ 44.06959 ,  -1.291737,  -0.614894, ...,  -1.707806,  -0.06027 ,
    E                     3.596826],
    E                  [ -1.291737,  50.031647,  -0.936252, ...,  -9.246351, -12.977635,...
    
    args       = (<function assert_allclose.<locals>.compare at 0x5745c44d60>, array([[ 4.40695915e+01, -1.29173660e+00, -6.14894450e-0...    [  3.5968263 ,  -0.22433573,  -2.8806841 , ...,   6.9285684 ,
            -11.654396  ,  47.500088  ]], dtype=float32))
    func       = <function assert_array_compare at 0x55155a3c40>
    kwds       = {'equal_nan': True, 'err_msg': "(50, 50) <class 'numpy.float32'>\n[[ 44.06959     -1.2917366   -0.61489445 ...  -1.707...1939702  0.88379747\n   1.6186445 ]]", 'header': 'Not equal to tolerance rtol=1e-07, atol=0.00298023', 'verbose': True}
    self       = <contextlib._GeneratorContextManager object at 0x55151ef910>
    
    ../_test_env_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_/lib/python3.11/contextlib.py:81: AssertionError
    _______________ TestCholesky.test_basic_property[float32-shape4] _______________
    [gw0] linux -- Python 3.11.5 $PREFIX/bin/python
    
    self = <numpy.linalg.tests.test_linalg.TestCholesky object at 0x5521f1c190>
    shape = (3, 10, 10), dtype = <class 'numpy.float32'>
    
        @pytest.mark.parametrize(
            'shape', [(1, 1), (2, 2), (3, 3), (50, 50), (3, 10, 10)]
        )
        @pytest.mark.parametrize(
            'dtype', (np.float32, np.float64, np.complex64, np.complex128)
        )
        def test_basic_property(self, shape, dtype):
            # Check A = L L^H
            np.random.seed(1)
            a = np.random.randn(*shape)
            if np.issubdtype(dtype, np.complexfloating):
                a = a + 1j*np.random.randn(*shape)
        
            t = list(range(len(shape)))
            t[-2:] = -1, -2
        
            a = np.matmul(a.transpose(t).conj(), a)
            a = np.asarray(a, dtype=dtype)
        
            c = np.linalg.cholesky(a)
        
            b = np.matmul(c, c.transpose(t).conj())
            with np._no_nep50_warning():
                atol = 500 * a.shape[0] * np.finfo(dtype).eps
    >       assert_allclose(b, a, atol=atol, err_msg=f'{shape} {dtype}\n{a}\n{c}')
    
    a          = array([[[10.734333  , -4.8768277 , -3.1554568 , -4.5997534 ,
              2.1030364 , -1.2435193 ,  3.0306861 , -4.149522...876 ,
             -3.0850477 , -7.346789  , -8.045567  , -0.07716311,
             -7.07966   ,  9.485415  ]]], dtype=float32)
    atol       = 0.00017881393432617188
    b          = array([[[10.734334  , -4.8768277 , -3.1554568 , -4.5997534 ,
              2.1030364 , -1.2435193 ,  3.0306861 , -4.149522...    ,
             -1.0930676 ,  0.29341286,  0.10394351, -0.28610924,
              0.7695215 ,  0.96673125]]], dtype=float32)
    c          = array([[[ 3.2763293 ,  0.        ,  0.        ,  0.        ,
              0.        ,  0.        ,  0.        ,  0.      ...91  ,
             -0.12896962, -0.8804634 , -0.07867548,  0.32361656,
             -0.51923645,  0.9485597 ]]], dtype=float32)
    dtype      = <class 'numpy.float32'>
    self       = <numpy.linalg.tests.test_linalg.TestCholesky object at 0x5521f1c190>
    shape      = (3, 10, 10)
             = [0, -1, -2]
    
    ../_test_env_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_/lib/python3.11/site-packages/numpy/linalg/tests/test_linalg.py:1821: 
    _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 
    
    args = (<function assert_allclose.<locals>.compare at 0x5745c44cc0>, array([[[10.734334  , -4.8768277 , -3.1554568 , -4.59975...76 ,
             -3.0850477 , -7.346789  , -8.045567  , -0.07716311,
             -7.07966   ,  9.485415  ]]], dtype=float32))
    kwds = {'equal_nan': True, 'err_msg': "(3, 10, 10) <class 'numpy.float32'>\n[[[10.734333   -4.8768277  -3.1554568  -4.5997534...32361656 -0.51923645  0.9485597 ]]]", 'header': 'Not equal to tolerance rtol=1e-07, atol=0.000178814', 'verbose': True}
    
        @wraps(func)
        def inner(*args, **kwds):
            with self._recreate_cm():
    >           return func(*args, **kwds)
    E           AssertionError: 
    E           Not equal to tolerance rtol=1e-07, atol=0.000178814
    E           (3, 10, 10) <class 'numpy.float32'>
    E           [[[10.734333   -4.8768277  -3.1554568  -4.5997534   2.1030364
    E              -1.2435193   3.0306861  -4.149522   -2.9620435   0.03625464]
    E             [-4.8768277   8.896948    3.812659   -0.03711339 -1.0476841
    E               4.170913    0.7686802   0.3364729   1.0283238  -3.826606  ]
    E             [-3.1554568   3.812659    3.9959366   1.1625074   0.8306916
    E               0.39898828 -0.77481    -1.9865611  -0.5670059  -2.2059839 ]
    E             [-4.5997534  -0.03711339  1.1625074   6.6847258  -0.24326262
    E              -0.47384936 -1.5542715   4.114234   -1.7963581   1.5196537 ]
    E             [ 2.1030364  -1.0476841   0.8306916  -0.24326262  3.89964
    E              -4.6199813   1.9657652  -1.6450504  -0.18314792  0.349001  ]
    E             [-1.2435193   4.170913    0.39898828 -0.47384936 -4.6199813
    E              11.839529   -2.9300923   0.8218101  -1.1914967  -1.5600258 ]
    E             [ 3.0306861   0.7686802  -0.77481    -1.5542715   1.9657652
    E              -2.9300923   7.020295    1.0565685   1.5246283  -3.3805852 ]
    E             [-4.149522    0.3364729  -1.9865611   4.114234   -1.6450504
    E               0.8218101   1.0565685  10.698549    4.4092803   0.4416819 ]
    E             [-2.9620435   1.0283238  -0.5670059  -1.7963581  -0.18314792
    E              -1.1914967   1.5246283   4.4092803   8.2551985  -1.8104365 ]
    E             [ 0.03625464 -3.826606   -2.2059839   1.5196537   0.349001
    E              -1.5600258  -3.3805852   0.4416819  -1.8104365   6.6920257 ]]
    E           
    E            [[ 5.9013734  -0.11575395 -1.8299209  -0.09370685  0.29582188
    E               0.94792557 -1.7730689   3.0220997  -2.5740616   2.1073136 ]
    E             [-0.11575395 10.544705    0.79119295 -5.9150043  -1.6428163
    E              -1.3827156   0.25873902 -1.2621315  -0.7767093   4.0993524 ]
    E             [-1.8299209   0.79119295 16.183662    6.329022   -1.1351309
    E              -2.710929    6.666974    0.74811184  2.4979637   1.5011857 ]
    E             [-0.09370685 -5.9150043   6.329022   13.666377   -2.3753624
    E               0.70267767  4.4945393   1.8476337  -2.3819492   1.1581259 ]
    E             [ 0.29582188 -1.6428163  -1.1351309  -2.3753624   6.571176
    E              -4.508656   -2.573465   -0.43898493  5.2973313  -1.8500149 ]
    E             [ 0.94792557 -1.3827156  -2.710929    0.70267767 -4.508656
    E               6.8080935   0.086738    2.382368   -5.498594   -0.53745675]
    E             [-1.7730689   0.25873902  6.666974    4.4945393  -2.573465
    E               0.086738    6.919965   -0.40823123  1.9532615  -0.06429972]
    E             [ 3.0220997  -1.2621315   0.74811184  1.8476337  -0.43898493
    E               2.382368   -0.40823123  5.7033362  -2.0585406   0.21069823]
    E             [-2.5740616  -0.7767093   2.4979637  -2.3819492   5.2973313
    E              -5.498594    1.9532615  -2.0585406   9.462108   -3.9543934 ]
    E             [ 2.1073136   4.0993524   1.5011857   1.1581259  -1.8500149
    E              -0.53745675 -0.06429972  0.21069823 -3.9543934   7.435262  ]]
    E           
    E            [[ 4.6643376   2.6854048   4.0593524   0.1535468  -1.5118827
    E               3.397957   -2.9920995   0.80777925 -1.7318133   0.82475716]
    E             [ 2.6854048   7.829547   -0.5087376   4.3746657  -1.4713306
    E              -4.861691   -6.0652037   0.99772763 -4.4356337   5.25942   ]
    E             [ 4.0593524  -0.5087376  13.68554    -5.680109   -4.2268295
    E               8.056314   -6.3996224  -0.8219479  -1.7537458   1.7455587 ]
    E             [ 0.1535468   4.3746657  -5.680109   15.329586   -1.0279889
    E              -9.684909   -4.311326   -0.32577878 -8.493642    7.0410876 ]
    E             [-1.5118827  -1.4713306  -4.2268295  -1.0279889   6.4806786
    E              -1.5806129   3.722421    1.541739   -0.32345185 -3.0850477 ]
    E             [ 3.397957   -4.861691    8.056314   -9.684909   -1.5806129
    E              15.264503    3.3202677  -0.3396074   4.926388   -7.346789  ]
    E             [-2.9920995  -6.0652037  -6.3996224  -4.311326    3.722421
    E               3.3202677  11.730729    1.6513809   7.1151867  -8.045567  ]
    E             [ 0.80777925  0.99772763 -0.8219479  -0.32577878  1.541739
    E              -0.3396074   1.6513809   4.239041   -0.10079275 -0.07716311]
    E             [-1.7318133  -4.4356337  -1.7537458  -8.493642   -0.32345185
    E               4.926388    7.1151867  -0.10079275 12.2900095  -7.07966   ]
    E             [ 0.82475716  5.25942     1.7455587   7.0410876  -3.0850477
    E              -7.346789   -8.045567   -0.07716311 -7.07966     9.485415  ]]]
    E           [[[ 3.2763293   0.          0.          0.          0.
    E               0.          0.          0.          0.          0.        ]
    E             [-1.4885036   2.584822    0.          0.          0.
    E               0.          0.          0.          0.          0.        ]
    E             [-0.96310735  0.9204      1.4903773   0.          0.
    E               0.          0.          0.          0.          0.        ]
    E             [-1.4039351  -0.8228325   0.38091183  1.9726999   0.
    E               0.          0.          0.          0.          0.        ]
    E             [ 0.641888   -0.03568195  0.9942048   0.12664968  1.5753931
    E               0.          0.          0.          0.          0.        ]
    E             [-0.3795465   1.3950504  -0.83908963  0.23359051 -2.2355907
    E               1.9982008   0.          0.          0.          0.        ]
    E             [ 0.9250249   0.83006996 -0.43472758  0.3006057   1.1398793
    E              -0.8125721   1.7990714   0.          0.          0.        ]
    E             [-1.2665155  -0.599167   -1.7813463   1.2782736   0.4796653
    E               0.22821037  0.67006654  1.7880605   0.          0.        ]
    E             [-0.90407383 -0.12279119 -0.8888414  -1.4336116   0.9255097
    E               0.14752597  0.87395006  1.3292007   1.0810157   0.        ]
    E             [ 0.01106563 -1.4740415  -0.5626888   0.27203056  0.5168721
    E               0.5606847  -1.4603251  -0.657102   -0.46530387  0.87528366]]
    E           
    E            [[ 2.4292743   0.          0.          0.          0.
    E               0.          0.          0.          0.          0.        ]
    E             [-0.0476496   3.2469115   0.          0.          0.
    E               0.          0.          0.          0.          0.        ]
    E             [-0.75327885  0.23262091  3.9448855   0.          0.
    E               0.          0.          0.          0.          0.        ]
    E             [-0.03857401 -1.8222985   1.7044525   2.7274456   0.
    E               0.          0.          0.          0.          0.        ]
    E             [ 0.12177376 -0.50417566 -0.2347646  -1.059335    2.263813
    E               0.          0.          0.          0.          0.        ]
    E             [ 0.39020938 -0.42012918 -0.5879161   0.3498526  -2.0034354
    E               1.4133387   0.          0.          0.          0.        ]
    E             [-0.729876    0.06897654  1.5465921   0.7171502  -0.58618873
    E              -0.08172157  1.768033    0.          0.          0.        ]
    E             [ 1.2440339  -0.37046087  0.4490354   0.16688555 -0.2186787
    E               1.067539   -0.18652947  1.6021042   0.          0.        ]
    E             [-1.0596011  -0.25476483  0.44590706 -1.3371879   1.7607771
    E              -0.6612598   1.3828325   0.3352417   0.8516632   0.        ]
    E             [ 0.86746633  1.2752694   0.47098336  0.9946084  -0.06559554
    E              -0.3839536  -0.58293706 -0.30378163 -0.96378136  1.5273129 ]]
    E           
    E            [[ 2.1597078   0.          0.          0.          0.
    E               0.          0.          0.          0.          0.        ]
    E             [ 1.2434112   2.5066862   0.          0.          0.
    E               0.          0.          0.          0.          0.        ]
    E             [ 1.8795841  -1.1352971   2.977214    0.          0.
    E               0.          0.          0.          0.          0.        ]
    E             [ 0.0710961   1.7099324  -1.3006988   3.272437    0.
    E               0.          0.          0.          0.          0.        ]
    E             [-0.7000404  -0.23971593 -1.0691853  -0.5986391   2.1051443
    E               0.          0.          0.          0.          0.        ]
    E             [ 1.5733411  -2.719926    0.6755185  -1.3039918  -0.5650853
    E               1.707355    0.          0.          0.          0.        ]
    E             [-1.3854187  -1.7323902  -1.9354969  -1.1514527  -0.20018531
    E               0.2816568   1.2723097   0.          0.          0.        ]
    E             [ 0.37402248  0.21249725 -0.43117726 -0.39009395  0.5510192
    E              -0.1500179   1.1054928   1.4722989   0.          0.        ]
    E             [-0.8018739  -1.3717611  -0.60590625 -2.102138   -1.4820251
    E              -0.41726547 -0.11362489  0.19627525  1.5991338   0.        ]
    E             [ 0.38188368  1.9087278   1.0730667   1.572491   -0.12896962
    E              -0.8804634  -0.07867548  0.32361656 -0.51923645  0.9485597 ]]]
    E           Mismatched elements: 253 / 300 (84.3%)
    E           Max absolute difference: 20.29966
    E           Max relative difference: 237.33156
    E            x: array([[[10.734334, -4.876828, -3.155457, -4.599753,  2.103036,
    E                    -1.243519,  3.030686, -4.149522,  0.      ,  0.      ],
    E                   [-4.876828,  2.244246,  1.433589,  8.771067,  1.423618,...
    E            y: array([[[10.734333, -4.876828, -3.155457, -4.599753,  2.103036,
    E                    -1.243519,  3.030686, -4.149522, -2.962044,  0.036255],
    E                   [-4.876828,  8.896948,  3.812659, -0.037113, -1.047684,...
    
    args       = (<function assert_allclose.<locals>.compare at 0x5745c44cc0>, array([[[10.734334  , -4.8768277 , -3.1554568 , -4.59975...76 ,
             -3.0850477 , -7.346789  , -8.045567  , -0.07716311,
             -7.07966   ,  9.485415  ]]], dtype=float32))
    func       = <function assert_array_compare at 0x55155a3c40>
    kwds       = {'equal_nan': True, 'err_msg': "(3, 10, 10) <class 'numpy.float32'>\n[[[10.734333   -4.8768277  -3.1554568  -4.5997534...32361656 -0.51923645  0.9485597 ]]]", 'header': 'Not equal to tolerance rtol=1e-07, atol=0.000178814', 'verbose': True}
    self       = <contextlib._GeneratorContextManager object at 0x55151ef910>
    
    ../_test_env_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_/lib/python3.11/contextlib.py:81: AssertionError
    =============================== warnings summary ===============================
    
    Full error log pypy on windows
    =================================== ERRORS ====================================
    ______________________ ERROR at setup of test_set_policy ______________________
    [gw0] win32 -- Python 3.9.17 %PREFIX%\python.exe
    
    modname = 'mem_policy'
    functions = [('get_default_policy', 'METH_NOARGS', '\n             Py_INCREF(PyDataMem_DefaultHandler);\n             return PyDat...\n                Py_DECREF(obj);\n                return NULL;\n            }\n            return arr;\n\n         ')]
    
        def build_and_import_extension(
                modname, functions, *, prologue="", build_dir=None,
                include_dirs=[], more_init=""):
            """
            Build and imports a c-extension module `modname` from a list of function
            fragments `functions`.
        
        
            Parameters
            ----------
            functions : list of fragments
                Each fragment is a sequence of func_name, calling convention, snippet.
            prologue : string
                Code to precede the rest, usually extra ``#include`` or ``#define``
                macros.
            build_dir : pathlib.Path
                Where to build the module, usually a temporary directory
            include_dirs : list
                Extra directories to find include files when compiling
            more_init : string
                Code to appear in the module PyMODINIT_FUNC
        
            Returns
            -------
            out: module
                The module will have been loaded and is ready for use
        
            Examples
            --------
            >>> functions = [("test_bytes", "METH_O", \"\"\"
                if ( !PyBytesCheck(args)) {
                    Py_RETURN_FALSE;
                }
                Py_RETURN_TRUE;
            \"\"\")]
            >>> mod = build_and_import_extension("testme", functions)
            >>> assert not mod.test_bytes(u'abc')
            >>> assert mod.test_bytes(b'abc')
            """
            body = prologue + _make_methods(functions, modname)
            init = """PyObject *mod = PyModule_Create(&moduledef);
                   """
            if not build_dir:
                build_dir = pathlib.Path('.')
            if more_init:
                init += """#define INITERROR return NULL
                        """
                init += more_init
            init += "\nreturn mod;"
            source_string = _make_source(modname, init, body)
            try:
    >           mod_so = compile_extension_module(
                    modname, build_dir, include_dirs, source_string)
    
    body       = '\n        #define NPY_TARGET_VERSION NPY_1_22_API_VERSION\n        #define NPY_NO_DEPRECATED_API NPY_1_7_API_VERSION\...LL,           /* m_doc */\n        -1,             /* m_size */\n        methods,        /* m_methods */\n    };\n    '
    build_dir  = WindowsPath('C:/Users/VssAdministrator/AppData/Local/Temp/pytest-of-VssAdministrator/pytest-0/popen-gw0/test_set_policy0')
    functions  = [('get_default_policy', 'METH_NOARGS', '\n             Py_INCREF(PyDataMem_DefaultHandler);\n             return PyDat...\n                Py_DECREF(obj);\n                return NULL;\n            }\n            return arr;\n\n         ')]
    include_dirs = ['D:\\bld\\numpy_1694041522631\\_test_env\\lib\\site-packages\\numpy\\core\\include']
    init       = 'PyObject *mod = PyModule_Create(&moduledef);\n           #define INITERROR return NULL\n                import_array();\nreturn mod;'
    modname    = 'mem_policy'
    more_init  = 'import_array();'
    prologue   = '\n        #define NPY_TARGET_VERSION NPY_1_22_API_VERSION\n        #define NPY_NO_DEPRECATED_API NPY_1_7_API_VERSION\...                                            PyCapsule_GetName(capsule));\n            free(obj);\n        };\n        '
    source_string = '\n    #include <Python.h>\n\n    \n        #define NPY_TARGET_VERSION NPY_1_22_API_VERSION\n        #define NPY_NO_DE...eate(&moduledef);\n           #define INITERROR return NULL\n                import_array();\nreturn mod;\n    }\n    '
    
    ..\_test_env\lib\site-packages\numpy\testing\_private\extbuild.py:68: 
    _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
    ..\_test_env\lib\site-packages\numpy\testing\_private\extbuild.py:107: in compile_extension_module
        return _c_compile(
            builddir   = WindowsPath('C:/Users/VssAdministrator/AppData/Local/Temp/pytest-of-VssAdministrator/pytest-0/popen-gw0/test_set_policy0')
            cfile      = WindowsPath('C:/Users/VssAdministrator/AppData/Local/Temp/pytest-of-VssAdministrator/pytest-0/popen-gw0/test_set_policy0/mem_policy/source.c')
            dirname    = WindowsPath('C:/Users/VssAdministrator/AppData/Local/Temp/pytest-of-VssAdministrator/pytest-0/popen-gw0/test_set_policy0/mem_policy')
            include_dirs = ['D:\\bld\\numpy_1694041522631\\_test_env\\lib\\site-packages\\numpy\\core\\include', 'D:\\bld\\numpy_1694041522631\\_test_env\\Include']
            libraries  = []
            library_dirs = []
            modname    = 'mem_policy'
            name       = 'mem_policy'
            source_string = '\n    #include <Python.h>\n\n    \n        #define NPY_TARGET_VERSION NPY_1_22_API_VERSION\n        #define NPY_NO_DE...eate(&moduledef);\n           #define INITERROR return NULL\n                import_array();\nreturn mod;\n    }\n    '
    ..\_test_env\lib\site-packages\numpy\testing\_private\extbuild.py:205: in _c_compile
        build(
            cfile      = WindowsPath('C:/Users/VssAdministrator/AppData/Local/Temp/pytest-of-VssAdministrator/pytest-0/popen-gw0/test_set_policy0/mem_policy/source.c')
            compile_extra = ['/we4013']
            include_dirs = ['D:\\bld\\numpy_1694041522631\\_test_env\\lib\\site-packages\\numpy\\core\\include', 'D:\\bld\\numpy_1694041522631\\_test_env\\Include']
            libraries  = []
            library_dirs = []
            link_extra = ['/LIBPATH:D:\\bld\\numpy_1694041522631\\_test_env\\libs', '/DEBUG']
            outputfilename = WindowsPath('C:/Users/VssAdministrator/AppData/Local/Temp/pytest-of-VssAdministrator/pytest-0/popen-gw0/test_set_policy0/mem_policy/mem_policy.pypy39-pp73-win_amd64.pyd')
    ..\_test_env\lib\site-packages\numpy\testing\_private\extbuild.py:233: in build
        subprocess.check_call(["meson", "setup",
            build_dir  = WindowsPath('C:/Users/VssAdministrator/AppData/Local/Temp/pytest-of-VssAdministrator/pytest-0/popen-gw0/test_set_policy0/mem_policy/build')
            cfile      = WindowsPath('C:/Users/VssAdministrator/AppData/Local/Temp/pytest-of-VssAdministrator/pytest-0/popen-gw0/test_set_policy0/mem_policy/source.c')
            compile_extra = ['/we4013']
            fid        = <_io.TextIOWrapper name='C:\\Users\\VssAdministrator\\AppData\\Local\\Temp\\pytest-of-VssAdministrator\\pytest-0\\popen-gw0\\test_set_policy0\\mem_policy\\meson.build' mode='wt' encoding='UTF-8'>
            include_dirs = ['D:\\bld\\numpy_1694041522631\\_test_env\\lib\\site-packages\\numpy\\core\\include', 'D:\\bld\\numpy_1694041522631\\_test_env\\Include']
            includes   = ['-ID:\\bld\\numpy_1694041522631\\_test_env\\lib\\site-packages\\numpy\\core\\include', '-ID:\\bld\\numpy_1694041522631\\_test_env\\Include']
            libraries  = []
            library_dirs = []
            link_dirs  = []
            link_extra = ['/LIBPATH:D:\\bld\\numpy_1694041522631\\_test_env\\libs', '/DEBUG']
            outputfilename = WindowsPath('C:/Users/VssAdministrator/AppData/Local/Temp/pytest-of-VssAdministrator/pytest-0/popen-gw0/test_set_policy0/mem_policy/mem_policy.pypy39-pp73-win_amd64.pyd')
            so_name    = 'mem_policy.pypy39-pp73-win_amd64.pyd'
    _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
    
    popenargs = (['meson', 'setup', '--buildtype=release', '--vsenv', '..'],)
    kwargs = {'cwd': WindowsPath('C:/Users/VssAdministrator/AppData/Local/Temp/pytest-of-VssAdministrator/pytest-0/popen-gw0/test_set_policy0/mem_policy/build')}
    retcode = 1, cmd = ['meson', 'setup', '--buildtype=release', '--vsenv', '..']
    
        def check_call(*popenargs, **kwargs):
            """Run command with arguments.  Wait for command to complete.  If
            the exit code was zero then return, otherwise raise
            CalledProcessError.  The CalledProcessError object will have the
            return code in the returncode attribute.
        
            The arguments are the same as for the call function.  Example:
        
            check_call(["ls", "-l"])
            """
            retcode = call(*popenargs, **kwargs)
            if retcode:
                cmd = kwargs.get("args")
                if cmd is None:
                    cmd = popenargs[0]
    >           raise CalledProcessError(retcode, cmd)
    E           subprocess.CalledProcessError: Command '['meson', 'setup', '--buildtype=release', '--vsenv', '..']' returned non-zero exit status 1.
    
    cmd        = ['meson', 'setup', '--buildtype=release', '--vsenv', '..']
    kwargs     = {'cwd': WindowsPath('C:/Users/VssAdministrator/AppData/Local/Temp/pytest-of-VssAdministrator/pytest-0/popen-gw0/test_set_policy0/mem_policy/build')}
    popenargs  = (['meson', 'setup', '--buildtype=release', '--vsenv', '..'],)
    retcode    = 1
    
    ..\_test_env\Lib\subprocess.py:373: CalledProcessError
    
    The above exception was the direct cause of the following exception:
    
    tmp_path = WindowsPath('C:/Users/VssAdministrator/AppData/Local/Temp/pytest-of-VssAdministrator/pytest-0/popen-gw0/test_set_policy0')
    
        @pytest.fixture
        def get_module(tmp_path):
            """ Add a memory policy that returns a false pointer 64 bytes into the
            actual allocation, and fill the prefix with some text. Then check at each
            memory manipulation that the prefix exists, to make sure all alloc/realloc/
            free/calloc go via the functions here.
            """
            if sys.platform.startswith('cygwin'):
                pytest.skip('link fails on cygwin')
            if IS_WASM:
                pytest.skip("Can't build module inside Wasm")
            functions = [
                ("get_default_policy", "METH_NOARGS", """
                     Py_INCREF(PyDataMem_DefaultHandler);
                     return PyDataMem_DefaultHandler;
                 """),
                ("set_secret_data_policy", "METH_NOARGS", """
                     PyObject *secret_data =
                         PyCapsule_New(&secret_data_handler, "mem_handler", NULL);
                     if (secret_data == NULL) {
                         return NULL;
                     }
                     PyObject *old = PyDataMem_SetHandler(secret_data);
                     Py_DECREF(secret_data);
                     return old;
                 """),
                ("set_old_policy", "METH_O", """
                     PyObject *old;
                     if (args != NULL && PyCapsule_CheckExact(args)) {
                         old = PyDataMem_SetHandler(args);
                     }
                     else {
                         old = PyDataMem_SetHandler(NULL);
                     }
                     return old;
                 """),
                ("get_array", "METH_NOARGS", """
                    char *buf = (char *)malloc(20);
                    npy_intp dims[1];
                    dims[0] = 20;
                    PyArray_Descr *descr =  PyArray_DescrNewFromType(NPY_UINT8);
                    return PyArray_NewFromDescr(&PyArray_Type, descr, 1, dims, NULL,
                                                buf, NPY_ARRAY_WRITEABLE, NULL);
                 """),
                ("set_own", "METH_O", """
                    if (!PyArray_Check(args)) {
                        PyErr_SetString(PyExc_ValueError,
                                     "need an ndarray");
                        return NULL;
                    }
                    PyArray_ENABLEFLAGS((PyArrayObject*)args, NPY_ARRAY_OWNDATA);
                    // Maybe try this too?
                    // PyArray_BASE(PyArrayObject *)args) = NULL;
                    Py_RETURN_NONE;
                 """),
                ("get_array_with_base", "METH_NOARGS", """
                    char *buf = (char *)malloc(20);
                    npy_intp dims[1];
                    dims[0] = 20;
                    PyArray_Descr *descr =  PyArray_DescrNewFromType(NPY_UINT8);
                    PyObject *arr = PyArray_NewFromDescr(&PyArray_Type, descr, 1, dims,
                                                         NULL, buf,
                                                         NPY_ARRAY_WRITEABLE, NULL);
                    if (arr == NULL) return NULL;
                    PyObject *obj = PyCapsule_New(buf, "buf capsule",
                                                  (PyCapsule_Destructor)&warn_on_free);
                    if (obj == NULL) {
                        Py_DECREF(arr);
                        return NULL;
                    }
                    if (PyArray_SetBaseObject((PyArrayObject *)arr, obj) < 0) {
                        Py_DECREF(arr);
                        Py_DECREF(obj);
                        return NULL;
                    }
                    return arr;
        
                 """),
            ]
            prologue = '''
                #define NPY_TARGET_VERSION NPY_1_22_API_VERSION
                #define NPY_NO_DEPRECATED_API NPY_1_7_API_VERSION
                #include <numpy/arrayobject.h>
                /*
                 * This struct allows the dynamic configuration of the allocator funcs
                 * of the `secret_data_allocator`. It is provided here for
                 * demonstration purposes, as a valid `ctx` use-case scenario.
                 */
                typedef struct {
                    void *(*malloc)(size_t);
                    void *(*calloc)(size_t, size_t);
                    void *(*realloc)(void *, size_t);
                    void (*free)(void *);
                } SecretDataAllocatorFuncs;
        
                NPY_NO_EXPORT void *
                shift_alloc(void *ctx, size_t sz) {
                    SecretDataAllocatorFuncs *funcs = (SecretDataAllocatorFuncs *)ctx;
                    char *real = (char *)funcs->malloc(sz + 64);
                    if (real == NULL) {
                        return NULL;
                    }
                    snprintf(real, 64, "originally allocated %ld", (unsigned long)sz);
                    return (void *)(real + 64);
                }
                NPY_NO_EXPORT void *
                shift_zero(void *ctx, size_t sz, size_t cnt) {
                    SecretDataAllocatorFuncs *funcs = (SecretDataAllocatorFuncs *)ctx;
                    char *real = (char *)funcs->calloc(sz + 64, cnt);
                    if (real == NULL) {
                        return NULL;
                    }
                    snprintf(real, 64, "originally allocated %ld via zero",
                             (unsigned long)sz);
                    return (void *)(real + 64);
                }
                NPY_NO_EXPORT void
                shift_free(void *ctx, void * p, npy_uintp sz) {
                    SecretDataAllocatorFuncs *funcs = (SecretDataAllocatorFuncs *)ctx;
                    if (p == NULL) {
                        return ;
                    }
                    char *real = (char *)p - 64;
                    if (strncmp(real, "originally allocated", 20) != 0) {
                        fprintf(stdout, "uh-oh, unmatched shift_free, "
                                "no appropriate prefix\\n");
                        /* Make C runtime crash by calling free on the wrong address */
                        funcs->free((char *)p + 10);
                        /* funcs->free(real); */
                    }
                    else {
                        npy_uintp i = (npy_uintp)atoi(real +20);
                        if (i != sz) {
                            fprintf(stderr, "uh-oh, unmatched shift_free"
                                    "(ptr, %ld) but allocated %ld\\n", sz, i);
                            /* This happens in some places, only print */
                            funcs->free(real);
                        }
                        else {
                            funcs->free(real);
                        }
                    }
                }
                NPY_NO_EXPORT void *
                shift_realloc(void *ctx, void * p, npy_uintp sz) {
                    SecretDataAllocatorFuncs *funcs = (SecretDataAllocatorFuncs *)ctx;
                    if (p != NULL) {
                        char *real = (char *)p - 64;
                        if (strncmp(real, "originally allocated", 20) != 0) {
                            fprintf(stdout, "uh-oh, unmatched shift_realloc\\n");
                            return realloc(p, sz);
                        }
                        return (void *)((char *)funcs->realloc(real, sz + 64) + 64);
                    }
                    else {
                        char *real = (char *)funcs->realloc(p, sz + 64);
                        if (real == NULL) {
                            return NULL;
                        }
                        snprintf(real, 64, "originally allocated "
                                 "%ld  via realloc", (unsigned long)sz);
                        return (void *)(real + 64);
                    }
                }
                /* As an example, we use the standard {m|c|re}alloc/free funcs. */
                static SecretDataAllocatorFuncs secret_data_handler_ctx = {
                    malloc,
                    calloc,
                    realloc,
                    free
                };
                static PyDataMem_Handler secret_data_handler = {
                    "secret_data_allocator",
                    1,
                    {
                        &secret_data_handler_ctx, /* ctx */
                        shift_alloc,              /* malloc */
                        shift_zero,               /* calloc */
                        shift_realloc,            /* realloc */
                        shift_free                /* free */
                    }
                };
                void warn_on_free(void *capsule) {
                    PyErr_WarnEx(PyExc_UserWarning, "in warn_on_free", 1);
                    void * obj = PyCapsule_GetPointer(capsule,
                                                      PyCapsule_GetName(capsule));
                    free(obj);
                };
                '''
            more_init = "import_array();"
            try:
                import mem_policy
                return mem_policy
            except ImportError:
                pass
            # if it does not exist, build and load it
    >       return extbuild.build_and_import_extension('mem_policy',
                                                       functions,
                                                       prologue=prologue,
                                                       include_dirs=[np.get_include()],
                                                       build_dir=tmp_path,
                                                       more_init=more_init)
    
    functions  = [('get_default_policy', 'METH_NOARGS', '\n             Py_INCREF(PyDataMem_DefaultHandler);\n             return PyDat...\n                Py_DECREF(obj);\n                return NULL;\n            }\n            return arr;\n\n         ')]
    more_init  = 'import_array();'
    prologue   = '\n        #define NPY_TARGET_VERSION NPY_1_22_API_VERSION\n        #define NPY_NO_DEPRECATED_API NPY_1_7_API_VERSION\...                                            PyCapsule_GetName(capsule));\n            free(obj);\n        };\n        '
    tmp_path   = WindowsPath('C:/Users/VssAdministrator/AppData/Local/Temp/pytest-of-VssAdministrator/pytest-0/popen-gw0/test_set_policy0')
    
    ..\_test_env\lib\site-packages\numpy\core\tests\test_mem_policy.py:213: 
    _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
    
    modname = 'mem_policy'
    functions = [('get_default_policy', 'METH_NOARGS', '\n             Py_INCREF(PyDataMem_DefaultHandler);\n             return PyDat...\n                Py_DECREF(obj);\n                return NULL;\n            }\n            return arr;\n\n         ')]
    
        def build_and_import_extension(
                modname, functions, *, prologue="", build_dir=None,
                include_dirs=[], more_init=""):
            """
            Build and imports a c-extension module `modname` from a list of function
            fragments `functions`.
        
        
            Parameters
            ----------
            functions : list of fragments
                Each fragment is a sequence of func_name, calling convention, snippet.
            prologue : string
                Code to precede the rest, usually extra ``#include`` or ``#define``
                macros.
            build_dir : pathlib.Path
                Where to build the module, usually a temporary directory
            include_dirs : list
                Extra directories to find include files when compiling
            more_init : string
                Code to appear in the module PyMODINIT_FUNC
        
            Returns
            -------
            out: module
                The module will have been loaded and is ready for use
        
            Examples
            --------
            >>> functions = [("test_bytes", "METH_O", \"\"\"
                if ( !PyBytesCheck(args)) {
                    Py_RETURN_FALSE;
                }
                Py_RETURN_TRUE;
            \"\"\")]
            >>> mod = build_and_import_extension("testme", functions)
            >>> assert not mod.test_bytes(u'abc')
            >>> assert mod.test_bytes(b'abc')
            """
            body = prologue + _make_methods(functions, modname)
            init = """PyObject *mod = PyModule_Create(&moduledef);
                   """
            if not build_dir:
                build_dir = pathlib.Path('.')
            if more_init:
                init += """#define INITERROR return NULL
                        """
                init += more_init
            init += "\nreturn mod;"
            source_string = _make_source(modname, init, body)
            try:
                mod_so = compile_extension_module(
                    modname, build_dir, include_dirs, source_string)
            except Exception as e:
                # shorten the exception chain
    >           raise RuntimeError(f"could not compile in {build_dir}:") from e
    E           RuntimeError: could not compile in C:\Users\VssAdministrator\AppData\Local\Temp\pytest-of-VssAdministrator\pytest-0\popen-gw0\test_set_policy0:
    
    body       = '\n        #define NPY_TARGET_VERSION NPY_1_22_API_VERSION\n        #define NPY_NO_DEPRECATED_API NPY_1_7_API_VERSION\...LL,           /* m_doc */\n        -1,             /* m_size */\n        methods,        /* m_methods */\n    };\n    '
    build_dir  = WindowsPath('C:/Users/VssAdministrator/AppData/Local/Temp/pytest-of-VssAdministrator/pytest-0/popen-gw0/test_set_policy0')
    functions  = [('get_default_policy', 'METH_NOARGS', '\n             Py_INCREF(PyDataMem_DefaultHandler);\n             return PyDat...\n                Py_DECREF(obj);\n                return NULL;\n            }\n            return arr;\n\n         ')]
    include_dirs = ['D:\\bld\\numpy_1694041522631\\_test_env\\lib\\site-packages\\numpy\\core\\include']
    init       = 'PyObject *mod = PyModule_Create(&moduledef);\n           #define INITERROR return NULL\n                import_array();\nreturn mod;'
    modname    = 'mem_policy'
    more_init  = 'import_array();'
    prologue   = '\n        #define NPY_TARGET_VERSION NPY_1_22_API_VERSION\n        #define NPY_NO_DEPRECATED_API NPY_1_7_API_VERSION\...                                            PyCapsule_GetName(capsule));\n            free(obj);\n        };\n        '
    source_string = '\n    #include <Python.h>\n\n    \n        #define NPY_TARGET_VERSION NPY_1_22_API_VERSION\n        #define NPY_NO_DE...eate(&moduledef);\n           #define INITERROR return NULL\n                import_array();\nreturn mod;\n    }\n    '
    
    ..\_test_env\lib\site-packages\numpy\testing\_private\extbuild.py:72: RuntimeError
    Captured stderr setup ----------------------------
    Traceback (most recent call last):
    
      File "%PREFIX%\Scripts\meson-script.py", line 9, in <module>
    
        sys.exit(main())
    
      File "%PREFIX%\lib\site-packages\mesonbuild\mesonmain.py", line 294, in main
    
        return run(sys.argv[1:], launcher)
    
      File "%PREFIX%\lib\site-packages\mesonbuild\mesonmain.py", line 261, in run
    
        ensure_stdout_accepts_unicode()
    
      File "%PREFIX%\lib\site-packages\mesonbuild\mesonmain.py", line 230, in ensure_stdout_accepts_unicode
    
        if sys.stdout.encoding and not sys.stdout.encoding.upper().startswith('UTF-'):
    
    AttributeError: 'NoneType' object has no attribute 'encoding'
    
    _______________ ERROR at setup of test_default_policy_singleton _______________
    [gw0] win32 -- Python 3.9.17 %PREFIX%\python.exe
    
    modname = 'mem_policy'
    functions = [('get_default_policy', 'METH_NOARGS', '\n             Py_INCREF(PyDataMem_DefaultHandler);\n             return PyDat...\n                Py_DECREF(obj);\n                return NULL;\n            }\n            return arr;\n\n         ')]
    
        def build_and_import_extension(
                modname, functions, *, prologue="", build_dir=None,
                include_dirs=[], more_init=""):
            """
            Build and imports a c-extension module `modname` from a list of function
            fragments `functions`.
        
        
            Parameters
            ----------
            functions : list of fragments
                Each fragment is a sequence of func_name, calling convention, snippet.
            prologue : string
                Code to precede the rest, usually extra ``#include`` or ``#define``
                macros.
            build_dir : pathlib.Path
                Where to build the module, usually a temporary directory
            include_dirs : list
                Extra directories to find include files when compiling
            more_init : string
                Code to appear in the module PyMODINIT_FUNC
        
            Returns
            -------
            out: module
                The module will have been loaded and is ready for use
        
            Examples
            --------
            >>> functions = [("test_bytes", "METH_O", \"\"\"
                if ( !PyBytesCheck(args)) {
                    Py_RETURN_FALSE;
                }
                Py_RETURN_TRUE;
            \"\"\")]
            >>> mod = build_and_import_extension("testme", functions)
            >>> assert not mod.test_bytes(u'abc')
            >>> assert mod.test_bytes(b'abc')
            """
            body = prologue + _make_methods(functions, modname)
            init = """PyObject *mod = PyModule_Create(&moduledef);
                   """
            if not build_dir:
                build_dir = pathlib.Path('.')
            if more_init:
                init += """#define INITERROR return NULL
                        """
                init += more_init
            init += "\nreturn mod;"
            source_string = _make_source(modname, init, body)
            try:
    >           mod_so = compile_extension_module(
                    modname, build_dir, include_dirs, source_string)
    
    body       = '\n        #define NPY_TARGET_VERSION NPY_1_22_API_VERSION\n        #define NPY_NO_DEPRECATED_API NPY_1_7_API_VERSION\...LL,           /* m_doc */\n        -1,             /* m_size */\n        methods,        /* m_methods */\n    };\n    '
    build_dir  = WindowsPath('C:/Users/VssAdministrator/AppData/Local/Temp/pytest-of-VssAdministrator/pytest-0/popen-gw0/test_default_policy_singleton0')
    functions  = [('get_default_policy', 'METH_NOARGS', '\n             Py_INCREF(PyDataMem_DefaultHandler);\n             return PyDat...\n                Py_DECREF(obj);\n                return NULL;\n            }\n            return arr;\n\n         ')]
    include_dirs = ['D:\\bld\\numpy_1694041522631\\_test_env\\lib\\site-packages\\numpy\\core\\include']
    init       = 'PyObject *mod = PyModule_Create(&moduledef);\n           #define INITERROR return NULL\n                import_array();\nreturn mod;'
    modname    = 'mem_policy'
    more_init  = 'import_array();'
    prologue   = '\n        #define NPY_TARGET_VERSION NPY_1_22_API_VERSION\n        #define NPY_NO_DEPRECATED_API NPY_1_7_API_VERSION\...                                            PyCapsule_GetName(capsule));\n            free(obj);\n        };\n        '
    source_string = '\n    #include <Python.h>\n\n    \n        #define NPY_TARGET_VERSION NPY_1_22_API_VERSION\n        #define NPY_NO_DE...eate(&moduledef);\n           #define INITERROR return NULL\n                import_array();\nreturn mod;\n    }\n    '
    
    ..\_test_env\lib\site-packages\numpy\testing\_private\extbuild.py:68: 
    _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
    ..\_test_env\lib\site-packages\numpy\testing\_private\extbuild.py:107: in compile_extension_module
        return _c_compile(
            builddir   = WindowsPath('C:/Users/VssAdministrator/AppData/Local/Temp/pytest-of-VssAdministrator/pytest-0/popen-gw0/test_default_policy_singleton0')
            cfile      = WindowsPath('C:/Users/VssAdministrator/AppData/Local/Temp/pytest-of-VssAdministrator/pytest-0/popen-gw0/test_default_policy_singleton0/mem_policy/source.c')
            dirname    = WindowsPath('C:/Users/VssAdministrator/AppData/Local/Temp/pytest-of-VssAdministrator/pytest-0/popen-gw0/test_default_policy_singleton0/mem_policy')
            include_dirs = ['D:\\bld\\numpy_1694041522631\\_test_env\\lib\\site-packages\\numpy\\core\\include', 'D:\\bld\\numpy_1694041522631\\_test_env\\Include']
            libraries  = []
            library_dirs = []
            modname    = 'mem_policy'
            name       = 'mem_policy'
            source_string = '\n    #include <Python.h>\n\n    \n        #define NPY_TARGET_VERSION NPY_1_22_API_VERSION\n        #define NPY_NO_DE...eate(&moduledef);\n           #define INITERROR return NULL\n                import_array();\nreturn mod;\n    }\n    '
    ..\_test_env\lib\site-packages\numpy\testing\_private\extbuild.py:205: in _c_compile
        build(
            cfile      = WindowsPath('C:/Users/VssAdministrator/AppData/Local/Temp/pytest-of-VssAdministrator/pytest-0/popen-gw0/test_default_policy_singleton0/mem_policy/source.c')
            compile_extra = ['/we4013']
            include_dirs = ['D:\\bld\\numpy_1694041522631\\_test_env\\lib\\site-packages\\numpy\\core\\include', 'D:\\bld\\numpy_1694041522631\\_test_env\\Include']
            libraries  = []
            library_dirs = []
            link_extra = ['/LIBPATH:D:\\bld\\numpy_1694041522631\\_test_env\\libs', '/DEBUG']
            outputfilename = WindowsPath('C:/Users/VssAdministrator/AppData/Local/Temp/pytest-of-VssAdministrator/pytest-0/popen-gw0/test_default_policy_singleton0/mem_policy/mem_policy.pypy39-pp73-win_amd64.pyd')
    ..\_test_env\lib\site-packages\numpy\testing\_private\extbuild.py:233: in build
        subprocess.check_call(["meson", "setup",
            build_dir  = WindowsPath('C:/Users/VssAdministrator/AppData/Local/Temp/pytest-of-VssAdministrator/pytest-0/popen-gw0/test_default_policy_singleton0/mem_policy/build')
            cfile      = WindowsPath('C:/Users/VssAdministrator/AppData/Local/Temp/pytest-of-VssAdministrator/pytest-0/popen-gw0/test_default_policy_singleton0/mem_policy/source.c')
            compile_extra = ['/we4013']
            fid        = <_io.TextIOWrapper name='C:\\Users\\VssAdministrator\\AppData\\Local\\Temp\\pytest-of-VssAdministrator\\pytest-0\\popen-gw0\\test_default_policy_singleton0\\mem_policy\\meson.build' mode='wt' encoding='UTF-8'>
            include_dirs = ['D:\\bld\\numpy_1694041522631\\_test_env\\lib\\site-packages\\numpy\\core\\include', 'D:\\bld\\numpy_1694041522631\\_test_env\\Include']
            includes   = ['-ID:\\bld\\numpy_1694041522631\\_test_env\\lib\\site-packages\\numpy\\core\\include', '-ID:\\bld\\numpy_1694041522631\\_test_env\\Include']
            libraries  = []
            library_dirs = []
            link_dirs  = []
            link_extra = ['/LIBPATH:D:\\bld\\numpy_1694041522631\\_test_env\\libs', '/DEBUG']
            outputfilename = WindowsPath('C:/Users/VssAdministrator/AppData/Local/Temp/pytest-of-VssAdministrator/pytest-0/popen-gw0/test_default_policy_singleton0/mem_policy/mem_policy.pypy39-pp73-win_amd64.pyd')
            so_name    = 'mem_policy.pypy39-pp73-win_amd64.pyd'
    _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
    
    popenargs = (['meson', 'setup', '--buildtype=release', '--vsenv', '..'],)
    kwargs = {'cwd': WindowsPath('C:/Users/VssAdministrator/AppData/Local/Temp/pytest-of-VssAdministrator/pytest-0/popen-gw0/test_default_policy_singleton0/mem_policy/build')}
    retcode = 1, cmd = ['meson', 'setup', '--buildtype=release', '--vsenv', '..']
    
        def check_call(*popenargs, **kwargs):
            """Run command with arguments.  Wait for command to complete.  If
            the exit code was zero then return, otherwise raise
            CalledProcessError.  The CalledProcessError object will have the
            return code in the returncode attribute.
        
            The arguments are the same as for the call function.  Example:
        
            check_call(["ls", "-l"])
            """
            retcode = call(*popenargs, **kwargs)
            if retcode:
                cmd = kwargs.get("args")
                if cmd is None:
                    cmd = popenargs[0]
    >           raise CalledProcessError(retcode, cmd)
    E           subprocess.CalledProcessError: Command '['meson', 'setup', '--buildtype=release', '--vsenv', '..']' returned non-zero exit status 1.
    
    cmd        = ['meson', 'setup', '--buildtype=release', '--vsenv', '..']
    kwargs     = {'cwd': WindowsPath('C:/Users/VssAdministrator/AppData/Local/Temp/pytest-of-VssAdministrator/pytest-0/popen-gw0/test_default_policy_singleton0/mem_policy/build')}
    popenargs  = (['meson', 'setup', '--buildtype=release', '--vsenv', '..'],)
    retcode    = 1
    
    ..\_test_env\Lib\subprocess.py:373: CalledProcessError
    
    The above exception was the direct cause of the following exception:
    
    tmp_path = WindowsPath('C:/Users/VssAdministrator/AppData/Local/Temp/pytest-of-VssAdministrator/pytest-0/popen-gw0/test_default_policy_singleton0')
    
        @pytest.fixture
        def get_module(tmp_path):
            """ Add a memory policy that returns a false pointer 64 bytes into the
            actual allocation, and fill the prefix with some text. Then check at each
            memory manipulation that the prefix exists, to make sure all alloc/realloc/
            free/calloc go via the functions here.
            """
            if sys.platform.startswith('cygwin'):
                pytest.skip('link fails on cygwin')
            if IS_WASM:
                pytest.skip("Can't build module inside Wasm")
            functions = [
                ("get_default_policy", "METH_NOARGS", """
                     Py_INCREF(PyDataMem_DefaultHandler);
                     return PyDataMem_DefaultHandler;
                 """),
                ("set_secret_data_policy", "METH_NOARGS", """
                     PyObject *secret_data =
                         PyCapsule_New(&secret_data_handler, "mem_handler", NULL);
                     if (secret_data == NULL) {
                         return NULL;
                     }
                     PyObject *old = PyDataMem_SetHandler(secret_data);
                     Py_DECREF(secret_data);
                     return old;
                 """),
                ("set_old_policy", "METH_O", """
                     PyObject *old;
                     if (args != NULL && PyCapsule_CheckExact(args)) {
                         old = PyDataMem_SetHandler(args);
                     }
                     else {
                         old = PyDataMem_SetHandler(NULL);
                     }
                     return old;
                 """),
                ("get_array", "METH_NOARGS", """
                    char *buf = (char *)malloc(20);
                    npy_intp dims[1];
                    dims[0] = 20;
                    PyArray_Descr *descr =  PyArray_DescrNewFromType(NPY_UINT8);
                    return PyArray_NewFromDescr(&PyArray_Type, descr, 1, dims, NULL,
                                                buf, NPY_ARRAY_WRITEABLE, NULL);
                 """),
                ("set_own", "METH_O", """
                    if (!PyArray_Check(args)) {
                        PyErr_SetString(PyExc_ValueError,
                                     "need an ndarray");
                        return NULL;
                    }
                    PyArray_ENABLEFLAGS((PyArrayObject*)args, NPY_ARRAY_OWNDATA);
                    // Maybe try this too?
                    // PyArray_BASE(PyArrayObject *)args) = NULL;
                    Py_RETURN_NONE;
                 """),
                ("get_array_with_base", "METH_NOARGS", """
                    char *buf = (char *)malloc(20);
                    npy_intp dims[1];
                    dims[0] = 20;
                    PyArray_Descr *descr =  PyArray_DescrNewFromType(NPY_UINT8);
                    PyObject *arr = PyArray_NewFromDescr(&PyArray_Type, descr, 1, dims,
                                                         NULL, buf,
                                                         NPY_ARRAY_WRITEABLE, NULL);
                    if (arr == NULL) return NULL;
                    PyObject *obj = PyCapsule_New(buf, "buf capsule",
                                                  (PyCapsule_Destructor)&warn_on_free);
                    if (obj == NULL) {
                        Py_DECREF(arr);
                        return NULL;
                    }
                    if (PyArray_SetBaseObject((PyArrayObject *)arr, obj) < 0) {
                        Py_DECREF(arr);
                        Py_DECREF(obj);
                        return NULL;
                    }
                    return arr;
        
                 """),
            ]
            prologue = '''
                #define NPY_TARGET_VERSION NPY_1_22_API_VERSION
                #define NPY_NO_DEPRECATED_API NPY_1_7_API_VERSION
                #include <numpy/arrayobject.h>
                /*
                 * This struct allows the dynamic configuration of the allocator funcs
                 * of the `secret_data_allocator`. It is provided here for
                 * demonstration purposes, as a valid `ctx` use-case scenario.
                 */
                typedef struct {
                    void *(*malloc)(size_t);
                    void *(*calloc)(size_t, size_t);
                    void *(*realloc)(void *, size_t);
                    void (*free)(void *);
                } SecretDataAllocatorFuncs;
        
                NPY_NO_EXPORT void *
                shift_alloc(void *ctx, size_t sz) {
                    SecretDataAllocatorFuncs *funcs = (SecretDataAllocatorFuncs *)ctx;
                    char *real = (char *)funcs->malloc(sz + 64);
                    if (real == NULL) {
                        return NULL;
                    }
                    snprintf(real, 64, "originally allocated %ld", (unsigned long)sz);
                    return (void *)(real + 64);
                }
                NPY_NO_EXPORT void *
                shift_zero(void *ctx, size_t sz, size_t cnt) {
                    SecretDataAllocatorFuncs *funcs = (SecretDataAllocatorFuncs *)ctx;
                    char *real = (char *)funcs->calloc(sz + 64, cnt);
                    if (real == NULL) {
                        return NULL;
                    }
                    snprintf(real, 64, "originally allocated %ld via zero",
                             (unsigned long)sz);
                    return (void *)(real + 64);
                }
                NPY_NO_EXPORT void
                shift_free(void *ctx, void * p, npy_uintp sz) {
                    SecretDataAllocatorFuncs *funcs = (SecretDataAllocatorFuncs *)ctx;
                    if (p == NULL) {
                        return ;
                    }
                    char *real = (char *)p - 64;
                    if (strncmp(real, "originally allocated", 20) != 0) {
                        fprintf(stdout, "uh-oh, unmatched shift_free, "
                                "no appropriate prefix\\n");
                        /* Make C runtime crash by calling free on the wrong address */
                        funcs->free((char *)p + 10);
                        /* funcs->free(real); */
                    }
                    else {
                        npy_uintp i = (npy_uintp)atoi(real +20);
                        if (i != sz) {
                            fprintf(stderr, "uh-oh, unmatched shift_free"
                                    "(ptr, %ld) but allocated %ld\\n", sz, i);
                            /* This happens in some places, only print */
                            funcs->free(real);
                        }
                        else {
                            funcs->free(real);
                        }
                    }
                }
                NPY_NO_EXPORT void *
                shift_realloc(void *ctx, void * p, npy_uintp sz) {
                    SecretDataAllocatorFuncs *funcs = (SecretDataAllocatorFuncs *)ctx;
                    if (p != NULL) {
                        char *real = (char *)p - 64;
                        if (strncmp(real, "originally allocated", 20) != 0) {
                            fprintf(stdout, "uh-oh, unmatched shift_realloc\\n");
                            return realloc(p, sz);
                        }
                        return (void *)((char *)funcs->realloc(real, sz + 64) + 64);
                    }
                    else {
                        char *real = (char *)funcs->realloc(p, sz + 64);
                        if (real == NULL) {
                            return NULL;
                        }
                        snprintf(real, 64, "originally allocated "
                                 "%ld  via realloc", (unsigned long)sz);
                        return (void *)(real + 64);
                    }
                }
                /* As an example, we use the standard {m|c|re}alloc/free funcs. */
                static SecretDataAllocatorFuncs secret_data_handler_ctx = {
                    malloc,
                    calloc,
                    realloc,
                    free
                };
                static PyDataMem_Handler secret_data_handler = {
                    "secret_data_allocator",
                    1,
                    {
                        &secret_data_handler_ctx, /* ctx */
                        shift_alloc,              /* malloc */
                        shift_zero,               /* calloc */
                        shift_realloc,            /* realloc */
                        shift_free                /* free */
                    }
                };
                void warn_on_free(void *capsule) {
                    PyErr_WarnEx(PyExc_UserWarning, "in warn_on_free", 1);
                    void * obj = PyCapsule_GetPointer(capsule,
                                                      PyCapsule_GetName(capsule));
                    free(obj);
                };
                '''
            more_init = "import_array();"
            try:
                import mem_policy
                return mem_policy
            except ImportError:
                pass
            # if it does not exist, build and load it
    >       return extbuild.build_and_import_extension('mem_policy',
                                                       functions,
                                                       prologue=prologue,
                                                       include_dirs=[np.get_include()],
                                                       build_dir=tmp_path,
                                                       more_init=more_init)
    
    functions  = [('get_default_policy', 'METH_NOARGS', '\n             Py_INCREF(PyDataMem_DefaultHandler);\n             return PyDat...\n                Py_DECREF(obj);\n                return NULL;\n            }\n            return arr;\n\n         ')]
    more_init  = 'import_array();'
    prologue   = '\n        #define NPY_TARGET_VERSION NPY_1_22_API_VERSION\n        #define NPY_NO_DEPRECATED_API NPY_1_7_API_VERSION\...                                            PyCapsule_GetName(capsule));\n            free(obj);\n        };\n        '
    tmp_path   = WindowsPath('C:/Users/VssAdministrator/AppData/Local/Temp/pytest-of-VssAdministrator/pytest-0/popen-gw0/test_default_policy_singleton0')
    
    ..\_test_env\lib\site-packages\numpy\core\tests\test_mem_policy.py:213: 
    _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
    
    modname = 'mem_policy'
    functions = [('get_default_policy', 'METH_NOARGS', '\n             Py_INCREF(PyDataMem_DefaultHandler);\n             return PyDat...\n                Py_DECREF(obj);\n                return NULL;\n            }\n            return arr;\n\n         ')]
    
        def build_and_import_extension(
                modname, functions, *, prologue="", build_dir=None,
                include_dirs=[], more_init=""):
            """
            Build and imports a c-extension module `modname` from a list of function
            fragments `functions`.
        
        
            Parameters
            ----------
            functions : list of fragments
                Each fragment is a sequence of func_name, calling convention, snippet.
            prologue : string
                Code to precede the rest, usually extra ``#include`` or ``#define``
                macros.
            build_dir : pathlib.Path
                Where to build the module, usually a temporary directory
            include_dirs : list
                Extra directories to find include files when compiling
            more_init : string
                Code to appear in the module PyMODINIT_FUNC
        
            Returns
            -------
            out: module
                The module will have been loaded and is ready for use
        
            Examples
            --------
            >>> functions = [("test_bytes", "METH_O", \"\"\"
                if ( !PyBytesCheck(args)) {
                    Py_RETURN_FALSE;
                }
                Py_RETURN_TRUE;
            \"\"\")]
            >>> mod = build_and_import_extension("testme", functions)
            >>> assert not mod.test_bytes(u'abc')
            >>> assert mod.test_bytes(b'abc')
            """
            body = prologue + _make_methods(functions, modname)
            init = """PyObject *mod = PyModule_Create(&moduledef);
                   """
            if not build_dir:
                build_dir = pathlib.Path('.')
            if more_init:
                init += """#define INITERROR return NULL
                        """
                init += more_init
            init += "\nreturn mod;"
            source_string = _make_source(modname, init, body)
            try:
                mod_so = compile_extension_module(
                    modname, build_dir, include_dirs, source_string)
            except Exception as e:
                # shorten the exception chain
    >           raise RuntimeError(f"could not compile in {build_dir}:") from e
    E           RuntimeError: could not compile in C:\Users\VssAdministrator\AppData\Local\Temp\pytest-of-VssAdministrator\pytest-0\popen-gw0\test_default_policy_singleton0:
    
    body       = '\n        #define NPY_TARGET_VERSION NPY_1_22_API_VERSION\n        #define NPY_NO_DEPRECATED_API NPY_1_7_API_VERSION\...LL,           /* m_doc */\n        -1,             /* m_size */\n        methods,        /* m_methods */\n    };\n    '
    build_dir  = WindowsPath('C:/Users/VssAdministrator/AppData/Local/Temp/pytest-of-VssAdministrator/pytest-0/popen-gw0/test_default_policy_singleton0')
    functions  = [('get_default_policy', 'METH_NOARGS', '\n             Py_INCREF(PyDataMem_DefaultHandler);\n             return PyDat...\n                Py_DECREF(obj);\n                return NULL;\n            }\n            return arr;\n\n         ')]
    include_dirs = ['D:\\bld\\numpy_1694041522631\\_test_env\\lib\\site-packages\\numpy\\core\\include']
    init       = 'PyObject *mod = PyModule_Create(&moduledef);\n           #define INITERROR return NULL\n                import_array();\nreturn mod;'
    modname    = 'mem_policy'
    more_init  = 'import_array();'
    prologue   = '\n        #define NPY_TARGET_VERSION NPY_1_22_API_VERSION\n        #define NPY_NO_DEPRECATED_API NPY_1_7_API_VERSION\...                                            PyCapsule_GetName(capsule));\n            free(obj);\n        };\n        '
    source_string = '\n    #include <Python.h>\n\n    \n        #define NPY_TARGET_VERSION NPY_1_22_API_VERSION\n        #define NPY_NO_DE...eate(&moduledef);\n           #define INITERROR return NULL\n                import_array();\nreturn mod;\n    }\n    '
    
    ..\_test_env\lib\site-packages\numpy\testing\_private\extbuild.py:72: RuntimeError
    Captured stderr setup ----------------------------
    Traceback (most recent call last):
    
      File "%PREFIX%\Scripts\meson-script.py", line 9, in <module>
    
        sys.exit(main())
    
      File "%PREFIX%\lib\site-packages\mesonbuild\mesonmain.py", line 294, in main
    
        return run(sys.argv[1:], launcher)
    
      File "%PREFIX%\lib\site-packages\mesonbuild\mesonmain.py", line 261, in run
    
        ensure_stdout_accepts_unicode()
    
      File "%PREFIX%\lib\site-packages\mesonbuild\mesonmain.py", line 230, in ensure_stdout_accepts_unicode
    
        if sys.stdout.encoding and not sys.stdout.encoding.upper().startswith('UTF-'):
    
    AttributeError: 'NoneType' object has no attribute 'encoding'
    
    __________________ ERROR at setup of test_policy_propagation __________________
    [gw0] win32 -- Python 3.9.17 %PREFIX%\python.exe
    
    modname = 'mem_policy'
    functions = [('get_default_policy', 'METH_NOARGS', '\n             Py_INCREF(PyDataMem_DefaultHandler);\n             return PyDat...\n                Py_DECREF(obj);\n                return NULL;\n            }\n            return arr;\n\n         ')]
    
        def build_and_import_extension(
                modname, functions, *, prologue="", build_dir=None,
                include_dirs=[], more_init=""):
            """
            Build and imports a c-extension module `modname` from a list of function
            fragments `functions`.
        
        
            Parameters
            ----------
            functions : list of fragments
                Each fragment is a sequence of func_name, calling convention, snippet.
            prologue : string
                Code to precede the rest, usually extra ``#include`` or ``#define``
                macros.
            build_dir : pathlib.Path
                Where to build the module, usually a temporary directory
            include_dirs : list
                Extra directories to find include files when compiling
            more_init : string
                Code to appear in the module PyMODINIT_FUNC
        
            Returns
            -------
            out: module
                The module will have been loaded and is ready for use
        
            Examples
            --------
            >>> functions = [("test_bytes", "METH_O", \"\"\"
                if ( !PyBytesCheck(args)) {
                    Py_RETURN_FALSE;
                }
                Py_RETURN_TRUE;
            \"\"\")]
            >>> mod = build_and_import_extension("testme", functions)
            >>> assert not mod.test_bytes(u'abc')
            >>> assert mod.test_bytes(b'abc')
            """
            body = prologue + _make_methods(functions, modname)
            init = """PyObject *mod = PyModule_Create(&moduledef);
                   """
            if not build_dir:
                build_dir = pathlib.Path('.')
            if more_init:
                init += """#define INITERROR return NULL
                        """
                init += more_init
            init += "\nreturn mod;"
            source_string = _make_source(modname, init, body)
            try:
    >           mod_so = compile_extension_module(
                    modname, build_dir, include_dirs, source_string)
    
    body       = '\n        #define NPY_TARGET_VERSION NPY_1_22_API_VERSION\n        #define NPY_NO_DEPRECATED_API NPY_1_7_API_VERSION\...LL,           /* m_doc */\n        -1,             /* m_size */\n        methods,        /* m_methods */\n    };\n    '
    build_dir  = WindowsPath('C:/Users/VssAdministrator/AppData/Local/Temp/pytest-of-VssAdministrator/pytest-0/popen-gw0/test_policy_propagation0')
    functions  = [('get_default_policy', 'METH_NOARGS', '\n             Py_INCREF(PyDataMem_DefaultHandler);\n             return PyDat...\n                Py_DECREF(obj);\n                return NULL;\n            }\n            return arr;\n\n         ')]
    include_dirs = ['D:\\bld\\numpy_1694041522631\\_test_env\\lib\\site-packages\\numpy\\core\\include']
    init       = 'PyObject *mod = PyModule_Create(&moduledef);\n           #define INITERROR return NULL\n                import_array();\nreturn mod;'
    modname    = 'mem_policy'
    more_init  = 'import_array();'
    prologue   = '\n        #define NPY_TARGET_VERSION NPY_1_22_API_VERSION\n        #define NPY_NO_DEPRECATED_API NPY_1_7_API_VERSION\...                                            PyCapsule_GetName(capsule));\n            free(obj);\n        };\n        '
    source_string = '\n    #include <Python.h>\n\n    \n        #define NPY_TARGET_VERSION NPY_1_22_API_VERSION\n        #define NPY_NO_DE...eate(&moduledef);\n           #define INITERROR return NULL\n                import_array();\nreturn mod;\n    }\n    '
    
    ..\_test_env\lib\site-packages\numpy\testing\_private\extbuild.py:68: 
    _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
    ..\_test_env\lib\site-packages\numpy\testing\_private\extbuild.py:107: in compile_extension_module
        return _c_compile(
            builddir   = WindowsPath('C:/Users/VssAdministrator/AppData/Local/Temp/pytest-of-VssAdministrator/pytest-0/popen-gw0/test_policy_propagation0')
            cfile      = WindowsPath('C:/Users/VssAdministrator/AppData/Local/Temp/pytest-of-VssAdministrator/pytest-0/popen-gw0/test_policy_propagation0/mem_policy/source.c')
            dirname    = WindowsPath('C:/Users/VssAdministrator/AppData/Local/Temp/pytest-of-VssAdministrator/pytest-0/popen-gw0/test_policy_propagation0/mem_policy')
            include_dirs = ['D:\\bld\\numpy_1694041522631\\_test_env\\lib\\site-packages\\numpy\\core\\include', 'D:\\bld\\numpy_1694041522631\\_test_env\\Include']
            libraries  = []
            library_dirs = []
            modname    = 'mem_policy'
            name       = 'mem_policy'
            source_string = '\n    #include <Python.h>\n\n    \n        #define NPY_TARGET_VERSION NPY_1_22_API_VERSION\n        #define NPY_NO_DE...eate(&moduledef);\n           #define INITERROR return NULL\n                import_array();\nreturn mod;\n    }\n    '
    ..\_test_env\lib\site-packages\numpy\testing\_private\extbuild.py:205: in _c_compile
        build(
            cfile      = WindowsPath('C:/Users/VssAdministrator/AppData/Local/Temp/pytest-of-VssAdministrator/pytest-0/popen-gw0/test_policy_propagation0/mem_policy/source.c')
            compile_extra = ['/we4013']
            include_dirs = ['D:\\bld\\numpy_1694041522631\\_test_env\\lib\\site-packages\\numpy\\core\\include', 'D:\\bld\\numpy_1694041522631\\_test_env\\Include']
            libraries  = []
            library_dirs = []
            link_extra = ['/LIBPATH:D:\\bld\\numpy_1694041522631\\_test_env\\libs', '/DEBUG']
            outputfilename = WindowsPath('C:/Users/VssAdministrator/AppData/Local/Temp/pytest-of-VssAdministrator/pytest-0/popen-gw0/test_policy_propagation0/mem_policy/mem_policy.pypy39-pp73-win_amd64.pyd')
    ..\_test_env\lib\site-packages\numpy\testing\_private\extbuild.py:233: in build
        subprocess.check_call(["meson", "setup",
            build_dir  = WindowsPath('C:/Users/VssAdministrator/AppData/Local/Temp/pytest-of-VssAdministrator/pytest-0/popen-gw0/test_policy_propagation0/mem_policy/build')
            cfile      = WindowsPath('C:/Users/VssAdministrator/AppData/Local/Temp/pytest-of-VssAdministrator/pytest-0/popen-gw0/test_policy_propagation0/mem_policy/source.c')
            compile_extra = ['/we4013']
            fid        = <_io.TextIOWrapper name='C:\\Users\\VssAdministrator\\AppData\\Local\\Temp\\pytest-of-VssAdministrator\\pytest-0\\popen-gw0\\test_policy_propagation0\\mem_policy\\meson.build' mode='wt' encoding='UTF-8'>
            include_dirs = ['D:\\bld\\numpy_1694041522631\\_test_env\\lib\\site-packages\\numpy\\core\\include', 'D:\\bld\\numpy_1694041522631\\_test_env\\Include']
            includes   = ['-ID:\\bld\\numpy_1694041522631\\_test_env\\lib\\site-packages\\numpy\\core\\include', '-ID:\\bld\\numpy_1694041522631\\_test_env\\Include']
            libraries  = []
            library_dirs = []
            link_dirs  = []
            link_extra = ['/LIBPATH:D:\\bld\\numpy_1694041522631\\_test_env\\libs', '/DEBUG']
            outputfilename = WindowsPath('C:/Users/VssAdministrator/AppData/Local/Temp/pytest-of-VssAdministrator/pytest-0/popen-gw0/test_policy_propagation0/mem_policy/mem_policy.pypy39-pp73-win_amd64.pyd')
            so_name    = 'mem_policy.pypy39-pp73-win_amd64.pyd'
    _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
    
    popenargs = (['meson', 'setup', '--buildtype=release', '--vsenv', '..'],)
    kwargs = {'cwd': WindowsPath('C:/Users/VssAdministrator/AppData/Local/Temp/pytest-of-VssAdministrator/pytest-0/popen-gw0/test_policy_propagation0/mem_policy/build')}
    retcode = 1, cmd = ['meson', 'setup', '--buildtype=release', '--vsenv', '..']
    
        def check_call(*popenargs, **kwargs):
            """Run command with arguments.  Wait for command to complete.  If
            the exit code was zero then return, otherwise raise
            CalledProcessError.  The CalledProcessError object will have the
            return code in the returncode attribute.
        
            The arguments are the same as for the call function.  Example:
        
            check_call(["ls", "-l"])
            """
            retcode = call(*popenargs, **kwargs)
            if retcode:
                cmd = kwargs.get("args")
                if cmd is None:
                    cmd = popenargs[0]
    >           raise CalledProcessError(retcode, cmd)
    E           subprocess.CalledProcessError: Command '['meson', 'setup', '--buildtype=release', '--vsenv', '..']' returned non-zero exit status 1.
    
    cmd        = ['meson', 'setup', '--buildtype=release', '--vsenv', '..']
    kwargs     = {'cwd': WindowsPath('C:/Users/VssAdministrator/AppData/Local/Temp/pytest-of-VssAdministrator/pytest-0/popen-gw0/test_policy_propagation0/mem_policy/build')}
    popenargs  = (['meson', 'setup', '--buildtype=release', '--vsenv', '..'],)
    retcode    = 1
    
    ..\_test_env\Lib\subprocess.py:373: CalledProcessError
    
    The above exception was the direct cause of the following exception:
    
    tmp_path = WindowsPath('C:/Users/VssAdministrator/AppData/Local/Temp/pytest-of-VssAdministrator/pytest-0/popen-gw0/test_policy_propagation0')
    
        @pytest.fixture
        def get_module(tmp_path):
            """ Add a memory policy that returns a false pointer 64 bytes into the
            actual allocation, and fill the prefix with some text. Then check at each
            memory manipulation that the prefix exists, to make sure all alloc/realloc/
            free/calloc go via the functions here.
            """
            if sys.platform.startswith('cygwin'):
                pytest.skip('link fails on cygwin')
            if IS_WASM:
                pytest.skip("Can't build module inside Wasm")
            functions = [
                ("get_default_policy", "METH_NOARGS", """
                     Py_INCREF(PyDataMem_DefaultHandler);
                     return PyDataMem_DefaultHandler;
                 """),
                ("set_secret_data_policy", "METH_NOARGS", """
                     PyObject *secret_data =
                         PyCapsule_New(&secret_data_handler, "mem_handler", NULL);
                     if (secret_data == NULL) {
                         return NULL;
                     }
                     PyObject *old = PyDataMem_SetHandler(secret_data);
                     Py_DECREF(secret_data);
                     return old;
                 """),
                ("set_old_policy", "METH_O", """
                     PyObject *old;
                     if (args != NULL && PyCapsule_CheckExact(args)) {
                         old = PyDataMem_SetHandler(args);
                     }
                     else {
                         old = PyDataMem_SetHandler(NULL);
                     }
                     return old;
                 """),
                ("get_array", "METH_NOARGS", """
                    char *buf = (char *)malloc(20);
                    npy_intp dims[1];
                    dims[0] = 20;
                    PyArray_Descr *descr =  PyArray_DescrNewFromType(NPY_UINT8);
                    return PyArray_NewFromDescr(&PyArray_Type, descr, 1, dims, NULL,
                                                buf, NPY_ARRAY_WRITEABLE, NULL);
                 """),
                ("set_own", "METH_O", """
                    if (!PyArray_Check(args)) {
                        PyErr_SetString(PyExc_ValueError,
                                     "need an ndarray");
                        return NULL;
                    }
                    PyArray_ENABLEFLAGS((PyArrayObject*)args, NPY_ARRAY_OWNDATA);
                    // Maybe try this too?
                    // PyArray_BASE(PyArrayObject *)args) = NULL;
                    Py_RETURN_NONE;
                 """),
                ("get_array_with_base", "METH_NOARGS", """
                    char *buf = (char *)malloc(20);
                    npy_intp dims[1];
                    dims[0] = 20;
                    PyArray_Descr *descr =  PyArray_DescrNewFromType(NPY_UINT8);
                    PyObject *arr = PyArray_NewFromDescr(&PyArray_Type, descr, 1, dims,
                                                         NULL, buf,
                                                         NPY_ARRAY_WRITEABLE, NULL);
                    if (arr == NULL) return NULL;
                    PyObject *obj = PyCapsule_New(buf, "buf capsule",
                                                  (PyCapsule_Destructor)&warn_on_free);
                    if (obj == NULL) {
                        Py_DECREF(arr);
                        return NULL;
                    }
                    if (PyArray_SetBaseObject((PyArrayObject *)arr, obj) < 0) {
                        Py_DECREF(arr);
                        Py_DECREF(obj);
                        return NULL;
                    }
                    return arr;
        
                 """),
            ]
            prologue = '''
                #define NPY_TARGET_VERSION NPY_1_22_API_VERSION
                #define NPY_NO_DEPRECATED_API NPY_1_7_API_VERSION
                #include <numpy/arrayobject.h>
                /*
                 * This struct allows the dynamic configuration of the allocator funcs
                 * of the `secret_data_allocator`. It is provided here for
                 * demonstration purposes, as a valid `ctx` use-case scenario.
                 */
                typedef struct {
                    void *(*malloc)(size_t);
                    void *(*calloc)(size_t, size_t);
                    void *(*realloc)(void *, size_t);
                    void (*free)(void *);
                } SecretDataAllocatorFuncs;
        
                NPY_NO_EXPORT void *
                shift_alloc(void *ctx, size_t sz) {
                    SecretDataAllocatorFuncs *funcs = (SecretDataAllocatorFuncs *)ctx;
                    char *real = (char *)funcs->malloc(sz + 64);
                    if (real == NULL) {
                        return NULL;
                    }
                    snprintf(real, 64, "originally allocated %ld", (unsigned long)sz);
                    return (void *)(real + 64);
                }
                NPY_NO_EXPORT void *
                shift_zero(void *ctx, size_t sz, size_t cnt) {
                    SecretDataAllocatorFuncs *funcs = (SecretDataAllocatorFuncs *)ctx;
                    char *real = (char *)funcs->calloc(sz + 64, cnt);
                    if (real == NULL) {
                        return NULL;
                    }
                    snprintf(real, 64, "originally allocated %ld via zero",
                             (unsigned long)sz);
                    return (void *)(real + 64);
                }
                NPY_NO_EXPORT void
                shift_free(void *ctx, void * p, npy_uintp sz) {
                    SecretDataAllocatorFuncs *funcs = (SecretDataAllocatorFuncs *)ctx;
                    if (p == NULL) {
                        return ;
                    }
                    char *real = (char *)p - 64;
                    if (strncmp(real, "originally allocated", 20) != 0) {
                        fprintf(stdout, "uh-oh, unmatched shift_free, "
                                "no appropriate prefix\\n");
                        /* Make C runtime crash by calling free on the wrong address */
                        funcs->free((char *)p + 10);
                        /* funcs->free(real); */
                    }
                    else {
                        npy_uintp i = (npy_uintp)atoi(real +20);
                        if (i != sz) {
                            fprintf(stderr, "uh-oh, unmatched shift_free"
                                    "(ptr, %ld) but allocated %ld\\n", sz, i);
                            /* This happens in some places, only print */
                            funcs->free(real);
                        }
                        else {
                            funcs->free(real);
                        }
                    }
                }
                NPY_NO_EXPORT void *
                shift_realloc(void *ctx, void * p, npy_uintp sz) {
                    SecretDataAllocatorFuncs *funcs = (SecretDataAllocatorFuncs *)ctx;
                    if (p != NULL) {
                        char *real = (char *)p - 64;
                        if (strncmp(real, "originally allocated", 20) != 0) {
                            fprintf(stdout, "uh-oh, unmatched shift_realloc\\n");
                            return realloc(p, sz);
                        }
                        return (void *)((char *)funcs->realloc(real, sz + 64) + 64);
                    }
                    else {
                        char *real = (char *)funcs->realloc(p, sz + 64);
                        if (real == NULL) {
                            return NULL;
                        }
                        snprintf(real, 64, "originally allocated "
                                 "%ld  via realloc", (unsigned long)sz);
                        return (void *)(real + 64);
                    }
                }
                /* As an example, we use the standard {m|c|re}alloc/free funcs. */
                static SecretDataAllocatorFuncs secret_data_handler_ctx = {
                    malloc,
                    calloc,
                    realloc,
                    free
                };
                static PyDataMem_Handler secret_data_handler = {
                    "secret_data_allocator",
                    1,
                    {
                        &secret_data_handler_ctx, /* ctx */
                        shift_alloc,              /* malloc */
                        shift_zero,               /* calloc */
                        shift_realloc,            /* realloc */
                        shift_free                /* free */
                    }
                };
                void warn_on_free(void *capsule) {
                    PyErr_WarnEx(PyExc_UserWarning, "in warn_on_free", 1);
                    void * obj = PyCapsule_GetPointer(capsule,
                                                      PyCapsule_GetName(capsule));
                    free(obj);
                };
                '''
            more_init = "import_array();"
            try:
                import mem_policy
                return mem_policy
            except ImportError:
                pass
            # if it does not exist, build and load it
    >       return extbuild.build_and_import_extension('mem_policy',
                                                       functions,
                                                       prologue=prologue,
                                                       include_dirs=[np.get_include()],
                                                       build_dir=tmp_path,
                                                       more_init=more_init)
    
    functions  = [('get_default_policy', 'METH_NOARGS', '\n             Py_INCREF(PyDataMem_DefaultHandler);\n             return PyDat...\n                Py_DECREF(obj);\n                return NULL;\n            }\n            return arr;\n\n         ')]
    more_init  = 'import_array();'
    prologue   = '\n        #define NPY_TARGET_VERSION NPY_1_22_API_VERSION\n        #define NPY_NO_DEPRECATED_API NPY_1_7_API_VERSION\...                                            PyCapsule_GetName(capsule));\n            free(obj);\n        };\n        '
    tmp_path   = WindowsPath('C:/Users/VssAdministrator/AppData/Local/Temp/pytest-of-VssAdministrator/pytest-0/popen-gw0/test_policy_propagation0')
    
    ..\_test_env\lib\site-packages\numpy\core\tests\test_mem_policy.py:213: 
    _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
    
    modname = 'mem_policy'
    functions = [('get_default_policy', 'METH_NOARGS', '\n             Py_INCREF(PyDataMem_DefaultHandler);\n             return PyDat...\n                Py_DECREF(obj);\n                return NULL;\n            }\n            return arr;\n\n         ')]
    
        def build_and_import_extension(
                modname, functions, *, prologue="", build_dir=None,
                include_dirs=[], more_init=""):
            """
            Build and imports a c-extension module `modname` from a list of function
            fragments `functions`.
        
        
            Parameters
            ----------
            functions : list of fragments
                Each fragment is a sequence of func_name, calling convention, snippet.
            prologue : string
                Code to precede the rest, usually extra ``#include`` or ``#define``
                macros.
            build_dir : pathlib.Path
                Where to build the module, usually a temporary directory
            include_dirs : list
                Extra directories to find include files when compiling
            more_init : string
                Code to appear in the module PyMODINIT_FUNC
        
            Returns
            -------
            out: module
                The module will have been loaded and is ready for use
        
            Examples
            --------
            >>> functions = [("test_bytes", "METH_O", \"\"\"
                if ( !PyBytesCheck(args)) {
                    Py_RETURN_FALSE;
                }
                Py_RETURN_TRUE;
            \"\"\")]
            >>> mod = build_and_import_extension("testme", functions)
            >>> assert not mod.test_bytes(u'abc')
            >>> assert mod.test_bytes(b'abc')
            """
            body = prologue + _make_methods(functions, modname)
            init = """PyObject *mod = PyModule_Create(&moduledef);
                   """
            if not build_dir:
                build_dir = pathlib.Path('.')
            if more_init:
                init += """#define INITERROR return NULL
                        """
                init += more_init
            init += "\nreturn mod;"
            source_string = _make_source(modname, init, body)
            try:
                mod_so = compile_extension_module(
                    modname, build_dir, include_dirs, source_string)
            except Exception as e:
                # shorten the exception chain
    >           raise RuntimeError(f"could not compile in {build_dir}:") from e
    E           RuntimeError: could not compile in C:\Users\VssAdministrator\AppData\Local\Temp\pytest-of-VssAdministrator\pytest-0\popen-gw0\test_policy_propagation0:
    
    body       = '\n        #define NPY_TARGET_VERSION NPY_1_22_API_VERSION\n        #define NPY_NO_DEPRECATED_API NPY_1_7_API_VERSION\...LL,           /* m_doc */\n        -1,             /* m_size */\n        methods,        /* m_methods */\n    };\n    '
    build_dir  = WindowsPath('C:/Users/VssAdministrator/AppData/Local/Temp/pytest-of-VssAdministrator/pytest-0/popen-gw0/test_policy_propagation0')
    functions  = [('get_default_policy', 'METH_NOARGS', '\n             Py_INCREF(PyDataMem_DefaultHandler);\n             return PyDat...\n                Py_DECREF(obj);\n                return NULL;\n            }\n            return arr;\n\n         ')]
    include_dirs = ['D:\\bld\\numpy_1694041522631\\_test_env\\lib\\site-packages\\numpy\\core\\include']
    init       = 'PyObject *mod = PyModule_Create(&moduledef);\n           #define INITERROR return NULL\n                import_array();\nreturn mod;'
    modname    = 'mem_policy'
    more_init  = 'import_array();'
    prologue   = '\n        #define NPY_TARGET_VERSION NPY_1_22_API_VERSION\n        #define NPY_NO_DEPRECATED_API NPY_1_7_API_VERSION\...                                            PyCapsule_GetName(capsule));\n            free(obj);\n        };\n        '
    source_string = '\n    #include <Python.h>\n\n    \n        #define NPY_TARGET_VERSION NPY_1_22_API_VERSION\n        #define NPY_NO_DE...eate(&moduledef);\n           #define INITERROR return NULL\n                import_array();\nreturn mod;\n    }\n    '
    
    ..\_test_env\lib\site-packages\numpy\testing\_private\extbuild.py:72: RuntimeError
    Captured stderr setup ----------------------------
    Traceback (most recent call last):
    
      File "%PREFIX%\Scripts\meson-script.py", line 9, in <module>
    
        sys.exit(main())
    
      File "%PREFIX%\lib\site-packages\mesonbuild\mesonmain.py", line 294, in main
    
        return run(sys.argv[1:], launcher)
    
      File "%PREFIX%\lib\site-packages\mesonbuild\mesonmain.py", line 261, in run
    
        ensure_stdout_accepts_unicode()
    
      File "%PREFIX%\lib\site-packages\mesonbuild\mesonmain.py", line 230, in ensure_stdout_accepts_unicode
    
        if sys.stdout.encoding and not sys.stdout.encoding.upper().startswith('UTF-'):
    
    AttributeError: 'NoneType' object has no attribute 'encoding'
    
    ___________________ ERROR at setup of test_context_locality ___________________
    [gw0] win32 -- Python 3.9.17 %PREFIX%\python.exe
    
    modname = 'mem_policy'
    functions = [('get_default_policy', 'METH_NOARGS', '\n             Py_INCREF(PyDataMem_DefaultHandler);\n             return PyDat...\n                Py_DECREF(obj);\n                return NULL;\n            }\n            return arr;\n\n         ')]
    
        def build_and_import_extension(
                modname, functions, *, prologue="", build_dir=None,
                include_dirs=[], more_init=""):
            """
            Build and imports a c-extension module `modname` from a list of function
            fragments `functions`.
        
        
            Parameters
            ----------
            functions : list of fragments
                Each fragment is a sequence of func_name, calling convention, snippet.
            prologue : string
                Code to precede the rest, usually extra ``#include`` or ``#define``
                macros.
            build_dir : pathlib.Path
                Where to build the module, usually a temporary directory
            include_dirs : list
                Extra directories to find include files when compiling
            more_init : string
                Code to appear in the module PyMODINIT_FUNC
        
            Returns
            -------
            out: module
                The module will have been loaded and is ready for use
        
            Examples
            --------
            >>> functions = [("test_bytes", "METH_O", \"\"\"
                if ( !PyBytesCheck(args)) {
                    Py_RETURN_FALSE;
                }
                Py_RETURN_TRUE;
            \"\"\")]
            >>> mod = build_and_import_extension("testme", functions)
            >>> assert not mod.test_bytes(u'abc')
            >>> assert mod.test_bytes(b'abc')
            """
            body = prologue + _make_methods(functions, modname)
            init = """PyObject *mod = PyModule_Create(&moduledef);
                   """
            if not build_dir:
                build_dir = pathlib.Path('.')
            if more_init:
                init += """#define INITERROR return NULL
                        """
                init += more_init
            init += "\nreturn mod;"
            source_string = _make_source(modname, init, body)
            try:
    >           mod_so = compile_extension_module(
                    modname, build_dir, include_dirs, source_string)
    
    body       = '\n        #define NPY_TARGET_VERSION NPY_1_22_API_VERSION\n        #define NPY_NO_DEPRECATED_API NPY_1_7_API_VERSION\...LL,           /* m_doc */\n        -1,             /* m_size */\n        methods,        /* m_methods */\n    };\n    '
    build_dir  = WindowsPath('C:/Users/VssAdministrator/AppData/Local/Temp/pytest-of-VssAdministrator/pytest-0/popen-gw0/test_context_locality0')
    functions  = [('get_default_policy', 'METH_NOARGS', '\n             Py_INCREF(PyDataMem_DefaultHandler);\n             return PyDat...\n                Py_DECREF(obj);\n                return NULL;\n            }\n            return arr;\n\n         ')]
    include_dirs = ['D:\\bld\\numpy_1694041522631\\_test_env\\lib\\site-packages\\numpy\\core\\include']
    init       = 'PyObject *mod = PyModule_Create(&moduledef);\n           #define INITERROR return NULL\n                import_array();\nreturn mod;'
    modname    = 'mem_policy'
    more_init  = 'import_array();'
    prologue   = '\n        #define NPY_TARGET_VERSION NPY_1_22_API_VERSION\n        #define NPY_NO_DEPRECATED_API NPY_1_7_API_VERSION\...                                            PyCapsule_GetName(capsule));\n            free(obj);\n        };\n        '
    source_string = '\n    #include <Python.h>\n\n    \n        #define NPY_TARGET_VERSION NPY_1_22_API_VERSION\n        #define NPY_NO_DE...eate(&moduledef);\n           #define INITERROR return NULL\n                import_array();\nreturn mod;\n    }\n    '
    
    ..\_test_env\lib\site-packages\numpy\testing\_private\extbuild.py:68: 
    _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
    ..\_test_env\lib\site-packages\numpy\testing\_private\extbuild.py:107: in compile_extension_module
        return _c_compile(
            builddir   = WindowsPath('C:/Users/VssAdministrator/AppData/Local/Temp/pytest-of-VssAdministrator/pytest-0/popen-gw0/test_context_locality0')
            cfile      = WindowsPath('C:/Users/VssAdministrator/AppData/Local/Temp/pytest-of-VssAdministrator/pytest-0/popen-gw0/test_context_locality0/mem_policy/source.c')
            dirname    = WindowsPath('C:/Users/VssAdministrator/AppData/Local/Temp/pytest-of-VssAdministrator/pytest-0/popen-gw0/test_context_locality0/mem_policy')
            include_dirs = ['D:\\bld\\numpy_1694041522631\\_test_env\\lib\\site-packages\\numpy\\core\\include', 'D:\\bld\\numpy_1694041522631\\_test_env\\Include']
            libraries  = []
            library_dirs = []
            modname    = 'mem_policy'
            name       = 'mem_policy'
            source_string = '\n    #include <Python.h>\n\n    \n        #define NPY_TARGET_VERSION NPY_1_22_API_VERSION\n        #define NPY_NO_DE...eate(&moduledef);\n           #define INITERROR return NULL\n                import_array();\nreturn mod;\n    }\n    '
    ..\_test_env\lib\site-packages\numpy\testing\_private\extbuild.py:205: in _c_compile
        build(
            cfile      = WindowsPath('C:/Users/VssAdministrator/AppData/Local/Temp/pytest-of-VssAdministrator/pytest-0/popen-gw0/test_context_locality0/mem_policy/source.c')
            compile_extra = ['/we4013']
            include_dirs = ['D:\\bld\\numpy_1694041522631\\_test_env\\lib\\site-packages\\numpy\\core\\include', 'D:\\bld\\numpy_1694041522631\\_test_env\\Include']
            libraries  = []
            library_dirs = []
            link_extra = ['/LIBPATH:D:\\bld\\numpy_1694041522631\\_test_env\\libs', '/DEBUG']
            outputfilename = WindowsPath('C:/Users/VssAdministrator/AppData/Local/Temp/pytest-of-VssAdministrator/pytest-0/popen-gw0/test_context_locality0/mem_policy/mem_policy.pypy39-pp73-win_amd64.pyd')
    ..\_test_env\lib\site-packages\numpy\testing\_private\extbuild.py:233: in build
        subprocess.check_call(["meson", "setup",
            build_dir  = WindowsPath('C:/Users/VssAdministrator/AppData/Local/Temp/pytest-of-VssAdministrator/pytest-0/popen-gw0/test_context_locality0/mem_policy/build')
            cfile      = WindowsPath('C:/Users/VssAdministrator/AppData/Local/Temp/pytest-of-VssAdministrator/pytest-0/popen-gw0/test_context_locality0/mem_policy/source.c')
            compile_extra = ['/we4013']
            fid        = <_io.TextIOWrapper name='C:\\Users\\VssAdministrator\\AppData\\Local\\Temp\\pytest-of-VssAdministrator\\pytest-0\\popen-gw0\\test_context_locality0\\mem_policy\\meson.build' mode='wt' encoding='UTF-8'>
            include_dirs = ['D:\\bld\\numpy_1694041522631\\_test_env\\lib\\site-packages\\numpy\\core\\include', 'D:\\bld\\numpy_1694041522631\\_test_env\\Include']
            includes   = ['-ID:\\bld\\numpy_1694041522631\\_test_env\\lib\\site-packages\\numpy\\core\\include', '-ID:\\bld\\numpy_1694041522631\\_test_env\\Include']
            libraries  = []
            library_dirs = []
            link_dirs  = []
            link_extra = ['/LIBPATH:D:\\bld\\numpy_1694041522631\\_test_env\\libs', '/DEBUG']
            outputfilename = WindowsPath('C:/Users/VssAdministrator/AppData/Local/Temp/pytest-of-VssAdministrator/pytest-0/popen-gw0/test_context_locality0/mem_policy/mem_policy.pypy39-pp73-win_amd64.pyd')
            so_name    = 'mem_policy.pypy39-pp73-win_amd64.pyd'
    _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
    
    popenargs = (['meson', 'setup', '--buildtype=release', '--vsenv', '..'],)
    kwargs = {'cwd': WindowsPath('C:/Users/VssAdministrator/AppData/Local/Temp/pytest-of-VssAdministrator/pytest-0/popen-gw0/test_context_locality0/mem_policy/build')}
    retcode = 1, cmd = ['meson', 'setup', '--buildtype=release', '--vsenv', '..']
    
        def check_call(*popenargs, **kwargs):
            """Run command with arguments.  Wait for command to complete.  If
            the exit code was zero then return, otherwise raise
            CalledProcessError.  The CalledProcessError object will have the
            return code in the returncode attribute.
        
            The arguments are the same as for the call function.  Example:
        
            check_call(["ls", "-l"])
            """
            retcode = call(*popenargs, **kwargs)
            if retcode:
                cmd = kwargs.get("args")
                if cmd is None:
                    cmd = popenargs[0]
    >           raise CalledProcessError(retcode, cmd)
    E           subprocess.CalledProcessError: Command '['meson', 'setup', '--buildtype=release', '--vsenv', '..']' returned non-zero exit status 1.
    
    cmd        = ['meson', 'setup', '--buildtype=release', '--vsenv', '..']
    kwargs     = {'cwd': WindowsPath('C:/Users/VssAdministrator/AppData/Local/Temp/pytest-of-VssAdministrator/pytest-0/popen-gw0/test_context_locality0/mem_policy/build')}
    popenargs  = (['meson', 'setup', '--buildtype=release', '--vsenv', '..'],)
    retcode    = 1
    
    ..\_test_env\Lib\subprocess.py:373: CalledProcessError
    
    The above exception was the direct cause of the following exception:
    
    tmp_path = WindowsPath('C:/Users/VssAdministrator/AppData/Local/Temp/pytest-of-VssAdministrator/pytest-0/popen-gw0/test_context_locality0')
    
        @pytest.fixture
        def get_module(tmp_path):
            """ Add a memory policy that returns a false pointer 64 bytes into the
            actual allocation, and fill the prefix with some text. Then check at each
            memory manipulation that the prefix exists, to make sure all alloc/realloc/
            free/calloc go via the functions here.
            """
            if sys.platform.startswith('cygwin'):
                pytest.skip('link fails on cygwin')
            if IS_WASM:
                pytest.skip("Can't build module inside Wasm")
            functions = [
                ("get_default_policy", "METH_NOARGS", """
                     Py_INCREF(PyDataMem_DefaultHandler);
                     return PyDataMem_DefaultHandler;
                 """),
                ("set_secret_data_policy", "METH_NOARGS", """
                     PyObject *secret_data =
                         PyCapsule_New(&secret_data_handler, "mem_handler", NULL);
                     if (secret_data == NULL) {
                         return NULL;
                     }
                     PyObject *old = PyDataMem_SetHandler(secret_data);
                     Py_DECREF(secret_data);
                     return old;
                 """),
                ("set_old_policy", "METH_O", """
                     PyObject *old;
                     if (args != NULL && PyCapsule_CheckExact(args)) {
                         old = PyDataMem_SetHandler(args);
                     }
                     else {
                         old = PyDataMem_SetHandler(NULL);
                     }
                     return old;
                 """),
                ("get_array", "METH_NOARGS", """
                    char *buf = (char *)malloc(20);
                    npy_intp dims[1];
                    dims[0] = 20;
                    PyArray_Descr *descr =  PyArray_DescrNewFromType(NPY_UINT8);
                    return PyArray_NewFromDescr(&PyArray_Type, descr, 1, dims, NULL,
                                                buf, NPY_ARRAY_WRITEABLE, NULL);
                 """),
                ("set_own", "METH_O", """
                    if (!PyArray_Check(args)) {
                        PyErr_SetString(PyExc_ValueError,
                                     "need an ndarray");
                        return NULL;
                    }
                    PyArray_ENABLEFLAGS((PyArrayObject*)args, NPY_ARRAY_OWNDATA);
                    // Maybe try this too?
                    // PyArray_BASE(PyArrayObject *)args) = NULL;
                    Py_RETURN_NONE;
                 """),
                ("get_array_with_base", "METH_NOARGS", """
                    char *buf = (char *)malloc(20);
                    npy_intp dims[1];
                    dims[0] = 20;
                    PyArray_Descr *descr =  PyArray_DescrNewFromType(NPY_UINT8);
                    PyObject *arr = PyArray_NewFromDescr(&PyArray_Type, descr, 1, dims,
                                                         NULL, buf,
                                                         NPY_ARRAY_WRITEABLE, NULL);
                    if (arr == NULL) return NULL;
                    PyObject *obj = PyCapsule_New(buf, "buf capsule",
                                                  (PyCapsule_Destructor)&warn_on_free);
                    if (obj == NULL) {
                        Py_DECREF(arr);
                        return NULL;
                    }
                    if (PyArray_SetBaseObject((PyArrayObject *)arr, obj) < 0) {
                        Py_DECREF(arr);
                        Py_DECREF(obj);
                        return NULL;
                    }
                    return arr;
        
                 """),
            ]
            prologue = '''
                #define NPY_TARGET_VERSION NPY_1_22_API_VERSION
                #define NPY_NO_DEPRECATED_API NPY_1_7_API_VERSION
                #include <numpy/arrayobject.h>
                /*
                 * This struct allows the dynamic configuration of the allocator funcs
                 * of the `secret_data_allocator`. It is provided here for
                 * demonstration purposes, as a valid `ctx` use-case scenario.
                 */
                typedef struct {
                    void *(*malloc)(size_t);
                    void *(*calloc)(size_t, size_t);
                    void *(*realloc)(void *, size_t);
                    void (*free)(void *);
                } SecretDataAllocatorFuncs;
        
                NPY_NO_EXPORT void *
                shift_alloc(void *ctx, size_t sz) {
                    SecretDataAllocatorFuncs *funcs = (SecretDataAllocatorFuncs *)ctx;
                    char *real = (char *)funcs->malloc(sz + 64);
                    if (real == NULL) {
                        return NULL;
                    }
                    snprintf(real, 64, "originally allocated %ld", (unsigned long)sz);
                    return (void *)(real + 64);
                }
                NPY_NO_EXPORT void *
                shift_zero(void *ctx, size_t sz, size_t cnt) {
                    SecretDataAllocatorFuncs *funcs = (SecretDataAllocatorFuncs *)ctx;
                    char *real = (char *)funcs->calloc(sz + 64, cnt);
                    if (real == NULL) {
                        return NULL;
                    }
                    snprintf(real, 64, "originally allocated %ld via zero",
                             (unsigned long)sz);
                    return (void *)(real + 64);
                }
                NPY_NO_EXPORT void
                shift_free(void *ctx, void * p, npy_uintp sz) {
                    SecretDataAllocatorFuncs *funcs = (SecretDataAllocatorFuncs *)ctx;
                    if (p == NULL) {
                        return ;
                    }
                    char *real = (char *)p - 64;
                    if (strncmp(real, "originally allocated", 20) != 0) {
                        fprintf(stdout, "uh-oh, unmatched shift_free, "
                                "no appropriate prefix\\n");
                        /* Make C runtime crash by calling free on the wrong address */
                        funcs->free((char *)p + 10);
                        /* funcs->free(real); */
                    }
                    else {
                        npy_uintp i = (npy_uintp)atoi(real +20);
                        if (i != sz) {
                            fprintf(stderr, "uh-oh, unmatched shift_free"
                                    "(ptr, %ld) but allocated %ld\\n", sz, i);
                            /* This happens in some places, only print */
                            funcs->free(real);
                        }
                        else {
                            funcs->free(real);
                        }
                    }
                }
                NPY_NO_EXPORT void *
                shift_realloc(void *ctx, void * p, npy_uintp sz) {
                    SecretDataAllocatorFuncs *funcs = (SecretDataAllocatorFuncs *)ctx;
                    if (p != NULL) {
                        char *real = (char *)p - 64;
                        if (strncmp(real, "originally allocated", 20) != 0) {
                            fprintf(stdout, "uh-oh, unmatched shift_realloc\\n");
                            return realloc(p, sz);
                        }
                        return (void *)((char *)funcs->realloc(real, sz + 64) + 64);
                    }
                    else {
                        char *real = (char *)funcs->realloc(p, sz + 64);
                        if (real == NULL) {
                            return NULL;
                        }
                        snprintf(real, 64, "originally allocated "
                                 "%ld  via realloc", (unsigned long)sz);
                        return (void *)(real + 64);
                    }
                }
                /* As an example, we use the standard {m|c|re}alloc/free funcs. */
                static SecretDataAllocatorFuncs secret_data_handler_ctx = {
                    malloc,
                    calloc,
                    realloc,
                    free
                };
                static PyDataMem_Handler secret_data_handler = {
                    "secret_data_allocator",
                    1,
                    {
                        &secret_data_handler_ctx, /* ctx */
                        shift_alloc,              /* malloc */
                        shift_zero,               /* calloc */
                        shift_realloc,            /* realloc */
                        shift_free                /* free */
                    }
                };
                void warn_on_free(void *capsule) {
                    PyErr_WarnEx(PyExc_UserWarning, "in warn_on_free", 1);
                    void * obj = PyCapsule_GetPointer(capsule,
                                                      PyCapsule_GetName(capsule));
                    free(obj);
                };
                '''
            more_init = "import_array();"
            try:
                import mem_policy
                return mem_policy
            except ImportError:
                pass
            # if it does not exist, build and load it
    >       return extbuild.build_and_import_extension('mem_policy',
                                                       functions,
                                                       prologue=prologue,
                                                       include_dirs=[np.get_include()],
                                                       build_dir=tmp_path,
                                                       more_init=more_init)
    
    functions  = [('get_default_policy', 'METH_NOARGS', '\n             Py_INCREF(PyDataMem_DefaultHandler);\n             return PyDat...\n                Py_DECREF(obj);\n                return NULL;\n            }\n            return arr;\n\n         ')]
    more_init  = 'import_array();'
    prologue   = '\n        #define NPY_TARGET_VERSION NPY_1_22_API_VERSION\n        #define NPY_NO_DEPRECATED_API NPY_1_7_API_VERSION\...                                            PyCapsule_GetName(capsule));\n            free(obj);\n        };\n        '
    tmp_path   = WindowsPath('C:/Users/VssAdministrator/AppData/Local/Temp/pytest-of-VssAdministrator/pytest-0/popen-gw0/test_context_locality0')
    
    ..\_test_env\lib\site-packages\numpy\core\tests\test_mem_policy.py:213: 
    _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
    
    modname = 'mem_policy'
    functions = [('get_default_policy', 'METH_NOARGS', '\n             Py_INCREF(PyDataMem_DefaultHandler);\n             return PyDat...\n                Py_DECREF(obj);\n                return NULL;\n            }\n            return arr;\n\n         ')]
    
        def build_and_import_extension(
                modname, functions, *, prologue="", build_dir=None,
                include_dirs=[], more_init=""):
            """
            Build and imports a c-extension module `modname` from a list of function
            fragments `functions`.
        
        
            Parameters
            ----------
            functions : list of fragments
                Each fragment is a sequence of func_name, calling convention, snippet.
            prologue : string
                Code to precede the rest, usually extra ``#include`` or ``#define``
                macros.
            build_dir : pathlib.Path
                Where to build the module, usually a temporary directory
            include_dirs : list
                Extra directories to find include files when compiling
            more_init : string
                Code to appear in the module PyMODINIT_FUNC
        
            Returns
            -------
            out: module
                The module will have been loaded and is ready for use
        
            Examples
            --------
            >>> functions = [("test_bytes", "METH_O", \"\"\"
                if ( !PyBytesCheck(args)) {
                    Py_RETURN_FALSE;
                }
                Py_RETURN_TRUE;
            \"\"\")]
            >>> mod = build_and_import_extension("testme", functions)
            >>> assert not mod.test_bytes(u'abc')
            >>> assert mod.test_bytes(b'abc')
            """
            body = prologue + _make_methods(functions, modname)
            init = """PyObject *mod = PyModule_Create(&moduledef);
                   """
            if not build_dir:
                build_dir = pathlib.Path('.')
            if more_init:
                init += """#define INITERROR return NULL
                        """
                init += more_init
            init += "\nreturn mod;"
            source_string = _make_source(modname, init, body)
            try:
                mod_so = compile_extension_module(
                    modname, build_dir, include_dirs, source_string)
            except Exception as e:
                # shorten the exception chain
    >           raise RuntimeError(f"could not compile in {build_dir}:") from e
    E           RuntimeError: could not compile in C:\Users\VssAdministrator\AppData\Local\Temp\pytest-of-VssAdministrator\pytest-0\popen-gw0\test_context_locality0:
    
    body       = '\n        #define NPY_TARGET_VERSION NPY_1_22_API_VERSION\n        #define NPY_NO_DEPRECATED_API NPY_1_7_API_VERSION\...LL,           /* m_doc */\n        -1,             /* m_size */\n        methods,        /* m_methods */\n    };\n    '
    build_dir  = WindowsPath('C:/Users/VssAdministrator/AppData/Local/Temp/pytest-of-VssAdministrator/pytest-0/popen-gw0/test_context_locality0')
    functions  = [('get_default_policy', 'METH_NOARGS', '\n             Py_INCREF(PyDataMem_DefaultHandler);\n             return PyDat...\n                Py_DECREF(obj);\n                return NULL;\n            }\n            return arr;\n\n         ')]
    include_dirs = ['D:\\bld\\numpy_1694041522631\\_test_env\\lib\\site-packages\\numpy\\core\\include']
    init       = 'PyObject *mod = PyModule_Create(&moduledef);\n           #define INITERROR return NULL\n                import_array();\nreturn mod;'
    modname    = 'mem_policy'
    more_init  = 'import_array();'
    prologue   = '\n        #define NPY_TARGET_VERSION NPY_1_22_API_VERSION\n        #define NPY_NO_DEPRECATED_API NPY_1_7_API_VERSION\...                                            PyCapsule_GetName(capsule));\n            free(obj);\n        };\n        '
    source_string = '\n    #include <Python.h>\n\n    \n        #define NPY_TARGET_VERSION NPY_1_22_API_VERSION\n        #define NPY_NO_DE...eate(&moduledef);\n           #define INITERROR return NULL\n                import_array();\nreturn mod;\n    }\n    '
    
    ..\_test_env\lib\site-packages\numpy\testing\_private\extbuild.py:72: RuntimeError
    Captured stderr setup ----------------------------
    Traceback (most recent call last):
    
      File "%PREFIX%\Scripts\meson-script.py", line 9, in <module>
    
        sys.exit(main())
    
      File "%PREFIX%\lib\site-packages\mesonbuild\mesonmain.py", line 294, in main
    
        return run(sys.argv[1:], launcher)
    
      File "%PREFIX%\lib\site-packages\mesonbuild\mesonmain.py", line 261, in run
    
        ensure_stdout_accepts_unicode()
    
      File "%PREFIX%\lib\site-packages\mesonbuild\mesonmain.py", line 230, in ensure_stdout_accepts_unicode
    
        if sys.stdout.encoding and not sys.stdout.encoding.upper().startswith('UTF-'):
    
    AttributeError: 'NoneType' object has no attribute 'encoding'
    
    ___________________ ERROR at setup of test_thread_locality ____________________
    [gw0] win32 -- Python 3.9.17 %PREFIX%\python.exe
    
    modname = 'mem_policy'
    functions = [('get_default_policy', 'METH_NOARGS', '\n             Py_INCREF(PyDataMem_DefaultHandler);\n             return PyDat...\n                Py_DECREF(obj);\n                return NULL;\n            }\n            return arr;\n\n         ')]
    
        def build_and_import_extension(
                modname, functions, *, prologue="", build_dir=None,
                include_dirs=[], more_init=""):
            """
            Build and imports a c-extension module `modname` from a list of function
            fragments `functions`.
        
        
            Parameters
            ----------
            functions : list of fragments
                Each fragment is a sequence of func_name, calling convention, snippet.
            prologue : string
                Code to precede the rest, usually extra ``#include`` or ``#define``
                macros.
            build_dir : pathlib.Path
                Where to build the module, usually a temporary directory
            include_dirs : list
                Extra directories to find include files when compiling
            more_init : string
                Code to appear in the module PyMODINIT_FUNC
        
            Returns
            -------
            out: module
                The module will have been loaded and is ready for use
        
            Examples
            --------
            >>> functions = [("test_bytes", "METH_O", \"\"\"
                if ( !PyBytesCheck(args)) {
                    Py_RETURN_FALSE;
                }
                Py_RETURN_TRUE;
            \"\"\")]
            >>> mod = build_and_import_extension("testme", functions)
            >>> assert not mod.test_bytes(u'abc')
            >>> assert mod.test_bytes(b'abc')
            """
            body = prologue + _make_methods(functions, modname)
            init = """PyObject *mod = PyModule_Create(&moduledef);
                   """
            if not build_dir:
                build_dir = pathlib.Path('.')
            if more_init:
                init += """#define INITERROR return NULL
                        """
                init += more_init
            init += "\nreturn mod;"
            source_string = _make_source(modname, init, body)
            try:
    >           mod_so = compile_extension_module(
                    modname, build_dir, include_dirs, source_string)
    
    body       = '\n        #define NPY_TARGET_VERSION NPY_1_22_API_VERSION\n        #define NPY_NO_DEPRECATED_API NPY_1_7_API_VERSION\...LL,           /* m_doc */\n        -1,             /* m_size */\n        methods,        /* m_methods */\n    };\n    '
    build_dir  = WindowsPath('C:/Users/VssAdministrator/AppData/Local/Temp/pytest-of-VssAdministrator/pytest-0/popen-gw0/test_thread_locality0')
    functions  = [('get_default_policy', 'METH_NOARGS', '\n             Py_INCREF(PyDataMem_DefaultHandler);\n             return PyDat...\n                Py_DECREF(obj);\n                return NULL;\n            }\n            return arr;\n\n         ')]
    include_dirs = ['D:\\bld\\numpy_1694041522631\\_test_env\\lib\\site-packages\\numpy\\core\\include']
    init       = 'PyObject *mod = PyModule_Create(&moduledef);\n           #define INITERROR return NULL\n                import_array();\nreturn mod;'
    modname    = 'mem_policy'
    more_init  = 'import_array();'
    prologue   = '\n        #define NPY_TARGET_VERSION NPY_1_22_API_VERSION\n        #define NPY_NO_DEPRECATED_API NPY_1_7_API_VERSION\...                                            PyCapsule_GetName(capsule));\n            free(obj);\n        };\n        '
    source_string = '\n    #include <Python.h>\n\n    \n        #define NPY_TARGET_VERSION NPY_1_22_API_VERSION\n        #define NPY_NO_DE...eate(&moduledef);\n           #define INITERROR return NULL\n                import_array();\nreturn mod;\n    }\n    '
    
    ..\_test_env\lib\site-packages\numpy\testing\_private\extbuild.py:68: 
    _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
    ..\_test_env\lib\site-packages\numpy\testing\_private\extbuild.py:107: in compile_extension_module
        return _c_compile(
            builddir   = WindowsPath('C:/Users/VssAdministrator/AppData/Local/Temp/pytest-of-VssAdministrator/pytest-0/popen-gw0/test_thread_locality0')
            cfile      = WindowsPath('C:/Users/VssAdministrator/AppData/Local/Temp/pytest-of-VssAdministrator/pytest-0/popen-gw0/test_thread_locality0/mem_policy/source.c')
            dirname    = WindowsPath('C:/Users/VssAdministrator/AppData/Local/Temp/pytest-of-VssAdministrator/pytest-0/popen-gw0/test_thread_locality0/mem_policy')
            include_dirs = ['D:\\bld\\numpy_1694041522631\\_test_env\\lib\\site-packages\\numpy\\core\\include', 'D:\\bld\\numpy_1694041522631\\_test_env\\Include']
            libraries  = []
            library_dirs = []
            modname    = 'mem_policy'
            name       = 'mem_policy'
            source_string = '\n    #include <Python.h>\n\n    \n        #define NPY_TARGET_VERSION NPY_1_22_API_VERSION\n        #define NPY_NO_DE...eate(&moduledef);\n           #define INITERROR return NULL\n                import_array();\nreturn mod;\n    }\n    '
    ..\_test_env\lib\site-packages\numpy\testing\_private\extbuild.py:205: in _c_compile
        build(
            cfile      = WindowsPath('C:/Users/VssAdministrator/AppData/Local/Temp/pytest-of-VssAdministrator/pytest-0/popen-gw0/test_thread_locality0/mem_policy/source.c')
            compile_extra = ['/we4013']
            include_dirs = ['D:\\bld\\numpy_1694041522631\\_test_env\\lib\\site-packages\\numpy\\core\\include', 'D:\\bld\\numpy_1694041522631\\_test_env\\Include']
            libraries  = []
            library_dirs = []
            link_extra = ['/LIBPATH:D:\\bld\\numpy_1694041522631\\_test_env\\libs', '/DEBUG']
            outputfilename = WindowsPath('C:/Users/VssAdministrator/AppData/Local/Temp/pytest-of-VssAdministrator/pytest-0/popen-gw0/test_thread_locality0/mem_policy/mem_policy.pypy39-pp73-win_amd64.pyd')
    ..\_test_env\lib\site-packages\numpy\testing\_private\extbuild.py:233: in build
        subprocess.check_call(["meson", "setup",
            build_dir  = WindowsPath('C:/Users/VssAdministrator/AppData/Local/Temp/pytest-of-VssAdministrator/pytest-0/popen-gw0/test_thread_locality0/mem_policy/build')
            cfile      = WindowsPath('C:/Users/VssAdministrator/AppData/Local/Temp/pytest-of-VssAdministrator/pytest-0/popen-gw0/test_thread_locality0/mem_policy/source.c')
            compile_extra = ['/we4013']
            fid        = <_io.TextIOWrapper name='C:\\Users\\VssAdministrator\\AppData\\Local\\Temp\\pytest-of-VssAdministrator\\pytest-0\\popen-gw0\\test_thread_locality0\\mem_policy\\meson.build' mode='wt' encoding='UTF-8'>
            include_dirs = ['D:\\bld\\numpy_1694041522631\\_test_env\\lib\\site-packages\\numpy\\core\\include', 'D:\\bld\\numpy_1694041522631\\_test_env\\Include']
            includes   = ['-ID:\\bld\\numpy_1694041522631\\_test_env\\lib\\site-packages\\numpy\\core\\include', '-ID:\\bld\\numpy_1694041522631\\_test_env\\Include']
            libraries  = []
            library_dirs = []
            link_dirs  = []
            link_extra = ['/LIBPATH:D:\\bld\\numpy_1694041522631\\_test_env\\libs', '/DEBUG']
            outputfilename = WindowsPath('C:/Users/VssAdministrator/AppData/Local/Temp/pytest-of-VssAdministrator/pytest-0/popen-gw0/test_thread_locality0/mem_policy/mem_policy.pypy39-pp73-win_amd64.pyd')
            so_name    = 'mem_policy.pypy39-pp73-win_amd64.pyd'
    _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
    
    popenargs = (['meson', 'setup', '--buildtype=release', '--vsenv', '..'],)
    kwargs = {'cwd': WindowsPath('C:/Users/VssAdministrator/AppData/Local/Temp/pytest-of-VssAdministrator/pytest-0/popen-gw0/test_thread_locality0/mem_policy/build')}
    retcode = 1, cmd = ['meson', 'setup', '--buildtype=release', '--vsenv', '..']
    
        def check_call(*popenargs, **kwargs):
            """Run command with arguments.  Wait for command to complete.  If
            the exit code was zero then return, otherwise raise
            CalledProcessError.  The CalledProcessError object will have the
            return code in the returncode attribute.
        
            The arguments are the same as for the call function.  Example:
        
            check_call(["ls", "-l"])
            """
            retcode = call(*popenargs, **kwargs)
            if retcode:
                cmd = kwargs.get("args")
                if cmd is None:
                    cmd = popenargs[0]
    >           raise CalledProcessError(retcode, cmd)
    E           subprocess.CalledProcessError: Command '['meson', 'setup', '--buildtype=release', '--vsenv', '..']' returned non-zero exit status 1.
    
    cmd        = ['meson', 'setup', '--buildtype=release', '--vsenv', '..']
    kwargs     = {'cwd': WindowsPath('C:/Users/VssAdministrator/AppData/Local/Temp/pytest-of-VssAdministrator/pytest-0/popen-gw0/test_thread_locality0/mem_policy/build')}
    popenargs  = (['meson', 'setup', '--buildtype=release', '--vsenv', '..'],)
    retcode    = 1
    
    ..\_test_env\Lib\subprocess.py:373: CalledProcessError
    
    The above exception was the direct cause of the following exception:
    
    tmp_path = WindowsPath('C:/Users/VssAdministrator/AppData/Local/Temp/pytest-of-VssAdministrator/pytest-0/popen-gw0/test_thread_locality0')
    
        @pytest.fixture
        def get_module(tmp_path):
            """ Add a memory policy that returns a false pointer 64 bytes into the
            actual allocation, and fill the prefix with some text. Then check at each
            memory manipulation that the prefix exists, to make sure all alloc/realloc/
            free/calloc go via the functions here.
            """
            if sys.platform.startswith('cygwin'):
                pytest.skip('link fails on cygwin')
            if IS_WASM:
                pytest.skip("Can't build module inside Wasm")
            functions = [
                ("get_default_policy", "METH_NOARGS", """
                     Py_INCREF(PyDataMem_DefaultHandler);
                     return PyDataMem_DefaultHandler;
                 """),
                ("set_secret_data_policy", "METH_NOARGS", """
                     PyObject *secret_data =
                         PyCapsule_New(&secret_data_handler, "mem_handler", NULL);
                     if (secret_data == NULL) {
                         return NULL;
                     }
                     PyObject *old = PyDataMem_SetHandler(secret_data);
                     Py_DECREF(secret_data);
                     return old;
                 """),
                ("set_old_policy", "METH_O", """
                     PyObject *old;
                     if (args != NULL && PyCapsule_CheckExact(args)) {
                         old = PyDataMem_SetHandler(args);
                     }
                     else {
                         old = PyDataMem_SetHandler(NULL);
                     }
                     return old;
                 """),
                ("get_array", "METH_NOARGS", """
                    char *buf = (char *)malloc(20);
                    npy_intp dims[1];
                    dims[0] = 20;
                    PyArray_Descr *descr =  PyArray_DescrNewFromType(NPY_UINT8);
                    return PyArray_NewFromDescr(&PyArray_Type, descr, 1, dims, NULL,
                                                buf, NPY_ARRAY_WRITEABLE, NULL);
                 """),
                ("set_own", "METH_O", """
                    if (!PyArray_Check(args)) {
                        PyErr_SetString(PyExc_ValueError,
                                     "need an ndarray");
                        return NULL;
                    }
                    PyArray_ENABLEFLAGS((PyArrayObject*)args, NPY_ARRAY_OWNDATA);
                    // Maybe try this too?
                    // PyArray_BASE(PyArrayObject *)args) = NULL;
                    Py_RETURN_NONE;
                 """),
                ("get_array_with_base", "METH_NOARGS", """
                    char *buf = (char *)malloc(20);
                    npy_intp dims[1];
                    dims[0] = 20;
                    PyArray_Descr *descr =  PyArray_DescrNewFromType(NPY_UINT8);
                    PyObject *arr = PyArray_NewFromDescr(&PyArray_Type, descr, 1, dims,
                                                         NULL, buf,
                                                         NPY_ARRAY_WRITEABLE, NULL);
                    if (arr == NULL) return NULL;
                    PyObject *obj = PyCapsule_New(buf, "buf capsule",
                                                  (PyCapsule_Destructor)&warn_on_free);
                    if (obj == NULL) {
                        Py_DECREF(arr);
                        return NULL;
                    }
                    if (PyArray_SetBaseObject((PyArrayObject *)arr, obj) < 0) {
                        Py_DECREF(arr);
                        Py_DECREF(obj);
                        return NULL;
                    }
                    return arr;
        
                 """),
            ]
            prologue = '''
                #define NPY_TARGET_VERSION NPY_1_22_API_VERSION
                #define NPY_NO_DEPRECATED_API NPY_1_7_API_VERSION
                #include <numpy/arrayobject.h>
                /*
                 * This struct allows the dynamic configuration of the allocator funcs
                 * of the `secret_data_allocator`. It is provided here for
                 * demonstration purposes, as a valid `ctx` use-case scenario.
                 */
                typedef struct {
                    void *(*malloc)(size_t);
                    void *(*calloc)(size_t, size_t);
                    void *(*realloc)(void *, size_t);
                    void (*free)(void *);
                } SecretDataAllocatorFuncs;
        
                NPY_NO_EXPORT void *
                shift_alloc(void *ctx, size_t sz) {
                    SecretDataAllocatorFuncs *funcs = (SecretDataAllocatorFuncs *)ctx;
                    char *real = (char *)funcs->malloc(sz + 64);
                    if (real == NULL) {
                        return NULL;
                    }
                    snprintf(real, 64, "originally allocated %ld", (unsigned long)sz);
                    return (void *)(real + 64);
                }
                NPY_NO_EXPORT void *
                shift_zero(void *ctx, size_t sz, size_t cnt) {
                    SecretDataAllocatorFuncs *funcs = (SecretDataAllocatorFuncs *)ctx;
                    char *real = (char *)funcs->calloc(sz + 64, cnt);
                    if (real == NULL) {
                        return NULL;
                    }
                    snprintf(real, 64, "originally allocated %ld via zero",
                             (unsigned long)sz);
                    return (void *)(real + 64);
                }
                NPY_NO_EXPORT void
                shift_free(void *ctx, void * p, npy_uintp sz) {
                    SecretDataAllocatorFuncs *funcs = (SecretDataAllocatorFuncs *)ctx;
                    if (p == NULL) {
                        return ;
                    }
                    char *real = (char *)p - 64;
                    if (strncmp(real, "originally allocated", 20) != 0) {
                        fprintf(stdout, "uh-oh, unmatched shift_free, "
                                "no appropriate prefix\\n");
                        /* Make C runtime crash by calling free on the wrong address */
                        funcs->free((char *)p + 10);
                        /* funcs->free(real); */
                    }
                    else {
                        npy_uintp i = (npy_uintp)atoi(real +20);
                        if (i != sz) {
                            fprintf(stderr, "uh-oh, unmatched shift_free"
                                    "(ptr, %ld) but allocated %ld\\n", sz, i);
                            /* This happens in some places, only print */
                            funcs->free(real);
                        }
                        else {
                            funcs->free(real);
                        }
                    }
                }
                NPY_NO_EXPORT void *
                shift_realloc(void *ctx, void * p, npy_uintp sz) {
                    SecretDataAllocatorFuncs *funcs = (SecretDataAllocatorFuncs *)ctx;
                    if (p != NULL) {
                        char *real = (char *)p - 64;
                        if (strncmp(real, "originally allocated", 20) != 0) {
                            fprintf(stdout, "uh-oh, unmatched shift_realloc\\n");
                            return realloc(p, sz);
                        }
                        return (void *)((char *)funcs->realloc(real, sz + 64) + 64);
                    }
                    else {
                        char *real = (char *)funcs->realloc(p, sz + 64);
                        if (real == NULL) {
                            return NULL;
                        }
                        snprintf(real, 64, "originally allocated "
                                 "%ld  via realloc", (unsigned long)sz);
                        return (void *)(real + 64);
                    }
                }
                /* As an example, we use the standard {m|c|re}alloc/free funcs. */
                static SecretDataAllocatorFuncs secret_data_handler_ctx = {
                    malloc,
                    calloc,
                    realloc,
                    free
                };
                static PyDataMem_Handler secret_data_handler = {
                    "secret_data_allocator",
                    1,
                    {
                        &secret_data_handler_ctx, /* ctx */
                        shift_alloc,              /* malloc */
                        shift_zero,               /* calloc */
                        shift_realloc,            /* realloc */
                        shift_free                /* free */
                    }
                };
                void warn_on_free(void *capsule) {
                    PyErr_WarnEx(PyExc_UserWarning, "in warn_on_free", 1);
                    void * obj = PyCapsule_GetPointer(capsule,
                                                      PyCapsule_GetName(capsule));
                    free(obj);
                };
                '''
            more_init = "import_array();"
            try:
                import mem_policy
                return mem_policy
            except ImportError:
                pass
            # if it does not exist, build and load it
    >       return extbuild.build_and_import_extension('mem_policy',
                                                       functions,
                                                       prologue=prologue,
                                                       include_dirs=[np.get_include()],
                                                       build_dir=tmp_path,
                                                       more_init=more_init)
    
    functions  = [('get_default_policy', 'METH_NOARGS', '\n             Py_INCREF(PyDataMem_DefaultHandler);\n             return PyDat...\n                Py_DECREF(obj);\n                return NULL;\n            }\n            return arr;\n\n         ')]
    more_init  = 'import_array();'
    prologue   = '\n        #define NPY_TARGET_VERSION NPY_1_22_API_VERSION\n        #define NPY_NO_DEPRECATED_API NPY_1_7_API_VERSION\...                                            PyCapsule_GetName(capsule));\n            free(obj);\n        };\n        '
    tmp_path   = WindowsPath('C:/Users/VssAdministrator/AppData/Local/Temp/pytest-of-VssAdministrator/pytest-0/popen-gw0/test_thread_locality0')
    
    ..\_test_env\lib\site-packages\numpy\core\tests\test_mem_policy.py:213: 
    _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
    
    modname = 'mem_policy'
    functions = [('get_default_policy', 'METH_NOARGS', '\n             Py_INCREF(PyDataMem_DefaultHandler);\n             return PyDat...\n                Py_DECREF(obj);\n                return NULL;\n            }\n            return arr;\n\n         ')]
    
        def build_and_import_extension(
                modname, functions, *, prologue="", build_dir=None,
                include_dirs=[], more_init=""):
            """
            Build and imports a c-extension module `modname` from a list of function
            fragments `functions`.
        
        
            Parameters
            ----------
            functions : list of fragments
                Each fragment is a sequence of func_name, calling convention, snippet.
            prologue : string
                Code to precede the rest, usually extra ``#include`` or ``#define``
                macros.
            build_dir : pathlib.Path
                Where to build the module, usually a temporary directory
            include_dirs : list
                Extra directories to find include files when compiling
            more_init : string
                Code to appear in the module PyMODINIT_FUNC
        
            Returns
            -------
            out: module
                The module will have been loaded and is ready for use
        
            Examples
            --------
            >>> functions = [("test_bytes", "METH_O", \"\"\"
                if ( !PyBytesCheck(args)) {
                    Py_RETURN_FALSE;
                }
                Py_RETURN_TRUE;
            \"\"\")]
            >>> mod = build_and_import_extension("testme", functions)
            >>> assert not mod.test_bytes(u'abc')
            >>> assert mod.test_bytes(b'abc')
            """
            body = prologue + _make_methods(functions, modname)
            init = """PyObject *mod = PyModule_Create(&moduledef);
                   """
            if not build_dir:
                build_dir = pathlib.Path('.')
            if more_init:
                init += """#define INITERROR return NULL
                        """
                init += more_init
            init += "\nreturn mod;"
            source_string = _make_source(modname, init, body)
            try:
                mod_so = compile_extension_module(
                    modname, build_dir, include_dirs, source_string)
            except Exception as e:
                # shorten the exception chain
    >           raise RuntimeError(f"could not compile in {build_dir}:") from e
    E           RuntimeError: could not compile in C:\Users\VssAdministrator\AppData\Local\Temp\pytest-of-VssAdministrator\pytest-0\popen-gw0\test_thread_locality0:
    
    body       = '\n        #define NPY_TARGET_VERSION NPY_1_22_API_VERSION\n        #define NPY_NO_DEPRECATED_API NPY_1_7_API_VERSION\...LL,           /* m_doc */\n        -1,             /* m_size */\n        methods,        /* m_methods */\n    };\n    '
    build_dir  = WindowsPath('C:/Users/VssAdministrator/AppData/Local/Temp/pytest-of-VssAdministrator/pytest-0/popen-gw0/test_thread_locality0')
    functions  = [('get_default_policy', 'METH_NOARGS', '\n             Py_INCREF(PyDataMem_DefaultHandler);\n             return PyDat...\n                Py_DECREF(obj);\n                return NULL;\n            }\n            return arr;\n\n         ')]
    include_dirs = ['D:\\bld\\numpy_1694041522631\\_test_env\\lib\\site-packages\\numpy\\core\\include']
    init       = 'PyObject *mod = PyModule_Create(&moduledef);\n           #define INITERROR return NULL\n                import_array();\nreturn mod;'
    modname    = 'mem_policy'
    more_init  = 'import_array();'
    prologue   = '\n        #define NPY_TARGET_VERSION NPY_1_22_API_VERSION\n        #define NPY_NO_DEPRECATED_API NPY_1_7_API_VERSION\...                                            PyCapsule_GetName(capsule));\n            free(obj);\n        };\n        '
    source_string = '\n    #include <Python.h>\n\n    \n        #define NPY_TARGET_VERSION NPY_1_22_API_VERSION\n        #define NPY_NO_DE...eate(&moduledef);\n           #define INITERROR return NULL\n                import_array();\nreturn mod;\n    }\n    '
    
    ..\_test_env\lib\site-packages\numpy\testing\_private\extbuild.py:72: RuntimeError
    Captured stderr setup ----------------------------
    Traceback (most recent call last):
    
      File "%PREFIX%\Scripts\meson-script.py", line 9, in <module>
    
        sys.exit(main())
    
      File "%PREFIX%\lib\site-packages\mesonbuild\mesonmain.py", line 294, in main
    
        return run(sys.argv[1:], launcher)
    
      File "%PREFIX%\lib\site-packages\mesonbuild\mesonmain.py", line 261, in run
    
        ensure_stdout_accepts_unicode()
    
      File "%PREFIX%\lib\site-packages\mesonbuild\mesonmain.py", line 230, in ensure_stdout_accepts_unicode
    
        if sys.stdout.encoding and not sys.stdout.encoding.upper().startswith('UTF-'):
    
    AttributeError: 'NoneType' object has no attribute 'encoding'
    
    ____________________ ERROR at setup of test_owner_is_base _____________________
    [gw0] win32 -- Python 3.9.17 %PREFIX%\python.exe
    
    modname = 'mem_policy'
    functions = [('get_default_policy', 'METH_NOARGS', '\n             Py_INCREF(PyDataMem_DefaultHandler);\n             return PyDat...\n                Py_DECREF(obj);\n                return NULL;\n            }\n            return arr;\n\n         ')]
    
        def build_and_import_extension(
                modname, functions, *, prologue="", build_dir=None,
                include_dirs=[], more_init=""):
            """
            Build and imports a c-extension module `modname` from a list of function
            fragments `functions`.
        
        
            Parameters
            ----------
            functions : list of fragments
                Each fragment is a sequence of func_name, calling convention, snippet.
            prologue : string
                Code to precede the rest, usually extra ``#include`` or ``#define``
                macros.
            build_dir : pathlib.Path
                Where to build the module, usually a temporary directory
            include_dirs : list
                Extra directories to find include files when compiling
            more_init : string
                Code to appear in the module PyMODINIT_FUNC
        
            Returns
            -------
            out: module
                The module will have been loaded and is ready for use
        
            Examples
            --------
            >>> functions = [("test_bytes", "METH_O", \"\"\"
                if ( !PyBytesCheck(args)) {
                    Py_RETURN_FALSE;
                }
                Py_RETURN_TRUE;
            \"\"\")]
            >>> mod = build_and_import_extension("testme", functions)
            >>> assert not mod.test_bytes(u'abc')
            >>> assert mod.test_bytes(b'abc')
            """
            body = prologue + _make_methods(functions, modname)
            init = """PyObject *mod = PyModule_Create(&moduledef);
                   """
            if not build_dir:
                build_dir = pathlib.Path('.')
            if more_init:
                init += """#define INITERROR return NULL
                        """
                init += more_init
            init += "\nreturn mod;"
            source_string = _make_source(modname, init, body)
            try:
    >           mod_so = compile_extension_module(
                    modname, build_dir, include_dirs, source_string)
    
    body       = '\n        #define NPY_TARGET_VERSION NPY_1_22_API_VERSION\n        #define NPY_NO_DEPRECATED_API NPY_1_7_API_VERSION\...LL,           /* m_doc */\n        -1,             /* m_size */\n        methods,        /* m_methods */\n    };\n    '
    build_dir  = WindowsPath('C:/Users/VssAdministrator/AppData/Local/Temp/pytest-of-VssAdministrator/pytest-0/popen-gw0/test_owner_is_base0')
    functions  = [('get_default_policy', 'METH_NOARGS', '\n             Py_INCREF(PyDataMem_DefaultHandler);\n             return PyDat...\n                Py_DECREF(obj);\n                return NULL;\n            }\n            return arr;\n\n         ')]
    include_dirs = ['D:\\bld\\numpy_1694041522631\\_test_env\\lib\\site-packages\\numpy\\core\\include']
    init       = 'PyObject *mod = PyModule_Create(&moduledef);\n           #define INITERROR return NULL\n                import_array();\nreturn mod;'
    modname    = 'mem_policy'
    more_init  = 'import_array();'
    prologue   = '\n        #define NPY_TARGET_VERSION NPY_1_22_API_VERSION\n        #define NPY_NO_DEPRECATED_API NPY_1_7_API_VERSION\...                                            PyCapsule_GetName(capsule));\n            free(obj);\n        };\n        '
    source_string = '\n    #include <Python.h>\n\n    \n        #define NPY_TARGET_VERSION NPY_1_22_API_VERSION\n        #define NPY_NO_DE...eate(&moduledef);\n           #define INITERROR return NULL\n                import_array();\nreturn mod;\n    }\n    '
    
    ..\_test_env\lib\site-packages\numpy\testing\_private\extbuild.py:68: 
    _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
    ..\_test_env\lib\site-packages\numpy\testing\_private\extbuild.py:107: in compile_extension_module
        return _c_compile(
            builddir   = WindowsPath('C:/Users/VssAdministrator/AppData/Local/Temp/pytest-of-VssAdministrator/pytest-0/popen-gw0/test_owner_is_base0')
            cfile      = WindowsPath('C:/Users/VssAdministrator/AppData/Local/Temp/pytest-of-VssAdministrator/pytest-0/popen-gw0/test_owner_is_base0/mem_policy/source.c')
            dirname    = WindowsPath('C:/Users/VssAdministrator/AppData/Local/Temp/pytest-of-VssAdministrator/pytest-0/popen-gw0/test_owner_is_base0/mem_policy')
            include_dirs = ['D:\\bld\\numpy_1694041522631\\_test_env\\lib\\site-packages\\numpy\\core\\include', 'D:\\bld\\numpy_1694041522631\\_test_env\\Include']
            libraries  = []
            library_dirs = []
            modname    = 'mem_policy'
            name       = 'mem_policy'
            source_string = '\n    #include <Python.h>\n\n    \n        #define NPY_TARGET_VERSION NPY_1_22_API_VERSION\n        #define NPY_NO_DE...eate(&moduledef);\n           #define INITERROR return NULL\n                import_array();\nreturn mod;\n    }\n    '
    ..\_test_env\lib\site-packages\numpy\testing\_private\extbuild.py:205: in _c_compile
        build(
            cfile      = WindowsPath('C:/Users/VssAdministrator/AppData/Local/Temp/pytest-of-VssAdministrator/pytest-0/popen-gw0/test_owner_is_base0/mem_policy/source.c')
            compile_extra = ['/we4013']
            include_dirs = ['D:\\bld\\numpy_1694041522631\\_test_env\\lib\\site-packages\\numpy\\core\\include', 'D:\\bld\\numpy_1694041522631\\_test_env\\Include']
            libraries  = []
            library_dirs = []
            link_extra = ['/LIBPATH:D:\\bld\\numpy_1694041522631\\_test_env\\libs', '/DEBUG']
            outputfilename = WindowsPath('C:/Users/VssAdministrator/AppData/Local/Temp/pytest-of-VssAdministrator/pytest-0/popen-gw0/test_owner_is_base0/mem_policy/mem_policy.pypy39-pp73-win_amd64.pyd')
    ..\_test_env\lib\site-packages\numpy\testing\_private\extbuild.py:233: in build
        subprocess.check_call(["meson", "setup",
            build_dir  = WindowsPath('C:/Users/VssAdministrator/AppData/Local/Temp/pytest-of-VssAdministrator/pytest-0/popen-gw0/test_owner_is_base0/mem_policy/build')
            cfile      = WindowsPath('C:/Users/VssAdministrator/AppData/Local/Temp/pytest-of-VssAdministrator/pytest-0/popen-gw0/test_owner_is_base0/mem_policy/source.c')
            compile_extra = ['/we4013']
            fid        = <_io.TextIOWrapper name='C:\\Users\\VssAdministrator\\AppData\\Local\\Temp\\pytest-of-VssAdministrator\\pytest-0\\popen-gw0\\test_owner_is_base0\\mem_policy\\meson.build' mode='wt' encoding='UTF-8'>
            include_dirs = ['D:\\bld\\numpy_1694041522631\\_test_env\\lib\\site-packages\\numpy\\core\\include', 'D:\\bld\\numpy_1694041522631\\_test_env\\Include']
            includes   = ['-ID:\\bld\\numpy_1694041522631\\_test_env\\lib\\site-packages\\numpy\\core\\include', '-ID:\\bld\\numpy_1694041522631\\_test_env\\Include']
            libraries  = []
            library_dirs = []
            link_dirs  = []
            link_extra = ['/LIBPATH:D:\\bld\\numpy_1694041522631\\_test_env\\libs', '/DEBUG']
            outputfilename = WindowsPath('C:/Users/VssAdministrator/AppData/Local/Temp/pytest-of-VssAdministrator/pytest-0/popen-gw0/test_owner_is_base0/mem_policy/mem_policy.pypy39-pp73-win_amd64.pyd')
            so_name    = 'mem_policy.pypy39-pp73-win_amd64.pyd'
    _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
    
    popenargs = (['meson', 'setup', '--buildtype=release', '--vsenv', '..'],)
    kwargs = {'cwd': WindowsPath('C:/Users/VssAdministrator/AppData/Local/Temp/pytest-of-VssAdministrator/pytest-0/popen-gw0/test_owner_is_base0/mem_policy/build')}
    retcode = 1, cmd = ['meson', 'setup', '--buildtype=release', '--vsenv', '..']
    
        def check_call(*popenargs, **kwargs):
            """Run command with arguments.  Wait for command to complete.  If
            the exit code was zero then return, otherwise raise
            CalledProcessError.  The CalledProcessError object will have the
            return code in the returncode attribute.
        
            The arguments are the same as for the call function.  Example:
        
            check_call(["ls", "-l"])
            """
            retcode = call(*popenargs, **kwargs)
            if retcode:
                cmd = kwargs.get("args")
                if cmd is None:
                    cmd = popenargs[0]
    >           raise CalledProcessError(retcode, cmd)
    E           subprocess.CalledProcessError: Command '['meson', 'setup', '--buildtype=release', '--vsenv', '..']' returned non-zero exit status 1.
    
    cmd        = ['meson', 'setup', '--buildtype=release', '--vsenv', '..']
    kwargs     = {'cwd': WindowsPath('C:/Users/VssAdministrator/AppData/Local/Temp/pytest-of-VssAdministrator/pytest-0/popen-gw0/test_owner_is_base0/mem_policy/build')}
    popenargs  = (['meson', 'setup', '--buildtype=release', '--vsenv', '..'],)
    retcode    = 1
    
    ..\_test_env\Lib\subprocess.py:373: CalledProcessError
    
    The above exception was the direct cause of the following exception:
    
    tmp_path = WindowsPath('C:/Users/VssAdministrator/AppData/Local/Temp/pytest-of-VssAdministrator/pytest-0/popen-gw0/test_owner_is_base0')
    
        @pytest.fixture
        def get_module(tmp_path):
            """ Add a memory policy that returns a false pointer 64 bytes into the
            actual allocation, and fill the prefix with some text. Then check at each
            memory manipulation that the prefix exists, to make sure all alloc/realloc/
            free/calloc go via the functions here.
            """
            if sys.platform.startswith('cygwin'):
                pytest.skip('link fails on cygwin')
            if IS_WASM:
                pytest.skip("Can't build module inside Wasm")
            functions = [
                ("get_default_policy", "METH_NOARGS", """
                     Py_INCREF(PyDataMem_DefaultHandler);
                     return PyDataMem_DefaultHandler;
                 """),
                ("set_secret_data_policy", "METH_NOARGS", """
                     PyObject *secret_data =
                         PyCapsule_New(&secret_data_handler, "mem_handler", NULL);
                     if (secret_data == NULL) {
                         return NULL;
                     }
                     PyObject *old = PyDataMem_SetHandler(secret_data);
                     Py_DECREF(secret_data);
                     return old;
                 """),
                ("set_old_policy", "METH_O", """
                     PyObject *old;
                     if (args != NULL && PyCapsule_CheckExact(args)) {
                         old = PyDataMem_SetHandler(args);
                     }
                     else {
                         old = PyDataMem_SetHandler(NULL);
                     }
                     return old;
                 """),
                ("get_array", "METH_NOARGS", """
                    char *buf = (char *)malloc(20);
                    npy_intp dims[1];
                    dims[0] = 20;
                    PyArray_Descr *descr =  PyArray_DescrNewFromType(NPY_UINT8);
                    return PyArray_NewFromDescr(&PyArray_Type, descr, 1, dims, NULL,
                                                buf, NPY_ARRAY_WRITEABLE, NULL);
                 """),
                ("set_own", "METH_O", """
                    if (!PyArray_Check(args)) {
                        PyErr_SetString(PyExc_ValueError,
                                     "need an ndarray");
                        return NULL;
                    }
                    PyArray_ENABLEFLAGS((PyArrayObject*)args, NPY_ARRAY_OWNDATA);
                    // Maybe try this too?
                    // PyArray_BASE(PyArrayObject *)args) = NULL;
                    Py_RETURN_NONE;
                 """),
                ("get_array_with_base", "METH_NOARGS", """
                    char *buf = (char *)malloc(20);
                    npy_intp dims[1];
                    dims[0] = 20;
                    PyArray_Descr *descr =  PyArray_DescrNewFromType(NPY_UINT8);
                    PyObject *arr = PyArray_NewFromDescr(&PyArray_Type, descr, 1, dims,
                                                         NULL, buf,
                                                         NPY_ARRAY_WRITEABLE, NULL);
                    if (arr == NULL) return NULL;
                    PyObject *obj = PyCapsule_New(buf, "buf capsule",
                                                  (PyCapsule_Destructor)&warn_on_free);
                    if (obj == NULL) {
                        Py_DECREF(arr);
                        return NULL;
                    }
                    if (PyArray_SetBaseObject((PyArrayObject *)arr, obj) < 0) {
                        Py_DECREF(arr);
                        Py_DECREF(obj);
                        return NULL;
                    }
                    return arr;
        
                 """),
            ]
            prologue = '''
                #define NPY_TARGET_VERSION NPY_1_22_API_VERSION
                #define NPY_NO_DEPRECATED_API NPY_1_7_API_VERSION
                #include <numpy/arrayobject.h>
                /*
                 * This struct allows the dynamic configuration of the allocator funcs
                 * of the `secret_data_allocator`. It is provided here for
                 * demonstration purposes, as a valid `ctx` use-case scenario.
                 */
                typedef struct {
                    void *(*malloc)(size_t);
                    void *(*calloc)(size_t, size_t);
                    void *(*realloc)(void *, size_t);
                    void (*free)(void *);
                } SecretDataAllocatorFuncs;
        
                NPY_NO_EXPORT void *
                shift_alloc(void *ctx, size_t sz) {
                    SecretDataAllocatorFuncs *funcs = (SecretDataAllocatorFuncs *)ctx;
                    char *real = (char *)funcs->malloc(sz + 64);
                    if (real == NULL) {
                        return NULL;
                    }
                    snprintf(real, 64, "originally allocated %ld", (unsigned long)sz);
                    return (void *)(real + 64);
                }
                NPY_NO_EXPORT void *
                shift_zero(void *ctx, size_t sz, size_t cnt) {
                    SecretDataAllocatorFuncs *funcs = (SecretDataAllocatorFuncs *)ctx;
                    char *real = (char *)funcs->calloc(sz + 64, cnt);
                    if (real == NULL) {
                        return NULL;
                    }
                    snprintf(real, 64, "originally allocated %ld via zero",
                             (unsigned long)sz);
                    return (void *)(real + 64);
                }
                NPY_NO_EXPORT void
                shift_free(void *ctx, void * p, npy_uintp sz) {
                    SecretDataAllocatorFuncs *funcs = (SecretDataAllocatorFuncs *)ctx;
                    if (p == NULL) {
                        return ;
                    }
                    char *real = (char *)p - 64;
                    if (strncmp(real, "originally allocated", 20) != 0) {
                        fprintf(stdout, "uh-oh, unmatched shift_free, "
                                "no appropriate prefix\\n");
                        /* Make C runtime crash by calling free on the wrong address */
                        funcs->free((char *)p + 10);
                        /* funcs->free(real); */
                    }
                    else {
                        npy_uintp i = (npy_uintp)atoi(real +20);
                        if (i != sz) {
                            fprintf(stderr, "uh-oh, unmatched shift_free"
                                    "(ptr, %ld) but allocated %ld\\n", sz, i);
                            /* This happens in some places, only print */
                            funcs->free(real);
                        }
                        else {
                            funcs->free(real);
                        }
                    }
                }
                NPY_NO_EXPORT void *
                shift_realloc(void *ctx, void * p, npy_uintp sz) {
                    SecretDataAllocatorFuncs *funcs = (SecretDataAllocatorFuncs *)ctx;
                    if (p != NULL) {
                        char *real = (char *)p - 64;
                        if (strncmp(real, "originally allocated", 20) != 0) {
                            fprintf(stdout, "uh-oh, unmatched shift_realloc\\n");
                            return realloc(p, sz);
                        }
                        return (void *)((char *)funcs->realloc(real, sz + 64) + 64);
                    }
                    else {
                        char *real = (char *)funcs->realloc(p, sz + 64);
                        if (real == NULL) {
                            return NULL;
                        }
                        snprintf(real, 64, "originally allocated "
                                 "%ld  via realloc", (unsigned long)sz);
                        return (void *)(real + 64);
                    }
                }
                /* As an example, we use the standard {m|c|re}alloc/free funcs. */
                static SecretDataAllocatorFuncs secret_data_handler_ctx = {
                    malloc,
                    calloc,
                    realloc,
                    free
                };
                static PyDataMem_Handler secret_data_handler = {
                    "secret_data_allocator",
                    1,
                    {
                        &secret_data_handler_ctx, /* ctx */
                        shift_alloc,              /* malloc */
                        shift_zero,               /* calloc */
                        shift_realloc,            /* realloc */
                        shift_free                /* free */
                    }
                };
                void warn_on_free(void *capsule) {
                    PyErr_WarnEx(PyExc_UserWarning, "in warn_on_free", 1);
                    void * obj = PyCapsule_GetPointer(capsule,
                                                      PyCapsule_GetName(capsule));
                    free(obj);
                };
                '''
            more_init = "import_array();"
            try:
                import mem_policy
                return mem_policy
            except ImportError:
                pass
            # if it does not exist, build and load it
    >       return extbuild.build_and_import_extension('mem_policy',
                                                       functions,
                                                       prologue=prologue,
                                                       include_dirs=[np.get_include()],
                                                       build_dir=tmp_path,
                                                       more_init=more_init)
    
    functions  = [('get_default_policy', 'METH_NOARGS', '\n             Py_INCREF(PyDataMem_DefaultHandler);\n             return PyDat...\n                Py_DECREF(obj);\n                return NULL;\n            }\n            return arr;\n\n         ')]
    more_init  = 'import_array();'
    prologue   = '\n        #define NPY_TARGET_VERSION NPY_1_22_API_VERSION\n        #define NPY_NO_DEPRECATED_API NPY_1_7_API_VERSION\...                                            PyCapsule_GetName(capsule));\n            free(obj);\n        };\n        '
    tmp_path   = WindowsPath('C:/Users/VssAdministrator/AppData/Local/Temp/pytest-of-VssAdministrator/pytest-0/popen-gw0/test_owner_is_base0')
    
    ..\_test_env\lib\site-packages\numpy\core\tests\test_mem_policy.py:213: 
    _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
    
    modname = 'mem_policy'
    functions = [('get_default_policy', 'METH_NOARGS', '\n             Py_INCREF(PyDataMem_DefaultHandler);\n             return PyDat...\n                Py_DECREF(obj);\n                return NULL;\n            }\n            return arr;\n\n         ')]
    
        def build_and_import_extension(
                modname, functions, *, prologue="", build_dir=None,
                include_dirs=[], more_init=""):
            """
            Build and imports a c-extension module `modname` from a list of function
            fragments `functions`.
        
        
            Parameters
            ----------
            functions : list of fragments
                Each fragment is a sequence of func_name, calling convention, snippet.
            prologue : string
                Code to precede the rest, usually extra ``#include`` or ``#define``
                macros.
            build_dir : pathlib.Path
                Where to build the module, usually a temporary directory
            include_dirs : list
                Extra directories to find include files when compiling
            more_init : string
                Code to appear in the module PyMODINIT_FUNC
        
            Returns
            -------
            out: module
                The module will have been loaded and is ready for use
        
            Examples
            --------
            >>> functions = [("test_bytes", "METH_O", \"\"\"
                if ( !PyBytesCheck(args)) {
                    Py_RETURN_FALSE;
                }
                Py_RETURN_TRUE;
            \"\"\")]
            >>> mod = build_and_import_extension("testme", functions)
            >>> assert not mod.test_bytes(u'abc')
            >>> assert mod.test_bytes(b'abc')
            """
            body = prologue + _make_methods(functions, modname)
            init = """PyObject *mod = PyModule_Create(&moduledef);
                   """
            if not build_dir:
                build_dir = pathlib.Path('.')
            if more_init:
                init += """#define INITERROR return NULL
                        """
                init += more_init
            init += "\nreturn mod;"
            source_string = _make_source(modname, init, body)
            try:
                mod_so = compile_extension_module(
                    modname, build_dir, include_dirs, source_string)
            except Exception as e:
                # shorten the exception chain
    >           raise RuntimeError(f"could not compile in {build_dir}:") from e
    E           RuntimeError: could not compile in C:\Users\VssAdministrator\AppData\Local\Temp\pytest-of-VssAdministrator\pytest-0\popen-gw0\test_owner_is_base0:
    
    body       = '\n        #define NPY_TARGET_VERSION NPY_1_22_API_VERSION\n        #define NPY_NO_DEPRECATED_API NPY_1_7_API_VERSION\...LL,           /* m_doc */\n        -1,             /* m_size */\n        methods,        /* m_methods */\n    };\n    '
    build_dir  = WindowsPath('C:/Users/VssAdministrator/AppData/Local/Temp/pytest-of-VssAdministrator/pytest-0/popen-gw0/test_owner_is_base0')
    functions  = [('get_default_policy', 'METH_NOARGS', '\n             Py_INCREF(PyDataMem_DefaultHandler);\n             return PyDat...\n                Py_DECREF(obj);\n                return NULL;\n            }\n            return arr;\n\n         ')]
    include_dirs = ['D:\\bld\\numpy_1694041522631\\_test_env\\lib\\site-packages\\numpy\\core\\include']
    init       = 'PyObject *mod = PyModule_Create(&moduledef);\n           #define INITERROR return NULL\n                import_array();\nreturn mod;'
    modname    = 'mem_policy'
    more_init  = 'import_array();'
    prologue   = '\n        #define NPY_TARGET_VERSION NPY_1_22_API_VERSION\n        #define NPY_NO_DEPRECATED_API NPY_1_7_API_VERSION\...                                            PyCapsule_GetName(capsule));\n            free(obj);\n        };\n        '
    source_string = '\n    #include <Python.h>\n\n    \n        #define NPY_TARGET_VERSION NPY_1_22_API_VERSION\n        #define NPY_NO_DE...eate(&moduledef);\n           #define INITERROR return NULL\n                import_array();\nreturn mod;\n    }\n    '
    
    ..\_test_env\lib\site-packages\numpy\testing\_private\extbuild.py:72: RuntimeError
    Captured stderr setup ----------------------------
    Traceback (most recent call last):
    
      File "%PREFIX%\Scripts\meson-script.py", line 9, in <module>
    
        sys.exit(main())
    
      File "%PREFIX%\lib\site-packages\mesonbuild\mesonmain.py", line 294, in main
    
        return run(sys.argv[1:], launcher)
    
      File "%PREFIX%\lib\site-packages\mesonbuild\mesonmain.py", line 261, in run
    
        ensure_stdout_accepts_unicode()
    
      File "%PREFIX%\lib\site-packages\mesonbuild\mesonmain.py", line 230, in ensure_stdout_accepts_unicode
    
        if sys.stdout.encoding and not sys.stdout.encoding.upper().startswith('UTF-'):
    
    AttributeError: 'NoneType' object has no attribute 'encoding'
    
    ================================== FAILURES ===================================
    _________________________________ test_cython _________________________________
    [gw0] win32 -- Python 3.9.17 %PREFIX%\python.exe
    
    tmp_path = WindowsPath('C:/Users/VssAdministrator/AppData/Local/Temp/pytest-of-VssAdministrator/pytest-0/popen-gw0/test_cython0')
    
        @pytest.mark.skipif(IS_WASM, reason="Can't start subprocess")
        @pytest.mark.skipif(cython is None, reason="requires cython")
        @pytest.mark.slow
        def test_cython(tmp_path):
            import glob
            # build the examples in a temporary directory
            srcdir = os.path.join(os.path.dirname(__file__), '..')
            shutil.copytree(srcdir, tmp_path / 'random')
            build_dir = tmp_path / 'random' / '_examples' / 'cython'
            target_dir = build_dir / "build"
            os.makedirs(target_dir, exist_ok=True)
            if sys.platform == "win32":
    >           subprocess.check_call(["meson", "setup",
                                       "--buildtype=release",
                                       "--vsenv", str(build_dir)],
                                      cwd=target_dir,
                                      )
    
    build_dir  = WindowsPath('C:/Users/VssAdministrator/AppData/Local/Temp/pytest-of-VssAdministrator/pytest-0/popen-gw0/test_cython0/random/_examples/cython')
    glob       = <module 'glob' from 'D:\\bld\\numpy_1694041522631\\_test_env\\Lib\\glob.py'>
    srcdir     = 'D:\\bld\\numpy_1694041522631\\_test_env\\lib\\site-packages\\numpy\\random\\tests\\..'
    target_dir = WindowsPath('C:/Users/VssAdministrator/AppData/Local/Temp/pytest-of-VssAdministrator/pytest-0/popen-gw0/test_cython0/random/_examples/cython/build')
    tmp_path   = WindowsPath('C:/Users/VssAdministrator/AppData/Local/Temp/pytest-of-VssAdministrator/pytest-0/popen-gw0/test_cython0')
    
    ..\_test_env\lib\site-packages\numpy\random\tests\test_extending.py:64: 
    _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
    
    popenargs = (['meson', 'setup', '--buildtype=release', '--vsenv', 'C:\\Users\\VssAdministrator\\AppData\\Local\\Temp\\pytest-of-VssAdministrator\\pytest-0\\popen-gw0\\test_cython0\\random\\_examples\\cython'],)
    kwargs = {'cwd': WindowsPath('C:/Users/VssAdministrator/AppData/Local/Temp/pytest-of-VssAdministrator/pytest-0/popen-gw0/test_cython0/random/_examples/cython/build')}
    retcode = 1
    cmd = ['meson', 'setup', '--buildtype=release', '--vsenv', 'C:\\Users\\VssAdministrator\\AppData\\Local\\Temp\\pytest-of-VssAdministrator\\pytest-0\\popen-gw0\\test_cython0\\random\\_examples\\cython']
    
        def check_call(*popenargs, **kwargs):
            """Run command with arguments.  Wait for command to complete.  If
            the exit code was zero then return, otherwise raise
            CalledProcessError.  The CalledProcessError object will have the
            return code in the returncode attribute.
        
            The arguments are the same as for the call function.  Example:
        
            check_call(["ls", "-l"])
            """
            retcode = call(*popenargs, **kwargs)
            if retcode:
                cmd = kwargs.get("args")
                if cmd is None:
                    cmd = popenargs[0]
    >           raise CalledProcessError(retcode, cmd)
    E           subprocess.CalledProcessError: Command '['meson', 'setup', '--buildtype=release', '--vsenv', 'C:\\Users\\VssAdministrator\\AppData\\Local\\Temp\\pytest-of-VssAdministrator\\pytest-0\\popen-gw0\\test_cython0\\random\\_examples\\cython']' returned non-zero exit status 1.
    
    cmd        = ['meson', 'setup', '--buildtype=release', '--vsenv', 'C:\\Users\\VssAdministrator\\AppData\\Local\\Temp\\pytest-of-VssAdministrator\\pytest-0\\popen-gw0\\test_cython0\\random\\_examples\\cython']
    kwargs     = {'cwd': WindowsPath('C:/Users/VssAdministrator/AppData/Local/Temp/pytest-of-VssAdministrator/pytest-0/popen-gw0/test_cython0/random/_examples/cython/build')}
    popenargs  = (['meson', 'setup', '--buildtype=release', '--vsenv', 'C:\\Users\\VssAdministrator\\AppData\\Local\\Temp\\pytest-of-VssAdministrator\\pytest-0\\popen-gw0\\test_cython0\\random\\_examples\\cython'],)
    retcode    = 1
    
    ..\_test_env\Lib\subprocess.py:373: CalledProcessError
    _________________________________ test_pep338 _________________________________
    [gw0] win32 -- Python 3.9.17 %PREFIX%\python.exe
    
        @pytest.mark.skipif(IS_WASM, reason="Cannot start subprocess")
        def test_pep338():
    >       stdout = subprocess.check_output([sys.executable, '-mnumpy.f2py', '-v'])
    
    
    ..\_test_env\lib\site-packages\numpy\tests\test_scripts.py:46: 
    _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
    ..\_test_env\Lib\subprocess.py:424: in check_output
        return run(*popenargs, stdout=PIPE, timeout=timeout, check=True,
            kwargs     = {}
            popenargs  = (['D:\\bld\\numpy_1694041522631\\_test_env\\python.exe', '-mnumpy.f2py', '-v'],)
            timeout    = None
    _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
    
    input = None, capture_output = False, timeout = None, check = True
    popenargs = (['D:\\bld\\numpy_1694041522631\\_test_env\\python.exe', '-mnumpy.f2py', '-v'],)
    kwargs = {'stdout': -1}
    process = <Popen: returncode: 1 args: ['D:\\bld\\numpy_1694041522631\\_test_env\\pytho...>
    stdout = b'Traceback (most recent call last):\r\n  File "D:\\bld\\numpy_1694041522631\\_test_env\\Lib\\runpy.py", line 191, in ...3, in <module>\r\n    errmess = sys.stderr.write\r\nAttributeError: \'NoneType\' object has no attribute \'write\'\r\n'
    stderr = None, retcode = 1
    
        def run(*popenargs,
                input=None, capture_output=False, timeout=None, check=False, **kwargs):
            """Run command with arguments and return a CompletedProcess instance.
        
            The returned instance will have attributes args, returncode, stdout and
            stderr. By default, stdout and stderr are not captured, and those attributes
            will be None. Pass stdout=PIPE and/or stderr=PIPE in order to capture them.
        
            If check is True and the exit code was non-zero, it raises a
            CalledProcessError. The CalledProcessError object will have the return code
            in the returncode attribute, and output & stderr attributes if those streams
            were captured.
        
            If timeout is given, and the process takes too long, a TimeoutExpired
            exception will be raised.
        
            There is an optional argument "input", allowing you to
            pass bytes or a string to the subprocess's stdin.  If you use this argument
            you may not also use the Popen constructor's "stdin" argument, as
            it will be used internally.
        
            By default, all communication is in bytes, and therefore any "input" should
            be bytes, and the stdout and stderr will be bytes. If in text mode, any
            "input" should be a string, and stdout and stderr will be strings decoded
            according to locale encoding, or by "encoding" if set. Text mode is
            triggered by setting any of text, encoding, errors or universal_newlines.
        
            The other arguments are the same as for the Popen constructor.
            """
            if input is not None:
                if kwargs.get('stdin') is not None:
                    raise ValueError('stdin and input arguments may not both be used.')
                kwargs['stdin'] = PIPE
        
            if capture_output:
                if kwargs.get('stdout') is not None or kwargs.get('stderr') is not None:
                    raise ValueError('stdout and stderr arguments may not be used '
                                     'with capture_output.')
                kwargs['stdout'] = PIPE
                kwargs['stderr'] = PIPE
        
            with Popen(*popenargs, **kwargs) as process:
                try:
                    stdout, stderr = process.communicate(input, timeout=timeout)
                except TimeoutExpired as exc:
                    process.kill()
                    if _mswindows:
                        # Windows accumulates the output in a single blocking
                        # read() call run on child threads, with the timeout
                        # being done in a join() on those threads.  communicate()
                        # _after_ kill() is required to collect that and add it
                        # to the exception.
                        exc.stdout, exc.stderr = process.communicate()
                    else:
                        # POSIX _communicate already populated the output so
                        # far into the TimeoutExpired exception.
                        process.wait()
                    raise
                except:  # Including KeyboardInterrupt, communicate handled that.
                    process.kill()
                    # We don't call process.wait() as .__exit__ does that for us.
                    raise
                retcode = process.poll()
                if check and retcode:
    >               raise CalledProcessError(retcode, process.args,
                                             output=stdout, stderr=stderr)
    E               subprocess.CalledProcessError: Command '['D:\\bld\\numpy_1694041522631\\_test_env\\python.exe', '-mnumpy.f2py', '-v']' returned non-zero exit status 1.
    
    capture_output = False
    check      = True
    input      = None
    kwargs     = {'stdout': -1}
    popenargs  = (['D:\\bld\\numpy_1694041522631\\_test_env\\python.exe', '-mnumpy.f2py', '-v'],)
    process    = <Popen: returncode: 1 args: ['D:\\bld\\numpy_1694041522631\\_test_env\\pytho...>
    retcode    = 1
    stderr     = None
    stdout     = b'Traceback (most recent call last):\r\n  File "D:\\bld\\numpy_1694041522631\\_test_env\\Lib\\runpy.py", line 191, in ...3, in <module>\r\n    errmess = sys.stderr.write\r\nAttributeError: \'NoneType\' object has no attribute \'write\'\r\n'
    timeout    = None
    
    ..\_test_env\Lib\subprocess.py:528: CalledProcessError
    ============================== warnings summary ===============================
    
  2. charris commented on Sep 7, 2023

    @charris
    Member

    Which openblas version are you using?
    Which cython version are you using?
    Did you build using meson or distutils?

    The cholesky error is most likely due to blas.

    The only changes in numpy/random were changing the cython binding directive (#24606) and a slight annotation improvement. The wheels we built did not error.

  3. h-vetinari commented on Sep 7, 2023

    @h-vetinari
    ContributorAuthor

    Which openblas version are you using?
    Which cython version are you using?

    I put the details in the issue text (under Runtime information:); it's openblas 0.3.24 and Cython 3.0.2.

    Did you build using meson or distutils?

    Meson on all platforms.

    The cholesky error is most likely due to blas.

    Yeah, 0.3.24 came out not too long ago, I can retest with 0.3.23.

  4. mattip commented on Sep 7, 2023

    @mattip
    Member

    I think the previous 1.26.0b1 may have been using lapack-lite for nmpy.linalg by mistake instead of OpenBLAS

  5. h-vetinari commented on Sep 7, 2023

    @h-vetinari
    ContributorAuthor

    Can confirm that aarch passes with openblas 0.3.23.

    @martin-frbg, this looks like a regression in 0.3.24. Do you want me to open an issue for OpenBLAS or perhaps you have a possible culprit in mind already based on the error in the cholesky test?

  6. martin-frbg commented on Sep 7, 2023

    @martin-frbg

    Which flavor of aarch64 is this ? The only very recent change that made it into 0.3.24 was the ROTG rewrite to use the new "safe" scaling algorithm from the Reference BLAS, most everything else was specific to NeoverseV1.

  7. h-vetinari commented on Sep 7, 2023

    @h-vetinari
    ContributorAuthor

    Which flavor of aarch64 is this ?

    Since this is running in emulation through QEMU, I'm guessing it's the "most vanilla possible"? Numpy has some CPU feature detection on aarch as well, but doesn't find any CPU features (printed before the test suite run).

    NumPy version 1.26.0rc1
    NumPy relaxed strides checking option: True
    NumPy CPU features:  nothing enabled
    bringing up nodes...
    
  8. martin-frbg commented on Sep 7, 2023

    @martin-frbg

    That would be the ARMV8 target, no changes there and nothing on the obvious Cholesky codepath (potrf &friends)

  9. mattip commented on Sep 7, 2023

    @mattip
    Member

    I wonder what the difference is between this aarch64 test run and the one in the github action on the numpy/numpy repo

  10. charris commented on Sep 8, 2023

    @charris
    Member

    What pypy version?

  11. seiko2plus commented on Sep 8, 2023

    @seiko2plus
    Member

    Since this is running in emulation through QEMU, I'm guessing it's the "most vanilla possible"? Numpy has some CPU feature detection on aarch as well, but doesn't find any CPU features (printed before the test suite run).

    According to the build log:

    Test features "NEON" : Unsupported due to Implied feature "NEON_FP16" is not supported
    Test features "NEON_FP16" : Unsupported due to Implied feature "NEON_VFPV4" is not supported
    Test features "NEON_VFPV4" : Unsupported due to Compiler fails against the test code of "NEON_VFPV4"
    Test features "ASIMD" : Unsupported due to Implied feature "NEON" is not supported
    Test features "ASIMDHP" : Unsupported due to Implied feature "NEON" is not supported
    Test features "ASIMDFHM" : Unsupported due to Implied feature "NEON" is not supported
    Configuring npy_cpu_dispatch_config.h using configuration
    Message: 
    CPU Optimization Options
      baseline:
        Requested : min
        Enabled   : 
      dispatch:
        Requested : max -xop -fma4
        Enabled   : 

    The compile-time test for NEON_VFPV4 located at https://github.com/numpy/numpy/blob/main/numpy/distutils/checks/cpu_neon_vfpv4.c seems to have failed. Is there a way we can access the meson build log to pinpoint the problem? Perhaps by using something like cat build/meson-logs/meson-log.txt?

  12. h-vetinari commented on Sep 8, 2023

    @h-vetinari
    ContributorAuthor

    What pypy version?

    Also in the OP already: pypy 7.3.12 (for python 3.9, as numpy doesn't support 3.8 anymore, and conda-forge doesn't build pypy for 3.10 yet)

  13. h-vetinari commented on Sep 8, 2023

    @h-vetinari
    ContributorAuthor

    The compile-time test for NEON_VFPV4 located at https://github.com/numpy/numpy/blob/main/numpy/distutils/checks/cpu_neon_vfpv4.c seems to have failed.

    I think these are always going to fail because we're cross-compiling on aarch. It sounds conceptually similar to #24414, which where we have to set an explicit value for cross-compilation to pass for osx-arm.

  14. charris commented on Sep 8, 2023

    @charris
    Member

    Also in the OP

    The hash in the OP didn't agree with the latest pypy release, that is why I asked.

  15. 8 remaining items

  16. added a commit that references this issue on Sep 13, 2023
    a0c5ea2
  17. rgommers commented on Sep 13, 2023

    @rgommers
    Member

    gh-24698 should close the important part of this issue, which is the Linux aarch64 accuracy issues.

    The PyPy on Windows + memory allocator / Cython / f2py are all the same issue it looks like: sys.stdout not having an "encoding" attribute:

    AttributeError: 'NoneType' object has no attribute 'encoding
    

    I'm not sure why sys.stdout is weird under PyPy on Windows there, but it's a test issue only and shouldn't impact anything of interest. We have a PyPy on Windows CI job, but it's running the default (fast) test suite rather than the full test suite. @h-vetinari it should be fine to mark these as broken to get the conda-forge CI to pass I think. We may want to open a follow-up issue here, but it's too low-prio to look at now imho.

  18. added a commit that references this issue on Sep 13, 2023
    c9e72cd
  19. h-vetinari commented on Sep 13, 2023

    @h-vetinari
    ContributorAuthor

    and it should be fixed by the following patch:
    mesonbuild/meson@82d41db

    Thanks a lot @seiko2plus!

    Is this going to be upstreamed into meson? Because if I mark the openblas 0.3.24 builds unbroken again on aarch, this would also rebreak the CI on the scipy-feedstock (which, being built by meson, is probably affected by the same issue).

    In other words, we'd at least need to patch this into the meson-feedstock, but I'd prefer to do just a backport of an upstream PR, rather than original patches.

  20. h-vetinari commented on Sep 13, 2023

    @h-vetinari
    ContributorAuthor

    We may want to open a follow-up issue here, but it's too low-prio to look at now imho.

    Agreed, issues with pypy on windows would not have kept us from releasing (on the conda-forge side at least)

  21. rgommers commented on Sep 13, 2023

    @rgommers
    Member

    This bug is in code that is not present in Meson and not relevant for SciPy because it doesn't use NEON SIMD.

  22. h-vetinari commented on Sep 13, 2023

    @h-vetinari
    ContributorAuthor

    Interesting... That means we're still lacking an understanding of what's causing scipy/scipy#19210, and I cannot mark openblas 0.3.24 unbroken again.

    In any case, nothing that should be blocking 1.26

  23. seiko2plus commented on Sep 14, 2023

    @seiko2plus
    Member

    The issues seem to stem from the compiler optimization being disabled by setting the optimize level to 0. Upon inspecting the provided meson log, I noticed that -O0 is specified after both -O3 and -O2, which is unusual.

    Check the following command line:

    Command line: `$BUILD_PREFIX/bin/aarch64-conda-linux-gnu-cc -L$PREFIX/lib $SRC_DIR/builddir/meson-private/tmp3f10l7c1/testfile.c -o $SRC_DIR/builddir/meson-private/tmp3f10l7c1/output.exe -ftree-vectorize -fPIC -fstack-protector-strong -fno-plt \
    -O3 \ # optimization level 3
    -pipe -isystem $PREFIX/include -fdebug-prefix-map=$SRC_DIR=/usr/local/src/conda/numpy-1.26.0rc1 -fdebug-prefix-map=$PREFIX=/usr/local/src/conda-prefix -DNDEBUG -D_FORTIFY_SOURCE=2 \
    -O2 \ # optimization level 2 overrides the O3
    -isystem $PREFIX/include -D_FILE_OFFSET_BITS=64 \
    -O0 \ # And here the issue ? the compiler optimization is turned off?
    -std=c99 \ 
    -Wl,-O2 \ # passing O2 to linker? void it.
    -Wl,--sort-common -Wl,--as-needed -Wl,-z,relro -Wl,-z,now -Wl,--allow-shlib-undefined -Wl,-rpath,$PREFIX/lib -Wl,-rpath-link,$PREFIX/lib` -> 1
  24. seiko2plus commented on Sep 14, 2023

    @seiko2plus
    Member

    It seems that the Meson build reverses the order of the CFLAGS for somehow and this may explains why we don't observe this issue in the distutils build.

  25. rgommers commented on Sep 14, 2023

    @rgommers
    Member

    Conda manages to make things a little messy with a ton of build flags, but I think we can unravel this. We have the following components of the puzzle for a C target:

    1. The default_options in the top-level meson.build file: -std=c99 (other relevant flags there get overridden by meson-python, see (2):)
    2. The flags that meson-python adds when building a wheel: -Dbuildtype=release, -Db_ndebug=if_release`
    3. c_args set for a particular build target in the relevant meson.build file
    4. CFLAGS and LDFLAGS set in the environment (comes from compiler activation):
    $ echo $CFLAGS
    -ftree-vectorize -fPIC -fPIE -fstack-protector-strong -O2 -pipe -isystem /Users/rgommers/mambaforge/envs/numpy-dev/include
    $ echo $LDFLAGS
    -Wl,-pie -Wl,-headerpad_max_install_names -Wl,-dead_strip_dylibs -Wl,-rpath,/Users/rgommers/mambaforge/envs/numpy-dev/lib -L/Users/rgommers/mambaforge/envs/numpy-dev/lib
    

    It's unclear to me where -O0 comes from, or -Wl,-O2.

    To get the compile and link args for a target, you can use meson introspect build --targets -i > tmp.json. Example output in a numpy-dev conda env:

    Details
            "filename": [
                "/Users/rgommers/code/numpy/build/numpy/core/_operand_flag_tests.cpython-39-darwin.so"
            ],
            "build_by_default": true,
            "target_sources": [
                {
                    "language": "c",
                    "compiler": [
                        "arm64-apple-darwin20.0.0-clang"
                    ],
                    "parameters": [
                        "-I/Users/rgommers/code/numpy/build/numpy/core/_operand_flag_tests.cpython-39-darwin.so.p",
                        "-I/Users/rgommers/code/numpy/build/numpy/core",
                        "-I/Users/rgommers/code/numpy/numpy/core",
                        "-I/Users/rgommers/code/numpy/numpy/core/src/multiarray",
                        "-I/Users/rgommers/code/numpy/numpy/core/src/npymath",
                        "-I/Users/rgommers/code/numpy/build/numpy/core/include",
                        "-I/Users/rgommers/code/numpy/numpy/core/include",
                        "-I/Users/rgommers/code/numpy/numpy/core/src/common",
                        "-I/Users/rgommers/mambaforge/envs/numpy-dev/include/python3.9",
                        "-I/Users/rgommers/code/numpy/build/meson_cpu",
                        "-fvisibility=hidden",
                        "-fcolor-diagnostics",
                        "-Wall",
                        "-Winvalid-pch",
                        "-std=c99",
                        "-O2",
                        "-g",
                        "-fno-strict-aliasing",
                        "-ftrapping-math",
                        "-Wno-unsupported-floating-point-opt",
                        "-DNPY_HAVE_NEON_VFPV4",
                        "-DNPY_HAVE_NEON_FP16",
                        "-DNPY_HAVE_NEON",
                        "-DNPY_HAVE_ASIMD",
                        "-ftree-vectorize",
                        "-fPIC",
                        "-fPIE",
                        "-fstack-protector-strong",
                        "-O2",
                        "-pipe",
                        "-isystem",
                        "/Users/rgommers/mambaforge/envs/numpy-dev/include",
                        "-D_FORTIFY_SOURCE=2",
                        "-isystem",
                        "/Users/rgommers/mambaforge/envs/numpy-dev/include",
                        "-DNPY_INTERNAL_BUILD",
                        "-DHAVE_NPY_CONFIG_H",
                        "-D_FILE_OFFSET_BITS=64",
                        "-D_LARGEFILE_SOURCE=1",
                        "-D_LARGEFILE64_SOURCE=1"
                    ],
                    "sources": [
                        "/Users/rgommers/code/numpy/numpy/core/src/umath/_operand_flag_tests.c"
                    ],
                    "generated_sources": [],
                    "unity_sources": []
                },
                {
                    "linker": [
                        "arm64-apple-darwin20.0.0-clang"
                    ],
                    "parameters": [
                        "-L/Users/rgommers/mambaforge/envs/numpy-dev/lib",
                        "-Wl,-dead_strip_dylibs",
                        "-Wl,-headerpad_max_install_names",
                        "-Wl,-undefined,dynamic_lookup",
                        "-bundle",
                        "-Wl,-undefined,dynamic_lookup",
                        "-lm",
                        "-Wl,-pie",
                        "-Wl,-headerpad_max_install_names",
                        "-Wl,-dead_strip_dylibs",
                        "-Wl,-rpath,/Users/rgommers/mambaforge/envs/numpy-dev/lib",
                        "-ftree-vectorize",
                        "-fPIC",
                        "-fPIE",
                        "-fstack-protector-strong",
                        "-O2",
                        "-pipe",
                        "-isystem",
                        "/Users/rgommers/mambaforge/envs/numpy-dev/include",
                        "-D_FORTIFY_SOURCE=2",
                        "-isystem",
                        "/Users/rgommers/mambaforge/envs/numpy-dev/include"
                    ]
                }
            ],
    

    Comparing that to a non-SIMD compiler feature check and a SIMD feature check from meson-log.txt on macOS arm64:

    Details
    Called: `/Users/rgommers/mambaforge/envs/numpy-dev/bin/pkg-config --libs python-3.9` -> 0
    Run-time dependency python found: YES 3.9
    Running compile:
    Working directory:  /Users/rgommers/code/numpy/build/meson-private/tmphchev019
    Code:
    
            #ifdef __has_include
             #if !__has_include("Python.h")
              #error "Header 'Python.h' could not be found"
             #endif
            #else
             #include <Python.h>
            #endif
    -----------
    Command line: `arm64-apple-darwin20.0.0-clang -I/Users/rgommers/mambaforge/envs/numpy-dev/include/python3.9 /Users/rgommers/code/numpy/build/meson-private/tmphchev019/testfile.c -E -P -ftree-vectorize -fPIC -fPIE -fstack-protector-strong -O2 -pipe -isystem /Users/rgommers/mambaforge/envs/numpy-dev/include -D_FORTIFY_SOURCE=2 -isystem /Users/rgommers/mambaforge/envs/numpy-dev/include -P -O0 -Werror=implicit-function-declaration -std=c99` -> 0
    Has header "Python.h" with dependency python-3.9: YES
    Running compile:
    Working directory:  /Users/rgommers/code/numpy/build/meson-private/tmpycxx7zlx
    Code:
     extern int i;
    int i;
    
    Command line: `arm64-apple-darwin20.0.0-clang /Users/rgommers/code/numpy/build/meson-private/tmp1abedxjs/testfile.c -o /Users/rgommers/code/numpy/build/meson-private/tmp1abedxjs/output.obj -c -ftree-vectorize -fPIC -fPIE -fstack-protector-strong -O2 -pipe -isystem /Users/rgommers/mambaforge/envs/numpy-dev/include -D_FORTIFY_SOURCE=2 -isystem /Users/rgommers/mambaforge/envs/numpy-dev/include -O0 -Werror=implicit-function-declaration -Werror=unknown-warning-option -Werror=unused-command-line-argument -Werror=ignored-optimization-argument -march=armv8.2-a+fp16fml+fp16` -> 0
    Running compile:
    Working directory:  /var/folders/2m/dk_4hyc90xd2drkbqsbsjfqw0000gn/T/tmp7myl4wt3
    Code:
     #ifdef _MSC_VER
        #include <Intrin.h>
    #endif
    #include <arm_neon.h>
    
    int main(int argc, char **argv)
    {
        float16_t *src = (float16_t*)argv[argc-1];
        float *src2 = (float*)argv[argc-2];
        float16x8_t vhp  = vdupq_n_f16(src[0]);
        float16x4_t vlhp = vdup_n_f16(src[1]);
        float32x4_t vf   = vdupq_n_f32(src2[0]);
        float32x2_t vlf  = vdup_n_f32(src2[1]);
    
        int ret  = (int)vget_lane_f32(vfmlal_low_f16(vlf, vlhp, vlhp), 0);
            ret += (int)vgetq_lane_f32(vfmlslq_high_f16(vf, vhp, vhp), 0);
    
        return ret;
    }
    

    Those do both contain -O0, so I think it's coming from Meson's compiler feature check support. Which I guess makes sense for cc.has_header and the like. But not so much for SIMD checks perhaps.

  26. rgommers commented on Sep 14, 2023

    @rgommers
    Member

    @seiko2plus are those actual problems for feature detection? It's working fine in all CI and locally, with -O0 included.

  27. seiko2plus commented on Sep 14, 2023

    @seiko2plus
    Member

    Those do both contain -O0, so I think it's coming from Meson's compiler feature check support.

    Thanks for clarifying. I was under the impression -O0 was applied to all sources, as I couldn't access the ninja debug log via CI.

    are those actual problems for feature detection? It's working fine in all CI and locally, with -O0 included.

    The presence of -O0 isn't a problem for feature detection. In fact, it's beneficial to include -O0 to prevent the optimization of any instructions pertinent to the test, allowing for direct assessment against the assembler.

  28. rgommers commented on Sep 14, 2023

    @rgommers
    Member

    Great, thanks for confirming. Then I think we're all good here.

  29. added a commit that references this issue on Nov 11, 2023
    e35d385
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions