Py_INFINITY didn't appear to be available in 3.11, and now it's "soft
deprecated", so just define a static pos_inf and neg_inf during module
initialization via math.inf.
Signed-off-by: Rob Browning <
r...@defaultvalue.org>
Tested-by: Rob Browning <
r...@defaultvalue.org>
---
Pushed to main.
lib/bup/_helpers.c | 21 +++++++++++++++++++++
1 file changed, 21 insertions(+)
diff --git a/lib/bup/_helpers.c b/lib/bup/_helpers.c
index 27941e76..b0a31be3 100644
--- a/lib/bup/_helpers.c
+++ b/lib/bup/_helpers.c
@@ -1774,6 +1774,9 @@ static PyObject *bup_limited_vint_pack(PyObject *self, PyObject *args)
return NULL;
}
+static PyObject *pos_inf;
+static PyObject *neg_inf;
+
static PyObject *
bup_strtoimax(PyObject *self, PyObject *args)
{
@@ -1958,6 +1961,24 @@ static int setup_module(PyObject *m)
Py_DECREF(value);
}
+ {
+ PyObject *math = PyImport_ImportModule("math");
+ if (!math) {
+ fprintf(stderr, "unable to find math module.\n");
+ exit(BUP_EXIT_FAILURE);
+ }
+ pos_inf = PyObject_GetAttrString(math, "inf");
+ Py_DECREF(math);
+ if (!pos_inf) {
+ fprintf(stderr, "unable to find math.inf.\n");
+ exit(BUP_EXIT_FAILURE);
+ }
+ if ((neg_inf = PyNumber_Negative(pos_inf)) == NULL) {
+ fprintf(stderr, "unable to define negative infinity.\n");
+ exit(BUP_EXIT_FAILURE);
+ }
+ }
+
#ifdef BUP_HAVE_MINCORE_INCORE
{
PyObject *value;
--
2.47.3