Module: kamailio
Branch: master
Commit: 5a048b9489ce4a5c48e632376f7472b26efefb45
URL:
https://github.com/kamailio/kamailio/commit/5a048b9489ce4a5c48e632376f7472b…
Author: Daniel-Constantin Mierla <miconda(a)gmail.com>
Committer: Daniel-Constantin Mierla <miconda(a)gmail.com>
Date: 2021-12-10T08:07:23+01:00
misc: kemi-code-gen.py - generate code for python functions with xval return
---
Modified: misc/tools/kemi/kemi-code-gen.py
---
Diff:
https://github.com/kamailio/kamailio/commit/5a048b9489ce4a5c48e632376f7472b…
Patch:
https://github.com/kamailio/kamailio/commit/5a048b9489ce4a5c48e632376f7472b…
---
diff --git a/misc/tools/kemi/kemi-code-gen.py b/misc/tools/kemi/kemi-code-gen.py
index dd77d61655..2a024f826e 100644
--- a/misc/tools/kemi/kemi-code-gen.py
+++ b/misc/tools/kemi/kemi-code-gen.py
@@ -4,7 +4,7 @@
PRINTPARAMS=3
# - print mode: typedefs, js, lua, python, pythonparams, ruby, sqlang
-PRINTMODE="js"
+PRINTMODE="python"
# - two tabs for python params, three for the other cases
# PRINTTABS="\t\t"
PRINTTABS="\t\t\t"
@@ -60,10 +60,8 @@ def printCodeIfJS(prefix):
sfunc = PRINTTABS + "\t\txret = ((sr_kemi_xfm" + prefix +
"_f)(ket->func))(env_J->msg,\n" + PRINTTABS + "\t\t\t"
print(sfunc + sparams)
print(PRINTTABS + "\t\treturn sr_kemi_jsdt_return_xval(J, ket, xret);")
-
print("\t\t\t\t} else {")
sfunc = PRINTTABS + "\t\tret = ((sr_kemi_fm" + prefix +
"_f)(ket->func))(env_J->msg,\n" + PRINTTABS + "\t\t\t"
-
print(sfunc + sparams)
print(PRINTTABS + "\t\treturn sr_kemi_jsdt_return_int(J, ket, ret);")
print("\t\t\t\t}")
@@ -100,10 +98,8 @@ def printCodeIfLua(prefix):
sfunc = PRINTTABS + "\t\txret = ((sr_kemi_xfm" + prefix +
"_f)(ket->func))(env_L->msg,\n" + PRINTTABS + "\t\t\t"
print(sfunc + sparams)
print(PRINTTABS + "\t\treturn sr_kemi_lua_return_xval(L, ket, xret);")
-
print("\t\t\t\t} else {")
sfunc = PRINTTABS + "\t\tret = ((sr_kemi_fm" + prefix +
"_f)(ket->func))(env_L->msg,\n" + PRINTTABS + "\t\t\t"
-
print(sfunc + sparams)
print(PRINTTABS + "\t\treturn sr_kemi_lua_return_int(L, ket, ret);")
print("\t\t\t\t}")
@@ -111,33 +107,40 @@ def printCodeIfLua(prefix):
def printCodeIfPython(prefix):
global PRINTELSE
- sfunc = PRINTTABS + "\tret = ((sr_kemi_fm" + prefix +
"_f)(ket->func))(lmsg,\n" + PRINTTABS + "\t\t\t"
+ sparams = ""
for i, c in enumerate(prefix):
if i==0:
if c == 's':
print(PRINTTABS + PRINTELSE + "if(ket->ptypes[0]==SR_KEMIP_STR")
- sfunc += "&vps[" + str(i) +"].s, "
+ sparams += "&vps[" + str(i) +"].s, "
else:
print(PRINTTABS + PRINTELSE + "if(ket->ptypes[0]==SR_KEMIP_INT")
- sfunc += "vps[" + str(i) +"].n, "
+ sparams += "vps[" + str(i) +"].n, "
PRINTELSE = "} else "
elif i==PRINTPARAMS-1:
if c == 's':
print(PRINTTABS + "\t\t&& ket->ptypes[" + str(i) +
"]==SR_KEMIP_STR) {")
- sfunc += "&vps[" + str(i) +"].s);"
+ sparams += "&vps[" + str(i) +"].s);"
else:
print(PRINTTABS + "\t\t&& ket->ptypes[" + str(i) +
"]==SR_KEMIP_INT) {")
- sfunc += "vps[" + str(i) +"].n);"
+ sparams += "vps[" + str(i) +"].n);"
else:
if c == 's':
print(PRINTTABS + "\t\t&& ket->ptypes[" + str(i) +
"]==SR_KEMIP_STR")
- sfunc += "&vps[" + str(i) +"].s, "
+ sparams += "&vps[" + str(i) +"].s, "
else:
print(PRINTTABS + "\t\t&& ket->ptypes[" + str(i) +
"]==SR_KEMIP_INT")
- sfunc += "vps[" + str(i) +"].n, "
+ sparams += "vps[" + str(i) +"].n, "
- print(sfunc)
- print(PRINTTABS + "\treturn sr_kemi_apy_return_int(ket, ret);")
+ print("\t\t\t\tif(ket->rtype==SR_KEMIP_XVAL) {")
+ sfunc = PRINTTABS + "\t\txret = ((sr_kemi_xfm" + prefix +
"_f)(ket->func))(lmsg,\n" + PRINTTABS + "\t\t\t"
+ print(sfunc + sparams)
+ print(PRINTTABS + "\t\treturn sr_kemi_apy_return_xval(ket, xret);")
+ print("\t\t\t\t} else {")
+ sfunc = PRINTTABS + "\t\tret = ((sr_kemi_fm" + prefix +
"_f)(ket->func))(lmsg,\n" + PRINTTABS + "\t\t\t"
+ print(sfunc + sparams)
+ print(PRINTTABS + "\t\treturn sr_kemi_apy_return_int(ket, ret);")
+ print("\t\t\t\t}")
def printCodeIfPythonParams(prefix):