Skip to content

Platform-dependent issue with compiling against version 3.11 of Limited API #18248

Closed

Description

@neutrinoceros

I've hit a couple compilation errors in stats when targetting a abi3-311 build, which appear to be defects in numpy's C API

astropy/stats/src/fast_sigma_clip.c:109:29: error: call to undeclared function 'PyMem_RawMalloc'; ISO C99 and later do not support implicit function declarations [-Wimplicit-function-declaration]
  109 |     data_buffer = (double *)PyArray_malloc(n_i * sizeof(double));
      |                             ^
/Users/clm/.cache/uv/builds-v0/.tmpBdRAcn/lib/python3.11/site-packages/numpy/_core/include/numpy/ndarraytypes.h:368:24: note: expanded from macro 'PyArray_malloc'
  368 | #define PyArray_malloc PyMem_RawMalloc
      |                        ^
astropy/stats/src/fast_sigma_clip.c:109:19: warning: cast to 'double *' from smaller integer type 'int' [-Wint-to-pointer-cast]
  109 |     data_buffer = (double *)PyArray_malloc(n_i * sizeof(double));
      |                   ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
astropy/stats/src/fast_sigma_clip.c:138:30: warning: cast to 'double *' from smaller integer type 'int' [-Wint-to-pointer-cast]
  138 |                 mad_buffer = (double *)PyArray_malloc(n_i * sizeof(double));
      |                              ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
astropy/stats/src/fast_sigma_clip.c:157:5: error: call to undeclared function 'PyMem_RawFree'; ISO C99 and later do not support implicit function declarations [-Wimplicit-function-declaration]
  157 |     PyArray_free((void *)data_buffer);
      |     ^
/Users/clm/.cache/uv/builds-v0/.tmpBdRAcn/lib/python3.11/site-packages/numpy/_core/include/numpy/ndarraytypes.h:369:22: note: expanded from macro 'PyArray_free'
  369 | #define PyArray_free PyMem_RawFree
      |                      ^
astropy/stats/src/fast_sigma_clip.c:157:5: note: did you mean 'PyMem_Free'?
/Users/clm/.cache/uv/builds-v0/.tmpBdRAcn/lib/python3.11/site-packages/numpy/_core/include/numpy/ndarraytypes.h:369:22: note: expanded from macro 'PyArray_free'
  369 | #define PyArray_free PyMem_RawFree
      |                      ^
/Users/clm/.local/share/uv/python/cpython-3.11.13-macos-aarch64-none/include/python3.11/pymem.h:55:18: note: 'PyMem_Free' declared here
   55 | PyAPI_FUNC(void) PyMem_Free(void *ptr);
      |                  ^
2 warnings and 2 errors generated.
error: command '/usr/bin/cc' failed with exit code 1

To summarize, PyArray_malloc and PyArray_free are aliased to Python's C-API PyMem_RawMalloc and PyMem_RawFree respectively, which were not part of Limited API until version 3.13, so they appear as undefined.
I'm surprised that this isn't showing up in the test job introduced in #18236, any idea why that is @astrofrog ?
I want to report/fix this upstream later, though for now I'll continue making progress on astropy itself by targeting abi-cp313 instead.

Activity

  1. astrofrog commented on Jun 10, 2025

    @astrofrog
    Member

    What platform are you using? I noticed that some limited API issues appear only with certain compilers, which might explain why they didn't appear in the CI. I will investigate a bit later on the CI side.

  2. neutrinoceros commented on Jun 10, 2025

    @neutrinoceros
    ContributorAuthor

    I got this error on Apple Silicon, presumably my auto-selected compiler should be clang

  3. neutrinoceros commented on Jun 10, 2025

    @neutrinoceros
    ContributorAuthor

    Actually these problems do get reported too on Linux (gcc), but there they're just warnings instead of errors

    /tmp/build-env-_saoug4w/lib/python3.11/site-packages/numpy/_core/include/numpy/ndarraytypes.h:368:24: warning: implicit declaration of function ‘PyMem_RawMalloc’; did you mean ‘PyMem_Realloc’? [-Wimplicit-function-declaration]
      368 | #define PyArray_malloc PyMem_RawMalloc
          |                        ^~~~~~~~~~~~~~~
    astropy/stats/src/fast_sigma_clip.c:109:29: note: in expansion of macro ‘PyArray_malloc’
      109 |     data_buffer = (double *)PyArray_malloc(n_i * sizeof(double));
          |                             ^~~~~~~~~~~~~~
    astropy/stats/src/fast_sigma_clip.c:109:19: warning: cast to pointer from integer of different size [-Wint-to-pointer-cast]
      109 |     data_buffer = (double *)PyArray_malloc(n_i * sizeof(double));
          |                   ^
    astropy/stats/src/fast_sigma_clip.c:138:30: warning: cast to pointer from integer of different size [-Wint-to-pointer-cast]
      138 |                 mad_buffer = (double *)PyArray_malloc(n_i * sizeof(double));
          |                              ^
    /tmp/build-env-_saoug4w/lib/python3.11/site-packages/numpy/_core/include/numpy/ndarraytypes.h:369:22: warning: implicit declaration of function ‘PyMem_RawFree’; did you mean ‘PyMem_Free’? [-Wimplicit-function-declaration]
      369 | #define PyArray_free PyMem_RawFree
          |                      ^~~~~~~~~~~~~
    astropy/stats/src/fast_sigma_clip.c:157:5: note: in expansion of macro ‘PyArray_free’
      157 |     PyArray_free((void *)data_buffer);
          |     ^~~~~~~~~~~~
    
  4. astrofrog commented on Jun 10, 2025

    @astrofrog
    Member

    These are fixed and properly tested in #18250

  5. changed the title [-]Upstream issue with compiling against version 3.11 of Limited API[/-] [+]Plateform-dependent issue with compiling against version 3.11 of Limited API[/+] on Jun 10, 2025
  6. changed the title [-]Plateform-dependent issue with compiling against version 3.11 of Limited API[/-] [+]Platform-dependent issue with compiling against version 3.11 of Limited API[/+] on Jun 11, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions