crash and burn during "pkg test pythonic"
See https://savannah.gnu.org/bugs/?66820 for details.
Doing pkg test pythonic crashes with assertion failure.
The patch:
diff --git a/src/Makefile b/src/Makefile
index fbc5c1f..c0a7a22 100644
--- a/src/Makefile
+++ b/src/Makefile
@@ -30,7 +30,6 @@ SED ?= sed
ARFLAGS = cr
-export CXXFLAGS ?= -g -O2
srcdir = .
diff --git a/src/oct-py-types.cc b/src/oct-py-types.cc
index a863344..831a6bb 100644
--- a/src/oct-py-types.cc
+++ b/src/oct-py-types.cc
@@ -407,8 +407,21 @@ namespace pythonic
if (PyLong_Check (obj))
{
// FIXME: if (value < 0), may be very implementation dependent
- if (Py_SIZE (obj) < 0)
+ // if (Py_SIZE (obj) < 0)
+
+ // Check if the number is negative
+ // In Python 3.13+, we can't use Py_SIZE on PyLong objects
+ // Instead, check if the number is negative by comparing with zero
+ // using a public API
+ int is_negative = PyObject_RichCompareBool(obj, PyLong_FromLong(0), Py_LT);
+ if (is_negative == 1)
return 0;
+ else if (is_negative == -1)
+ // If the comparison fails for some reason (returns -1),
+ // just call PyErr_Clear() to clear that exception and allow
+ // the code to continue execution.
+ // Is there a better way to handle it?
+ PyErr_Clear();
#if (defined (HAVE_LONG_LONG) && (SIZEOF_LONG_LONG == 8))
unsigned PY_LONG_LONG value = PyLong_AsUnsignedLongLong (obj);
(also attached) fixes that for me. But I do not really know the code so it could be wrong. das_pythonic.diff.gz
Dmitri.