From 72bcb2a188a25afbcd1f3be0fdcc466c4866b0f6 Mon Sep 17 00:00:00 2001 From: Andreas Hasenack Date: Sun, 17 Apr 2022 19:30:27 -0400 Subject: [PATCH 1/3] Make mod-python PY_SSIZE_T_CLEAN Required for Python 3.10 support. Bug-Debian: https://bugs.debian.org/1009243 Bug-Ubuntu: https://bugs.launchpad.net/ubuntu/+source/libapache2-mod-python/+bug/1960088 --- src/connobject.c | 2 +- src/filterobject.c | 2 +- src/include/mod_python.h | 1 + src/include/mod_python.h.in | 1 + src/requestobject.c | 2 +- 5 files changed, 5 insertions(+), 3 deletions(-) diff --git a/src/connobject.c b/src/connobject.c index 6f029a44..82cf195e 100644 --- a/src/connobject.c +++ b/src/connobject.c @@ -232,7 +232,7 @@ static PyObject * conn_readline(connobject *self, PyObject *args) static PyObject * conn_write(connobject *self, PyObject *args) { char *buff; - int len; + Py_ssize_t len; apr_bucket_brigade *bb; apr_bucket *b; PyObject *s; diff --git a/src/filterobject.c b/src/filterobject.c index 966d2f8b..712dbb4f 100644 --- a/src/filterobject.c +++ b/src/filterobject.c @@ -315,7 +315,7 @@ static PyObject *filter_write(filterobject *self, PyObject *args) { char *buff; - int len; + Py_ssize_t len; apr_bucket *b; PyObject *s; conn_rec *c = self->request_obj->request_rec->connection; diff --git a/src/include/mod_python.h b/src/include/mod_python.h index 68a77d46..69f02146 100644 --- a/src/include/mod_python.h +++ b/src/include/mod_python.h @@ -43,6 +43,7 @@ */ /* Python headers */ +#define PY_SSIZE_T_CLEAN #include "Python.h" #include "structmember.h" diff --git a/src/include/mod_python.h.in b/src/include/mod_python.h.in index 7d536c52..8d97c475 100644 --- a/src/include/mod_python.h.in +++ b/src/include/mod_python.h.in @@ -43,6 +43,7 @@ */ /* Python headers */ +#define PY_SSIZE_T_CLEAN #include "Python.h" #include "structmember.h" diff --git a/src/requestobject.c b/src/requestobject.c index 65d42ace..38b71653 100644 --- a/src/requestobject.c +++ b/src/requestobject.c @@ -1576,7 +1576,7 @@ static PyObject * req_update_mtime(requestobject *self, PyObject *args) static PyObject * req_write(requestobject *self, PyObject *args) { - int len; + Py_ssize_t len; int rc; char *buff; int flush=1; From 1e02915f9a15422936f626ddcb3f4e117eea8e46 Mon Sep 17 00:00:00 2001 From: Andreas Hasenack Date: Sun, 17 Apr 2022 19:31:55 -0400 Subject: [PATCH 2/3] Python 3.10 support: import Callable from collections.abc Bug-Debian: https://bugs.debian.org/1009243 Bug-Ubuntu: https://bugs.launchpad.net/ubuntu/+source/libapache2-mod-python/+bug/1960088 --- lib/python/mod_python/publisher.py | 4 ++-- lib/python/mod_python/util.py | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/lib/python/mod_python/publisher.py b/lib/python/mod_python/publisher.py index 75d103fa..5882e771 100644 --- a/lib/python/mod_python/publisher.py +++ b/lib/python/mod_python/publisher.py @@ -51,8 +51,8 @@ def _callable(obj): if PY2: return callable(obj) else: - return (isinstance(obj, collections.Callable) or - (hasattr(obj, "__call__") and isinstance(obj.__call__, collections.Callable))) + return (isinstance(obj, collections.abc.Callable) or + (hasattr(obj, "__call__") and isinstance(obj.__call__, collections.abc.Callable))) ####################### The published page cache ############################## diff --git a/lib/python/mod_python/util.py b/lib/python/mod_python/util.py index 67d6b3fd..30601a54 100644 --- a/lib/python/mod_python/util.py +++ b/lib/python/mod_python/util.py @@ -368,12 +368,12 @@ def __init__(self, req, keep_blank_values=0, strict_parsing=0, file_callback=Non filename = None if b"filename" in disp_options: filename = disp_options[b"filename"] - if file_callback and isinstance(file_callback, collections.Callable): + if file_callback and isinstance(file_callback, collections.abc.Callable): file = file_callback(filename) else: file = tempfile.TemporaryFile("w+b") else: - if field_callback and isinstance(field_callback, collections.Callable): + if field_callback and isinstance(field_callback, collections.abc.Callable): file = field_callback() else: file = BytesIO() From d22f24180f5e7dfad3ab8c993bf7094dec8fe14d Mon Sep 17 00:00:00 2001 From: Stefano Rivera Date: Sun, 17 Apr 2022 19:58:41 -0400 Subject: [PATCH 3/3] Support 2-digit Python minor versions Python 3.10 support. Fixes: #111 Bug-upstream: https://github.com/grisha/mod_python/issues/111 --- configure.in | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/configure.in b/configure.in index 8aa8fd3c..e90b7c41 100644 --- a/configure.in +++ b/configure.in @@ -167,9 +167,9 @@ fi # find out python version AC_MSG_CHECKING(Python version) -PyVERSION=`$PYTHON_BIN -c ['import sys; print(sys.version[:3])'`] -PyMAJVERSION=`$PYTHON_BIN -c ['import sys; print(sys.version[:1])'`] -PyMINVERSION=`$PYTHON_BIN -c ['import sys; print(sys.version.split(".")[1])'`] +PyVERSION=`$PYTHON_BIN -c ['import sys; print('{}.{}'.format(*sys.version_info))'`] +PyMAJVERSION=`$PYTHON_BIN -c ['import sys; print(sys.version_info.major)'`] +PyMINVERSION=`$PYTHON_BIN -c ['import sys; print(sys.version_info.minor)'`] AC_MSG_RESULT($PyVERSION) # make sure Python version is >= 2.6 for 2 and >= 3.3 for 3