Skip to content

Commit b813aad

Browse files
authored
Merge pull request #145 from saurik/master
get tests working on Python 3.13 and 3.14
2 parents 188b55d + 95207a0 commit b813aad

File tree

4 files changed

+19
-17
lines changed

4 files changed

+19
-17
lines changed

lib/python/mod_python/publisher.py

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -255,8 +255,16 @@ def lookup(name):
255255
if name in names:
256256
i = list(names).index(name)
257257
if i is not None:
258-
if PY2 or sys.hexversion >= 0x030b0000: # 3.12.0
259-
return (1, func_code.co_consts[i+1])
258+
# Python 3.11 moved qualified name into code object
259+
# https://github.com/python/cpython/pull/26941
260+
# commit 2f180ce2cb6e6a7e3c517495e0f4873d6aaf5f2f
261+
if PY2 or sys.hexversion >= 0x030b0000:
262+
# Python 3.14 added CO_HAS_DOCSTRING (0x4000000)
263+
# https://github.com/python/cpython/issues/126072
264+
# https://github.com/python/cpython/pull/126101
265+
# commit 35df4eb959b3923c08aaaeff728c5ed1706f31cf
266+
offset = 1 if sys.hexversion < 0x030e0000 or (func_code.co_flags & 0x4000000) != 0 else 0
267+
return (1, func_code.co_consts[offset+i])
260268
else:
261269
return (1, func_code.co_consts[1+i*2])
262270

src/_apachemodule.c

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -852,13 +852,6 @@ PyObject *_apache_module_init()
852852
m = Py_InitModule("_apache", _apache_module_methods);
853853
#else
854854
m = PyModule_Create(&_apache_moduledef);
855-
PyObject *name = PyUnicode_FromString("_apache");
856-
857-
_PyImport_FixupExtensionObject(m, name, name
858-
#if PY_MINOR_VERSION >= 7
859-
,PyImport_GetModuleDict()
860-
#endif
861-
);
862855
#endif
863856
d = PyModule_GetDict(m);
864857
Mp_ServerReturn = PyErr_NewException("_apache.SERVER_RETURN", NULL, NULL);

src/include/_apachemodule.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,5 @@
2929
*/
3030

3131
PyObject *get_ServerReturn(void);
32-
PyMODINIT_FUNC init_apache(void);
3332

3433
#endif /* !Mp_APACHEMODULE_H */

src/mod_python.c

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -69,12 +69,6 @@ static PyObject * make_obcallback(const char *name)
6969
PyObject *m = NULL;
7070
PyObject *obCallBack = NULL;
7171

72-
/* This makes _apache appear imported, and subsequent
73-
* >>> import _apache
74-
* will not give an error.
75-
*/
76-
_apache_module_init();
77-
7872
/* Now execute the equivalent of
7973
* >>> import <module>
8074
* >>> <initstring>
@@ -787,6 +781,14 @@ static int python_init(apr_pool_t *p, apr_pool_t *ptemp,
787781
Py_NoSiteFlag = 1;
788782
#endif
789783

784+
#if PY_MAJOR_VERSION == 2
785+
PyMODINIT_FUNC init_apache(void);
786+
PyImport_AppendInittab("_apache", &init_apache);
787+
#else
788+
PyMODINIT_FUNC PyInit_apache(void);
789+
PyImport_AppendInittab("_apache", &PyInit_apache);
790+
#endif
791+
790792
Py_Initialize();
791793

792794
#if PY_MAJOR_VERSION == 2 && \
@@ -2641,7 +2643,7 @@ static void PythonChildInitHandler(apr_pool_t *p, server_rec *s)
26412643

26422644
#if PY_VERSION_HEX < 0x03070000
26432645
PyOS_AfterFork();
2644-
#else
2646+
#elif PY_VERSION_HEX < 0x030D0000
26452647
PyOS_AfterFork_Child();
26462648
#endif
26472649

0 commit comments

Comments
 (0)