You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
kamailio/debian/patches/upstream/app_python3-use-new-Python-...

62 lines
2.3 KiB

From: Daniel-Constantin Mierla <miconda@gmail.com>
Date: Thu, 21 Jul 2022 20:15:29 +0200
Subject: [PATCH] app_python3: use new Python 3.10+ API functions for tracking
execution
- GH #3187
---
src/modules/app_python3/apy_kemi.c | 23 ++++++++++++++++++++++-
1 file changed, 22 insertions(+), 1 deletion(-)
diff --git a/src/modules/app_python3/apy_kemi.c b/src/modules/app_python3/apy_kemi.c
index 421db19..47a34a4 100644
--- a/src/modules/app_python3/apy_kemi.c
+++ b/src/modules/app_python3/apy_kemi.c
@@ -1810,6 +1810,9 @@ PyObject *sr_apy_kemi_exec_func(PyObject *self, PyObject *args, int idx)
PyObject *ret = NULL;
PyThreadState *pstate = NULL;
PyFrameObject *pframe = NULL;
+#if PY_VERSION_HEX >= 0x03100000
+ PyCodeObject *pcode = NULL;
+#endif
struct timeval tvb = {0}, tve = {0};
struct timezone tz;
unsigned int tdiff;
@@ -1832,10 +1835,27 @@ PyObject *sr_apy_kemi_exec_func(PyObject *self, PyObject *args, int idx)
+ (tve.tv_usec - tvb.tv_usec);
if(tdiff >= cfg_get(core, core_cfg, latency_limit_action)) {
pstate = PyThreadState_GET();
- if (pstate != NULL && pstate->frame != NULL) {
+ if (pstate != NULL) {
+#if PY_VERSION_HEX >= 0x03100000
+ pframe = PyThreadState_GetFrame(pstate);
+ if(pframe != NULL) {
+ pcode = PyFrame_GetCode(pframe);
+ }
+#else
pframe = pstate->frame;
+#endif
}
+#if PY_VERSION_HEX >= 0x03100000
+ LOG(cfg_get(core, core_cfg, latency_log),
+ "alert - action KSR.%s%s%s(...)"
+ " took too long [%u ms] (file:%s func:%s line:%d)\n",
+ (ket->mname.len>0)?ket->mname.s:"",
+ (ket->mname.len>0)?".":"", ket->fname.s, tdiff,
+ (pcode)?PyBytes_AsString(pcode->co_filename):"",
+ (pcode)?PyBytes_AsString(pcode->co_name):"",
+ (pframe)?PyFrame_GetLineNumber(pframe):0);
+#else
LOG(cfg_get(core, core_cfg, latency_log),
"alert - action KSR.%s%s%s(...)"
" took too long [%u ms] (file:%s func:%s line:%d)\n",
@@ -1844,6 +1864,7 @@ PyObject *sr_apy_kemi_exec_func(PyObject *self, PyObject *args, int idx)
(pframe && pframe->f_code)?PyBytes_AsString(pframe->f_code->co_filename):"",
(pframe && pframe->f_code)?PyBytes_AsString(pframe->f_code->co_name):"",
(pframe && pframe->f_code)?PyCode_Addr2Line(pframe->f_code, pframe->f_lasti):0);
+#endif
}
}