Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make use of CPython limited API #94

Merged
merged 10 commits into from
Sep 25, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
37 changes: 8 additions & 29 deletions .github/workflows/ci_workflows.yml
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ jobs:
python -m venv --system-site-packages tests
source tests/bin/activate
python -m pip install --editable .[test]
(nm -u erfa/ufunc.cpython-*.so | grep eraA2af) || exit 1
(nm -u erfa/ufunc.*.so | grep eraA2af) || exit 1
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The so files are now called ufunc.abi3.so hence the change

(python -c 'import erfa' 2>&1 | grep -n 'too old') > /dev/null && (echo 'liberfa too old, skipping tests'; exit 0) || python -m pytest


Expand All @@ -126,37 +126,16 @@ jobs:
test_command: pytest --pyargs erfa
targets: |
# Linux wheels
- cp39-manylinux_x86_64
- cp310-manylinux_x86_64
- cp311-manylinux_x86_64
- cp312-manylinux_x86_64
- cp39-musllinux_x86_64
- cp310-musllinux_x86_64
- cp311-musllinux_x86_64
- cp312-musllinux_x86_64
- cp39-manylinux_aarch64
- cp310-manylinux_aarch64
- cp311-manylinux_aarch64
- cp312-manylinux_aarch64
- cp3*-manylinux_x86_64
- cp3*-musllinux_x86_64
- cp3*-manylinux_aarch64
# MacOS X wheels - we deliberately do not build universal2 wheels.
# Note that the arm64 wheels are not actually tested so we
# rely on local manual testing of these to make sure they are ok.
- cp39*macosx_x86_64
- cp310*macosx_x86_64
- cp311*macosx_x86_64
- cp312*macosx_x86_64
- cp39*macosx_arm64
- cp310*macosx_arm64
- cp311*macosx_arm64
- cp312*macosx_arm64
- cp3*macosx_x86_64
- cp3*macosx_arm64
# Windows wheels
- cp39*win32
- cp310*win32
- cp311*win32
- cp312*win32
- cp39*win_amd64
- cp310*win_amd64
- cp311*win_amd64
- cp312*win_amd64
- cp3*win32
- cp3*win_amd64
secrets:
pypi_token: ${{ secrets.pypi_token }}
16 changes: 15 additions & 1 deletion erfa/ufunc.c.templ
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,24 @@
*/

#define NPY_NO_DEPRECATED_API NPY_1_7_API_VERSION
#define Py_LIMITED_API 0x030900f0
#include "Python.h"
#include "numpy/arrayobject.h"
#include "numpy/ufuncobject.h"
#include "erfa.h"
#include "erfaextra.h"

// On gcc<10 we can run into the following:
//
// error: dereferencing pointer to incomplete type 'PyTypeObject'
//
// As mentioned in https://github.com/numpy/numpy/issues/16970,
// the workaround is to define a fake _typeobject struct.

struct _typeobject {
int dummy;
mhvk marked this conversation as resolved.
Show resolved Hide resolved
};

#define MODULE_DOCSTRING \
"Ufunc wrappers of the ERFA routines.\n\n" \
"These ufuncs vectorize the ERFA functions assuming structured dtypes\n" \
Expand Down Expand Up @@ -207,7 +219,9 @@ static void ufunc_loop_{{ func.pyname }}(
{#- /* if needed, allocate memory for contiguous eraLDBODY copies */ #}
{%- if func.user_dtype == 'dt_eraLDBODY' %}
if (copy_b) {
_b = PyArray_malloc(nb * sizeof(eraLDBODY));
// Note that we can't use PyArray_malloc here as it is an alias to PyMem_RawMalloc
// which is not available in the Python limited API
_b = malloc(nb * sizeof(eraLDBODY));
mhvk marked this conversation as resolved.
Show resolved Hide resolved
if (_b == NULL) {
PyErr_NoMemory();
return;
Expand Down
3 changes: 3 additions & 0 deletions setup.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -56,3 +56,6 @@ max-line-length = 100

[pycodestyle]
max-line-length = 100

[bdist_wheel]
py_limited_api = cp39
1 change: 1 addition & 0 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,7 @@ def get_extensions():
include_dirs=include_dirs,
libraries=libraries,
define_macros=define_macros,
py_limited_api=True,
language="c")

return [erfa_ext]
Expand Down
Loading