]> git.ipfire.org Git - thirdparty/freeradius-server.git/commitdiff
use new API
authorAlan T. DeKok <aland@freeradius.org>
Fri, 25 Aug 2023 22:18:04 +0000 (18:18 -0400)
committerAlan T. DeKok <aland@freeradius.org>
Fri, 25 Aug 2023 22:18:04 +0000 (18:18 -0400)
src/modules/rlm_python/rlm_python.c
src/modules/rlm_python3/rlm_python3.c

index 1578df056fc18aa540f2fd21249b8009e5a76da3..412859c06bc33a7485a5c61bfe045f4beb25b5aa 100644 (file)
@@ -996,6 +996,7 @@ static void *dlopen_libpython(int flags)
 static int python_interpreter_init(rlm_python_t *inst, CONF_SECTION *conf)
 {
        int i;
+       bool locked = false;
 
        /*
         *      Explicitly load libpython, so symbols will be available to lib-dynload modules
@@ -1023,8 +1024,7 @@ static int python_interpreter_init(rlm_python_t *inst, CONF_SECTION *conf)
                Py_InitializeEx(0);                     /* Don't override signal handlers - noop on subs calls */
                PyEval_InitThreads();                   /* This also grabs a lock (which we then need to release) */
                main_interpreter = PyThreadState_Get(); /* Store reference to the main interpreter */
-       } else {
-               PyEval_AcquireLock();
+               locked = true;
        }
        rad_assert(PyEval_ThreadsInitialized());
 
@@ -1043,6 +1043,7 @@ static int python_interpreter_init(rlm_python_t *inst, CONF_SECTION *conf)
                inst->sub_interpreter = main_interpreter;
        }
 
+       if (!locked) PyEval_AcquireThread(inst->sub_interpreter);
        PyThreadState_Swap(inst->sub_interpreter);
 
        /*
index 817bf33749f74ef0481cec37de8278fcb74962ef..a200a988aeea99a12d0b1f54281d2031c7be17d2 100644 (file)
@@ -1094,6 +1094,8 @@ static PyMODINIT_FUNC PyInit_radiusd(void)
  */
 static int python_interpreter_init(rlm_python_t *inst, CONF_SECTION *conf)
 {
+       bool locked = false;
+
        /*
         * prepare radiusd module to be loaded
         */
@@ -1135,8 +1137,7 @@ static int python_interpreter_init(rlm_python_t *inst, CONF_SECTION *conf)
                Py_InitializeEx(0);                     /* Don't override signal handlers - noop on subs calls */
                PyEval_InitThreads();                   /* This also grabs a lock (which we then need to release) */
                main_interpreter = PyThreadState_Get(); /* Store reference to the main interpreter */
-       } else {
-               PyEval_AcquireLock();
+               locked = true;
        }
        rad_assert(PyEval_ThreadsInitialized());
 
@@ -1155,6 +1156,7 @@ static int python_interpreter_init(rlm_python_t *inst, CONF_SECTION *conf)
                inst->sub_interpreter = main_interpreter;
        }
 
+       if (!locked) PyEval_AcquireThread(inst->sub_interpreter);
        PyThreadState_Swap(inst->sub_interpreter);
 
        /*