mirror of
https://gitlab.linphone.org/BC/public/linphone-iphone.git
synced 2026-05-07 05:53:06 +00:00
Fix some refcounting issues in the Python wrapper.
This commit is contained in:
parent
f6e388c4b2
commit
fc11da8069
2 changed files with 35 additions and 25 deletions
|
|
@ -16,25 +16,29 @@ static void pylinphone_log(const char *level, int indent, const char *fmt, va_li
|
|||
gstate = PyGILState_Ensure();
|
||||
if (gstate != PyGILState_LOCKED) return;
|
||||
linphone_module = PyImport_ImportModule("linphone.linphone");
|
||||
if ((linphone_module != NULL) && PyObject_HasAttrString(linphone_module, "__log_handler")) {
|
||||
PyObject *log_handler = PyObject_GetAttrString(linphone_module, "__log_handler");
|
||||
if ((log_handler != NULL) && PyCallable_Check(log_handler)) {
|
||||
char logstr[4096];
|
||||
int i = 0;
|
||||
if (indent == -1) current_indent--;
|
||||
if (current_indent < 1) current_indent = 1;
|
||||
if ((indent >= -1) && (indent <= 1)) {
|
||||
for (i = 0; i < current_indent; i++) {
|
||||
logstr[i] = '\t';
|
||||
if (linphone_module != NULL) {
|
||||
if (PyObject_HasAttrString(linphone_module, "__log_handler")) {
|
||||
PyObject *log_handler = PyObject_GetAttrString(linphone_module, "__log_handler");
|
||||
if (log_handler != NULL) {
|
||||
if (PyCallable_Check(log_handler)) {
|
||||
char logstr[4096];
|
||||
int i = 0;
|
||||
if (indent == -1) current_indent--;
|
||||
if (current_indent < 1) current_indent = 1;
|
||||
if ((indent >= -1) && (indent <= 1)) {
|
||||
for (i = 0; i < current_indent; i++) {
|
||||
logstr[i] = '\t';
|
||||
}
|
||||
}
|
||||
if (indent == 1) current_indent++;
|
||||
if (vsnprintf(logstr + i, sizeof(logstr) - i, fmt, args) > 0) {
|
||||
if (PyEval_CallObject(log_handler, Py_BuildValue("ss", level, logstr)) == NULL) {
|
||||
PyErr_Print();
|
||||
}
|
||||
}
|
||||
}
|
||||
Py_DECREF(log_handler);
|
||||
}
|
||||
if (indent == 1) current_indent++;
|
||||
if (vsnprintf(logstr + i, sizeof(logstr) - i, fmt, args) > 0) {
|
||||
if (PyEval_CallObject(log_handler, Py_BuildValue("ss", level, logstr)) == NULL) {
|
||||
PyErr_Print();
|
||||
}
|
||||
}
|
||||
Py_DECREF(log_handler);
|
||||
}
|
||||
Py_DECREF(linphone_module);
|
||||
}
|
||||
|
|
@ -75,16 +79,20 @@ static void pylinphone_module_log_handler(OrtpLogLevel lev, const char *fmt, va_
|
|||
if (gstate != PyGILState_LOCKED) return;
|
||||
linphone_module = PyImport_ImportModule("linphone.linphone");
|
||||
level = pylinphone_ortp_log_level_to_string(lev);
|
||||
if ((linphone_module != NULL) && PyObject_HasAttrString(linphone_module, "__log_handler")) {
|
||||
PyObject *log_handler = PyObject_GetAttrString(linphone_module, "__log_handler");
|
||||
if ((log_handler != NULL) && PyCallable_Check(log_handler)) {
|
||||
char logstr[4096];
|
||||
if (vsnprintf(logstr, sizeof(logstr), fmt, args) > 0) {
|
||||
if (PyEval_CallObject(log_handler, Py_BuildValue("ss", level, logstr)) == NULL) {
|
||||
PyErr_Print();
|
||||
if (linphone_module != NULL) {
|
||||
if (PyObject_HasAttrString(linphone_module, "__log_handler")) {
|
||||
PyObject *log_handler = PyObject_GetAttrString(linphone_module, "__log_handler");
|
||||
if (log_handler != NULL) {
|
||||
if (PyCallable_Check(log_handler)) {
|
||||
char logstr[4096];
|
||||
if (vsnprintf(logstr, sizeof(logstr), fmt, args) > 0) {
|
||||
if (PyEval_CallObject(log_handler, Py_BuildValue("ss", level, logstr)) == NULL) {
|
||||
PyErr_Print();
|
||||
}
|
||||
}
|
||||
}
|
||||
Py_DECREF(log_handler);
|
||||
}
|
||||
Py_DECREF(log_handler);
|
||||
}
|
||||
Py_DECREF(linphone_module);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -293,6 +293,7 @@ PyMODINIT_FUNC initlinphone(void) {
|
|||
{{#enums}}
|
||||
menum = Py_InitModule3("{{enum_name}}", pylinphone_{{enum_name}}_ModuleMethods, "{{{enum_doc}}}");
|
||||
if (menum == NULL) return;
|
||||
Py_INCREF(menum);
|
||||
if (PyModule_AddObject(m, "{{enum_name}}", menum) < 0) return;
|
||||
{{#enum_values}}
|
||||
if (PyModule_AddIntConstant(menum, "{{enum_value_name}}", {{enum_value_cname}}) < 0) return;
|
||||
|
|
@ -301,6 +302,7 @@ PyMODINIT_FUNC initlinphone(void) {
|
|||
|
||||
menum = Py_InitModule3("PayloadTypeType", pylinphone_PayloadTypeType_ModuleMethods, "Type of linphone.PayloadType.");
|
||||
if (menum == NULL) return;
|
||||
Py_INCREF(menum);
|
||||
if (PyModule_AddObject(m, "PayloadTypeType", menum) < 0) return;
|
||||
if (PyModule_AddIntConstant(menum, "PAYLOAD_AUDIO_CONTINUOUS", PAYLOAD_AUDIO_CONTINUOUS) < 0) return;
|
||||
if (PyModule_AddIntConstant(menum, "PAYLOAD_AUDIO_PACKETIZED", PAYLOAD_AUDIO_PACKETIZED) < 0) return;
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue