Skip to content

Commit

Permalink
Fix build on macOS 12
Browse files Browse the repository at this point in the history
Building on macOS 12 fails with the following error

> implicit declaration of function 'unzip' is invalid in C99

Since unzip is only used in lp.c, this commit moves the function from
util.c to lp.c, makes the function static, and adds an explicit function
declaration.
  • Loading branch information
bradfordboyle committed Feb 19, 2023
1 parent a3c83c3 commit 5183955
Show file tree
Hide file tree
Showing 4 changed files with 60 additions and 45 deletions.
25 changes: 19 additions & 6 deletions .github/workflows/test.yml
Expand Up @@ -11,7 +11,7 @@ jobs:
runs-on: ${{ matrix.os }}
strategy:
matrix:
os: [ubuntu-22.04, ubuntu-20.04]
os: [macos-12, ubuntu-22.04, ubuntu-20.04]
glpk: ['4.65', '5.0']
python-version: ['3.8', '3.9', '3.10', '3.11']

Expand All @@ -29,15 +29,28 @@ jobs:
./configure
make -j $(nproc)
sudo make install
sudo ldconfig
[[ $(uname) == Darwin ]] || sudo ldconfig
popd
- name: install dependencies
- name: install lcov
run: |
pip install setuptools_scm tox
sudo apt-get update -q=1 -y
sudo apt-get install -q=1 -y lcov
platform="$(uname)"
case "${platform}" in
Darwin)
brew update -q
HOMEBREW_NO_INSTALL_CLEANUP=true brew install -q lcov
;;
Linux)
sudo apt-get update -q=1 -y
sudo apt-get install -q=1 -y lcov
;;
*)
echo >&2 "Unknown platform '${platform}'; supported platforms are 'Darwin' and 'Linux'"
exit 1
;;
esac
- name: run tox
run: |
pip install setuptools_scm tox
tox -e py
mkdir coverage
lcov --capture --directory . --output-file ./coverage/lcov.info
Expand Down
40 changes: 40 additions & 0 deletions src/lp.c
Expand Up @@ -36,6 +36,7 @@ along with PyGLPK. If not, see <http://www.gnu.org/licenses/>.
#define LP (self->lp)

static PyObject* glpstatus2string(int);
static int unzip(PyObject *, const int, BarObject *[], double []);

static int LPX_traverse(LPXObject *self, visitproc visit, void *arg)
{
Expand Down Expand Up @@ -1215,6 +1216,45 @@ static PyObject* LPX_getnumbin(LPXObject *self, void *closure)
return PyInt_FromLong(glp_get_num_bin(LP));
}

static int unzip(PyObject *iterator, const int len, BarObject *bars[], double val[]) {
if (!PyIter_Check(iterator)) {
PyErr_SetString(PyExc_TypeError, "object not iterable");
return -1;
}

PyObject *item;
int index = 0;
while ((item = PyIter_Next(iterator)) && (index < len)) {
if (!PyTuple_Check(item) || PyTuple_Size(item) != 2) {
PyErr_SetString(PyExc_TypeError, "item must be two element tuple");
Py_DECREF(item);
return -1;
}

PyObject *bo, *vo;
if ((bo = PyTuple_GetItem(item, 0)) == NULL || (vo = PyTuple_GetItem(item, 1)) == NULL) {
PyErr_SetString(PyExc_RuntimeError, "unable to unpack tuple");
Py_DECREF(item);
return -1;
}

if (!PyObject_TypeCheck(bo, &BarType) || !PyFloat_Check(vo)) {
PyErr_SetString(PyExc_TypeError, "tuple must contain glpk.Bar and double");
Py_DECREF(item);
return -1;
}

index += 1;

bars[index] = (BarObject *) bo;
val[index] = PyFloat_AsDouble(vo);

Py_DECREF(item);
}

return index;
}

/****************** OBJECT DEFINITION *********/

int LPX_InitType(PyObject *module)
Expand Down
38 changes: 0 additions & 38 deletions src/util.c
Expand Up @@ -289,41 +289,3 @@ int PyDict_SetIntString(PyObject *p, const char *key, int val) {
Py_DECREF(i);
return retval;
}

int unzip(PyObject *iterator, const int len, BarObject *bars[], double val[]) {
if (!PyIter_Check(iterator)) {
PyErr_SetString(PyExc_TypeError, "object not iterable");
return -1;
}

PyObject *item;
int index = 0;
while ((item = PyIter_Next(iterator)) && (index < len)) {
if (!PyTuple_Check(item) || PyTuple_Size(item) != 2) {
PyErr_SetString(PyExc_TypeError, "item must be two element tuple");
Py_DECREF(item);
return -1;
}

PyObject *bo, *vo;
if ((bo = PyTuple_GetItem(item, 0)) == NULL || (vo = PyTuple_GetItem(item, 1)) == NULL) {
PyErr_SetString(PyExc_RuntimeError, "unable to unpack tuple");
Py_DECREF(item);
return -1;
}

if (!PyObject_TypeCheck(bo, &BarType) || !PyFloat_Check(vo)) {
PyErr_SetString(PyExc_TypeError, "tuple must contain glpk.Bar and double");
Py_DECREF(item);
return -1;
}

index += 1;
bars[index] = (BarObject *) bo;
val[index] = PyFloat_AsDouble(vo);

Py_DECREF(item);
}

return index;
}
2 changes: 1 addition & 1 deletion tox.ini
Expand Up @@ -10,5 +10,5 @@ skip_install = true
setenv =
CFLAGS=-coverage
commands =
{envpython} setup.py clean --all install
{envpython} -m pip install .
pytest

0 comments on commit 5183955

Please sign in to comment.