Utils.logger: Initialize threads in the module.

If the print cb was called from another thread it would segfault.

This was being triggered when Emotion printed out an error message.
This commit is contained in:
Kai Huuhko 2013-11-29 23:41:07 +02:00
parent 98498c04b9
commit 1ad70ef3d6
1 changed files with 17 additions and 8 deletions

View File

@ -33,6 +33,9 @@ cdef extern from "stdarg.h":
cdef extern from "stdio.h":
int vsprintf(char *, const_char *fmt, va_list args)
cdef extern from "Python.h":
void PyEval_InitThreads()
cdef tuple log_levels = (
50,
40,
@ -45,18 +48,24 @@ cdef dict loggers = dict()
cdef char log_buf[1024]
cdef void py_eina_log_print_cb(const_Eina_Log_Domain *d,
Eina_Log_Level level,
const_char *file, const_char *fnc, int line,
const_char *fmt, void *data, va_list args) with gil:
PyEval_InitThreads()
cdef void py_eina_log_print_cb(const_Eina_Log_Domain *d, Eina_Log_Level level,
const_char *file, const_char *fnc, int line,
const_char *fmt, void *data, va_list args) with gil:
cdef:
unicode msg
unicode name = d.name.decode("utf-8")
unicode msg, name
object rec, logger
vsprintf(log_buf, fmt, args)
msg = log_buf.decode("utf-8")
rec = logging.LogRecord(name, log_levels[level], file, line, msg, None, None, fnc)
msg = log_buf.decode("utf-8")
name = d.name.decode("utf-8")
rec = logging.LogRecord(
name, log_levels[level], file, line, msg, None, None, fnc)
logger = loggers.get(name, loggers["efl"])
logger.handle(rec)