Repository: bradfordboyle/pyglpk (language: python)

Issue:
Installation issue on Debian trixie
On Debian testing I currently get the following errors.

i have `glpk-utils` and `libglpk-dev` installed 

for conda with python 3.12:
```
pip3 install glpk
Collecting glpk
  Using cached glpk-0.4.7.tar.gz (161 kB)
  Installing build dependencies ... done
  Getting requirements to build wheel ... done
  Preparing metadata (pyproject.toml) ... done
Building wheels for collected packages: glpk
  Building wheel for glpk (pyproject.toml) ... error
  error: subprocess-exited-with-error
  
  × Building wheel for glpk (pyproject.toml) did not run successfully.
  │ exit code: 1
  ╰─> [32 lines of output]
      WARNING setuptools_scm.pyproject_reading toml section missing 'pyproject.toml does not contain a tool.setuptools_scm section'
      Traceback (most recent call last):
        File "/tmp/pip-build-env-ac8lzp6j/overlay/lib/python3.12/site-packages/setuptools_scm/_integration/pyproject_reading.py", line 36, in read_pyproject
          section = defn.get("tool", {})[tool_name]
                    ~~~~~~~~~~~~~~~~~~~~^^^^^^^^^^^
      KeyError: 'setuptools_scm'
      running bdist_wheel
      running build
      running build_ext
      building 'glpk' extension
      creating build/temp.linux-x86_64-cpython-312/src
      gcc -pthread -B /home/maurer/.conda/envs/py312/compiler_compat -fno-strict-overflow -Wsign-compare -DNDEBUG -O2 -Wall -fPIC -O2 -isystem /home/maurer/.conda/envs/py312/include -fPIC -O2 -isystem /home/maurer/.conda/envs/py312/include -fPIC -DVERSION_NUMBER=\"0.4.7\" -I/home/maurer/.conda/envs/py312/include/python3.12 -c src/2to3.c -o build/temp.linux-x86_64-cpython-312/src/2to3.o
      gcc -pthread -B /home/maurer/.conda/envs/py312/compiler_compat -fno-strict-overflow -Wsign-compare -DNDEBUG -O2 -Wall -fPIC -O2 -isystem /home/maurer/.conda/envs/py312/include -fPIC -O2 -isystem /home/maurer/.conda/envs/py312/include -fPIC -DVERSION_NUMBER=\"0.4.7\" -I/home/maurer/.conda/envs/py312/include/python3.12 -c src/bar.c -o build/temp.linux-x86_64-cpython-312/src/bar.o
      src/bar.c: In function ‘Bar_setname’:
      src/bar.c:213:8: warning: assignment discards ‘const’ qualifier from pointer target type [-Wdiscarded-qualifiers]
        213 |   name = PyString_AsString(value);
            |        ^
      In file included from src/bar.c:20:
      src/2to3.h:13:26: error: implicit declaration of function ‘PyUnicode_GET_SIZE’; did you mean ‘PyDict_GET_SIZE’? [-Wimplicit-function-declaration]
         13 | #define PyString_Size(o) PyUnicode_GET_SIZE(o)
            |                          ^~~~~~~~~~~~~~~~~~
      src/bar.c:215:7: note: in expansion of macro ‘PyString_Size’
        215 |   if (PyString_Size(value) > 255) {
            |       ^~~~~~~~~~~~~
      src/bar.c: In function ‘Bar_setstatus’:
      src/2to3.h:18:27: warning: initialization discards ‘const’ qualifier from pointer target type [-Wdiscarded-qualifiers]
         18 | #define PyString_AsString PyUnicode_AsUTF8
            |                           ^~~~~~~~~~~~~~~~
      src/bar.c:381:16: note: in expansion of macro ‘PyString_AsString’
        381 |   char *sstr = PyString_AsString(value);
            |                ^~~~~~~~~~~~~~~~~
      error: command '/usr/bin/gcc' failed with exit code 1
      [end of output]
```

this is because of the deprecation of `PyUnicode_GET_SIZE` in 3.12.

There also is an error as there is no section of `setuptools_scm` in the pyproject.toml.


Discussion / hints:
Even on python3.11 I get errors:

```
Collecting glpk
  Using cached glpk-0.4.7.tar.gz (161 kB)
  Installing build dependencies ... done
  Getting requirements to build wheel ... done
  Preparing metadata (pyproject.toml) ... done
Building wheels for collected packages: glpk
  Building wheel for glpk (pyproject.toml) ... error
  error: subprocess-exited-with-error
  
  × Building wheel for glpk (pyproject.toml) did not run successfully.
  │ exit code: 1
  ╰─> [112 lines of output]
      WARNING setuptools_scm.pyproject_reading toml section missing 'pyproject.toml does not contain a tool.setuptools_scm section'
      Traceback (most recent call last):
        File "/tmp/pip-build-env-1414h00u/overlay/lib/python3.11/site-packages/setuptools_scm/_integration/pyproject_reading.py", line 36, in read_pyproject
          section = defn.get("tool", {})[tool_name]
                    ~~~~~~~~~~~~~~~~~~~~^^^^^^^^^^^
      KeyError: 'setuptools_scm'
      running bdist_wheel
      running build
      running build_ext
      building 'glpk' extension
      creating build/temp.linux-x86_64-cpython-311/src
      gcc -pthread -B /home/maurer/.conda/envs/assume11/compiler_compat -DNDEBUG -fwrapv -O2 -Wall -fPIC -O2 -isystem /home/maurer/.conda/envs/assume11/include -fPIC -O2 -isystem /home/maurer/.conda/envs/assume11/include -fPIC -DVERSION_NUMBER=\"0.4.7\" -I/home/maurer/.conda/envs/assume11/include/python3.11 -c src/2to3.c -o build/temp.linux-x86_64-cpython-311/src/2to3.o
      gcc -pthread -B /home/maurer/.conda/envs/assume11/compiler_compat -DNDEBUG -fwrapv -O2 -Wall -fPIC -O2 -isystem /home/maurer/.conda/envs/assume11/include -fPIC -O2 -isystem /home/maurer/.conda/envs/assume11/include -fPIC -DVERSION_NUMBER=\"0.4.7\" -I/home/maurer/.conda/envs/assume11/include/python3.11 -c src/bar.c -o build/temp.linux-x86_64-cpython-311/src/bar.o
      src/bar.c: In function ‘Bar_setname’:
      src/bar.c:213:8: warning: assignment discards ‘const’ qualifier from pointer target type [-Wdiscarded-qualifiers]
        213 |   name = PyString_AsString(value);
            |        ^
      src/bar.c:215:3: warning: ‘PyUnicode_GET_SIZE’ is deprecated [-Wdeprecated-declarations]
        215 |   if (PyString_Size(value) > 255) {
            |   ^~
      In file included from /home/maurer/.conda/envs/assume11/include/python3.11/unicodeobject.h:1042,
                       from /home/maurer/.conda/envs/assume11/include/python3.11/Python.h:51,
                       from src/2to3.h:1,
                       from src/bar.c:20:
      /home/maurer/.conda/envs/assume11/include/python3.11/cpython/unicodeobject.h:652:26: note: declared here
        652 | static inline Py_ssize_t PyUnicode_GET_SIZE(PyObject *op)
            |                          ^~~~~~~~~~~~~~~~~~
      src/bar.c: In function ‘Bar_setstatus’:
      src/2to3.h:18:27: warning: initialization discards ‘const’ qualifier from pointer target type [-Wdiscarded-qualifiers]
         18 | #define PyString_AsString PyUnicode_AsUTF8
            |                           ^~~~~~~~~~~~~~~~
      src/bar.c:381:16: note: in expansion of macro ‘PyString_AsString’
        381 |   char *sstr = PyString_AsString(value);
            |                ^~~~~~~~~~~~~~~~~
      gcc -pthread -B /home/maurer/.conda/envs/assume11/compiler_compat -DNDEBUG -fwrapv -O2 -Wall -fPIC -O2 -isystem /home/maurer/.conda/envs/assume11/include -fPIC -O2 -isystem /home/maurer/.conda/envs/assume11/include -fPIC -DVERSION_NUMBER=\"0.4.7\" -I/home/maurer/.conda/envs/assume11/include/python3.11 -c src/barcol.c -o build/temp.linux-x86_64-cpython-311/src/barcol.o
      In file included from src/barcol.c:20:
      src/barcol.c: In function ‘BarCol_Index’:
      src/2to3.h:18:27: warning: initialization discards ‘const’ qualifier from pointer target type [-Wdiscarded-qualifiers]
         18 | #define PyString_AsString PyUnicode_AsUTF8
            |                           ^~~~~~~~~~~~~~~~
      src/barcol.c:212:18: note: in expansion of macro ‘PyString_AsString’
        212 |     char *name = PyString_AsString(obj);
            |                  ^~~~~~~~~~~~~~~~~
      src/barcol.c: In function ‘BarCol_ass_subscript’:
      src/barcol.c:385:39: warning: reading 4 bytes from a region of size 0 [-Wstringop-overread]
        385 |     (BarCol_Rows(self) ? glp_del_rows : glp_del_cols)
            |     ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~
        386 |       (LP, numtodel, indtodel-1);
            |       ~~~~~~~~~~~~~~~~~~~~~~~~~~
      src/barcol.c:385:39: note: referencing argument 3 of type ‘const int[0]’
      src/barcol.c:385:39: note: in a call with type ‘void(glp_prob *, int,  const int *)’
      gcc -pthread -B /home/maurer/.conda/envs/assume11/compiler_compat -DNDEBUG -fwrapv -O2 -Wall -fPIC -O2 -isystem /home/maurer/.conda/envs/assume11/include -fPIC -O2 -isystem /home/maurer/.conda/envs/assume11/include -fPIC -DVERSION_NUMBER=\"0.4.7\" -I/home/maurer/.conda/envs/assume11/include/python3.11 -c src/environment.c -o build/temp.linux-x86_64-cpython-311/src/environment.o
      gcc -pthread -B /home/maurer/.conda/envs/assume11/compiler_compat -DNDEBUG -fwrapv -O2 -Wall -fPIC -O2 -isystem /home/maurer/.conda/envs/assume11/include -fPIC -O2 -isystem /home/maurer/.conda/envs/assume11/include -fPIC -DVERSION_NUMBER=\"0.4.7\" -I/home/maurer/.conda/envs/assume11/include/python3.11 -c src/glpk.c -o build/temp.linux-x86_64-cpython-311/src/glpk.o
      gcc -pthread -B /home/maurer/.conda/envs/assume11/compiler_compat -DNDEBUG -fwrapv -O2 -Wall -fPIC -O2 -isystem /home/maurer/.conda/envs/assume11/include -fPIC -O2 -isystem /home/maurer/.conda/envs/assume11/include -fPIC -DVERSION_NUMBER=\"0.4.7\" -I/home/maurer/.conda/envs/assume11/include/python3.11 -c src/kkt.c -o build/temp.linux-x86_64-cpython-311/src/kkt.o
      gcc -pthread -B /home/maurer/.conda/envs/assume11/compiler_compat -DNDEBUG -fwrapv -O2 -Wall -fPIC -O2 -isystem /home/maurer/.conda/envs/assume11/include -fPIC -O2 -isystem /home/maurer/.conda/envs/assume11/include -fPIC -DVERSION_NUMBER=\"0.4.7\" -I/home/maurer/.conda/envs/assume11/include/python3.11 -c src/lp.c -o build/temp.linux-x86_64-cpython-311/src/lp.o
      src/lp.c: In function ‘LPX_init’:
      src/lp.c:137:26: warning: assignment discards ‘const’ qualifier from pointer target type [-Wdiscarded-qualifiers]
        137 |                 model[0] = PyString_AsString(model_obj);
            |                          ^
      src/lp.c:152:34: warning: assignment discards ‘const’ qualifier from pointer target type [-Wdiscarded-qualifiers]
        152 |                         model[i] = PyString_AsString(so);
            |                                  ^
      src/lp.c: In function ‘LPX_Copy’:
      src/lp.c:312:16: error: returning ‘LPXObject *’ from a function with incompatible return type ‘PyObject *’ {aka ‘struct _object *’} [-Wincompatible-pointer-types]
        312 |         return LPX_FromLP(dest);
            |                ^~~~~~~~~~~~~~~~
      src/lp.c: In function ‘LPX_transform_row’:
      src/lp.c:832:21: warning: variable ‘m’ set but not used [-Wunused-but-set-variable]
        832 |         int k, len, m, n;
            |                     ^
      src/lp.c:832:13: warning: unused variable ‘k’ [-Wunused-variable]
        832 |         int k, len, m, n;
            |             ^
      src/lp.c: In function ‘LPX_transform_col’:
      src/lp.c:878:27: warning: variable ‘n’ set but not used [-Wunused-but-set-variable]
        878 |         int k, len, i, m, n;
            |                           ^
      src/lp.c:878:21: warning: unused variable ‘i’ [-Wunused-variable]
        878 |         int k, len, i, m, n;
            |                     ^
      src/lp.c:878:13: warning: unused variable ‘k’ [-Wunused-variable]
        878 |         int k, len, i, m, n;
            |             ^
      src/lp.c: In function ‘LPX_setname’:
      src/lp.c:1111:14: warning: assignment discards ‘const’ qualifier from pointer target type [-Wdiscarded-qualifiers]
       1111 |         name = PyString_AsString(value);
            |              ^
      src/lp.c:1114:9: warning: ‘PyUnicode_GET_SIZE’ is deprecated [-Wdeprecated-declarations]
       1114 |         if (PyString_Size(value) > 255) {
            |         ^~
      In file included from /home/maurer/.conda/envs/assume11/include/python3.11/unicodeobject.h:1042,
                       from /home/maurer/.conda/envs/assume11/include/python3.11/Python.h:51,
                       from src/lp.c:20:
      /home/maurer/.conda/envs/assume11/include/python3.11/cpython/unicodeobject.h:652:26: note: declared here
        652 | static inline Py_ssize_t PyUnicode_GET_SIZE(PyObject *op)
            |                          ^~~~~~~~~~~~~~~~~~
      src/lp.c: In function ‘LPX_getstatus’:
      src/lp.c:1167:9: warning: case label value is less than minimum value for type [-Wswitch-outside-range]
       1167 |         case -1:
            |         ^~~~
      In file included from /home/maurer/.conda/envs/assume11/include/python3.11/Python.h:39:
      src/lp.c: At top level:
      src/lp.c:1329:14: warning: ‘params_doc’ defined but not used [-Wunused-const-variable=]
       1329 | PyDoc_STRVAR(params_doc,
            |              ^~~~~~~~~~
      /home/maurer/.conda/envs/assume11/include/python3.11/pymacro.h:92:43: note: in definition of macro ‘PyDoc_VAR’
         92 | #define PyDoc_VAR(name) static const char name[]
            |                                           ^~~~
      src/lp.c:1329:1: note: in expansion of macro ‘PyDoc_STRVAR’
       1329 | PyDoc_STRVAR(params_doc,
            | ^~~~~~~~~~~~
      error: command '/usr/bin/gcc' failed with exit code 1
      [end of output]
```

this is due to `error: returning ‘LPXObject *’ from a function with incompatible return type ‘PyObject *’ {aka ‘struct _object *’} [-Wincompatible-pointer-types]` while I don't really know why this happens.

I also get errors in a python3.12 venv while it somehow works on my debian 12 bookworm laptop..

This surely has to do with `python3-dev` which now points to python3.12-dev and is therefore incompatible.

Fix patch:
diff --git a/pyproject.toml b/pyproject.toml
index 89786a4..1184406 100644
--- a/pyproject.toml
+++ b/pyproject.toml
@@ -1,2 +1,4 @@
 [build-system]
-requires = ["setuptools>=30.3.0", "wheel", "setuptools_scm"]
\ No newline at end of file
+requires = ["setuptools>=30.3.0", "wheel", "setuptools_scm"]
+
+[tool.setuptools_scm]
diff --git a/src/2to3.h b/src/2to3.h
index e6cdbdf..6f1e80c 100644
--- a/src/2to3.h
+++ b/src/2to3.h
@@ -10,15 +10,16 @@
 #define PyInt_FromSize_t(v) PyLong_FromSize_t(v)
 
 #define PyString_FromString(v) PyUnicode_FromString(v)
-#define PyString_Size(o) PyUnicode_GET_SIZE(o)
 #define PyString_FromFormat(fmt, ...) PyUnicode_FromFormat(fmt, __VA_ARGS__)
 #define PyString_Check(o) PyUnicode_Check(o)
 
 #if PY_MINOR_VERSION >= 3
-#define PyString_AsString PyUnicode_AsUTF8
+#define PyString_AsString(o) PyUnicode_AsUTF8(o)
+#define PyString_Size(o) PyUnicode_GetLength(o)
 #else
 const char* PyUnicode_AsUTF8_PriorToPy33(PyObject* unicode);
 #define PyString_AsString(o) PyUnicode_AsUTF8_PriorToPy33(o)
+#define PyString_Size(o) PyUnicode_GET_SIZE(o)
 #endif
 
 #endif
diff --git a/src/lp.c b/src/lp.c
index f56cc95..2825d6f 100644
--- a/src/lp.c
+++ b/src/lp.c
@@ -309,7 +309,7 @@ static PyObject* LPX_Copy(LPXObject *self, PyObject *args)
 	glp_prob *dest = glp_create_prob();
 	glp_copy_prob(dest, LP, names);
 
-	return LPX_FromLP(dest);
+	return (PyObject *) LPX_FromLP(dest);
 }
 
 static PyObject* LPX_Scale(LPXObject *self, PyObject*args)


Test patch:
diff --git a/tests/memory_test.py b/tests/memory_test.py
index b8a47d3..f602e46 100644
--- a/tests/memory_test.py
+++ b/tests/memory_test.py
@@ -21,7 +21,7 @@ class GarbageCollectionTestCase(unittest.TestCase):
     reference list are currently invalid."""
     def __init__(self, name=''):
         unittest.TestCase.__init__(self, name)
-        oldfunc = getattr(self, name)
+        oldfunc = getattr(self, name, "default")
 
         class tuplesubclass(list):
             pass