diff --git a/Modules/_struct.c b/Modules/_struct.c index ec896bf24dc..1c885b7430d 100644 --- a/Modules/_struct.c +++ b/Modules/_struct.c @@ -609,6 +609,9 @@ bu_uint(const char *p, const formatdef *f) #ifdef PY_USE_INT_WHEN_POSSIBLE if (x <= INT_MAX) return PyInt_FromLong((long)x); +#else + if (SIZEOF_LONG > f->size) + return PyInt_FromLong((long)x); #endif return PyLong_FromUnsignedLong(x); } @@ -805,6 +808,9 @@ lu_uint(const char *p, const formatdef *f) #ifdef PY_USE_INT_WHEN_POSSIBLE if (x <= INT_MAX) return PyInt_FromLong((long)x); +#else + if (SIZEOF_LONG > f->size) + return PyInt_FromLong((long)x); #endif return PyLong_FromUnsignedLong((long)x); }