]> git.ipfire.org Git - thirdparty/freeradius-server.git/commitdiff
Back port fixes for Python API changes from 3.2
authorNick Porter <nick@portercomputing.co.uk>
Thu, 23 Jan 2025 10:50:33 +0000 (10:50 +0000)
committerNick Porter <nick@portercomputing.co.uk>
Thu, 23 Jan 2025 10:50:33 +0000 (10:50 +0000)
src/modules/rlm_python3/rlm_python3.c

index 0fa68cda2a99b2f87fd6f1379dfe4cc9570859f4..3642ed9e3a1fdf98031e15ac769b9068e73c9e98 100644 (file)
@@ -1129,7 +1129,33 @@ static int python_interpreter_init(rlm_python_t *inst, CONF_SECTION *conf)
                python_dlhandle = dlopen_libpython(RTLD_NOW | RTLD_GLOBAL);
                if (!python_dlhandle) WARN("Failed loading libpython symbols into global symbol table");
 
-#if PY_VERSION_HEX >= 0x03050000
+#if PY_VERSION_HEX > 0x030a0000
+               {
+                       PyStatus status;
+                       PyConfig config;
+                       wchar_t  *name;
+
+                       /*
+                        *      Isolated config: Don't override signal handlers - noop on subs calls
+                        */
+                       PyConfig_InitIsolatedConfig(&config);
+
+                       MEM(name = Py_DecodeLocale(main_config.name, NULL));
+                       status = PyConfig_SetString(&config, &config.program_name, name);
+                       PyMem_RawFree(name);
+                       if (PyStatus_Exception(status)) {
+                               PyConfig_Clear(&config);
+                               return -1;
+                       }
+
+                       status = Py_InitializeFromConfig(&config);
+                       if (PyStatus_Exception(status)) {
+                               PyConfig_Clear(&config);
+                               return -1;
+                       }
+                       PyConfig_Clear(&config);
+               }
+#elif PY_VERSION_HEX >= 0x03050000
                {
                        wchar_t  *name;
 
@@ -1146,11 +1172,17 @@ static int python_interpreter_init(rlm_python_t *inst, CONF_SECTION *conf)
                }
 #endif
 
+#if PY_VERSION_HEX <= 0x030a0000
                Py_InitializeEx(0);                     /* Don't override signal handlers - noop on subs calls */
+#if PY_VERSION_HEX <= 0x03060000
                PyEval_InitThreads();                   /* This also grabs a lock (which we then need to release) */
+#endif
+#endif
                main_interpreter = PyThreadState_Get(); /* Store reference to the main interpreter */
        }
+#if PY_VERSION_HEX < 0x03090000
        rad_assert(PyEval_ThreadsInitialized());
+#endif
 
        /*
         *      Increment the reference counter