From 86e9f03c3195ad9a7b9c0fbb3c78f0f388586cb1 Mon Sep 17 00:00:00 2001 From: Tim Burke Date: Wed, 6 Apr 2022 09:45:42 -0700 Subject: Restrict ourselves to Python's Stable ABI This allows us to build shared libraries that work across minor CPython releases. See also: https://docs.python.org/3/c-api/stable.html To build abi3 wheels, run something like python setup.py bdist_wheel --py-limited-api=cp35 Change-Id: Iaa747d58c6ac9dd64c5e4d3b5fdd4e56e8e2cb5e --- setup.py | 1 + src/c/pyeclib_c/pyeclib_c.c | 13 +++++++------ 2 files changed, 8 insertions(+), 6 deletions(-) diff --git a/setup.py b/setup.py index 6eef16a..c8f03a2 100644 --- a/setup.py +++ b/setup.py @@ -209,6 +209,7 @@ class install(_install): module = Extension('pyeclib_c', + py_limited_api=True, define_macros=[('MAJOR VERSION', '1'), ('MINOR VERSION', '6')], include_dirs=[default_python_incdir, diff --git a/src/c/pyeclib_c/pyeclib_c.c b/src/c/pyeclib_c/pyeclib_c.c index 3184b34..407b6b5 100644 --- a/src/c/pyeclib_c/pyeclib_c.c +++ b/src/c/pyeclib_c/pyeclib_c.c @@ -27,6 +27,7 @@ #include #include #define PY_SSIZE_T_CLEAN +#define Py_LIMITED_API 0x03050000 #include #include #include @@ -488,7 +489,7 @@ static PyObject * pyeclib_c_encode(PyObject *self, PyObject *args) { PyObject *pyeclib_obj_handle = NULL; - pyeclib_t *pyeclib_handle= NULL; + pyeclib_t *pyeclib_handle = NULL; char **encoded_data = NULL; /* array of k data buffers */ char **encoded_parity = NULL; /* array of m parity buffers */ PyObject *list_of_strips = NULL; /* list of encoded strips to return */ @@ -512,25 +513,25 @@ pyeclib_c_encode(PyObject *self, PyObject *args) ret = liberasurecode_encode(pyeclib_handle->ec_desc, data, data_len, &encoded_data, &encoded_parity, &fragment_len); if (ret < 0) { pyeclib_c_seterr(ret, "pyeclib_c_encode"); - return NULL; + return NULL; } /* Create the python list of fragments to return */ list_of_strips = PyList_New(pyeclib_handle->ec_args.k + pyeclib_handle->ec_args.m); if (NULL == list_of_strips) { pyeclib_c_seterr(-ENOMEM, "pyeclib_c_encode"); - return NULL; + return NULL; } /* Add data fragments to the python list to return */ for (i = 0; i < pyeclib_handle->ec_args.k; i++) { - PyList_SET_ITEM(list_of_strips, i, + PyList_SetItem(list_of_strips, i, PY_BUILDVALUE_OBJ_LEN(encoded_data[i], fragment_len)); } /* Add parity fragments to the python list to return */ for (i = 0; i < pyeclib_handle->ec_args.m; i++) { - PyList_SET_ITEM(list_of_strips, pyeclib_handle->ec_args.k + i, + PyList_SetItem(list_of_strips, pyeclib_handle->ec_args.k + i, PY_BUILDVALUE_OBJ_LEN(encoded_parity[i], fragment_len)); } @@ -886,7 +887,7 @@ pyeclib_c_decode(PyObject *self, PyObject *args) pyeclib_c_seterr(-EINVALIDPARAMS, "pyeclib_c_decode invalid range"); goto error; } - PyList_SET_ITEM(ret_payload, i, + PyList_SetItem(ret_payload, i, PY_BUILDVALUE_OBJ_LEN(c_orig_payload + c_ranges[i].offset, c_ranges[i].length)); } } -- cgit v1.2.1