summaryrefslogtreecommitdiff
path: root/efl/utils
diff options
context:
space:
mode:
authorKai Huuhko <kai.huuhko@gmail.com>2013-10-30 11:26:14 +0200
committerKai Huuhko <kai.huuhko@gmail.com>2013-10-30 11:26:14 +0200
commitf9971fecc57561fab37c6385aa611c1153157bc4 (patch)
tree938063ee84fa0aebde1ba409aa5c44e03979a155 /efl/utils
parentb3f501b387b2ebad838f90c9da8d7fbfd287134c (diff)
utils.logger: PyUnicode_FromFormatV -> vsprintf
The Py function segfaults with certain (malformed?) messages.
Diffstat (limited to 'efl/utils')
-rw-r--r--efl/utils/logger.pyx20
1 files changed, 15 insertions, 5 deletions
diff --git a/efl/utils/logger.pyx b/efl/utils/logger.pyx
index 2866a51..22ce861 100644
--- a/efl/utils/logger.pyx
+++ b/efl/utils/logger.pyx
@@ -19,7 +19,8 @@ from libc.string cimport const_char
19from efl.eina cimport Eina_Log_Domain, const_Eina_Log_Domain, Eina_Log_Level, \ 19from efl.eina cimport Eina_Log_Domain, const_Eina_Log_Domain, Eina_Log_Level, \
20 eina_log_print_cb_set, eina_log_domain_register, eina_log_level_set, \ 20 eina_log_print_cb_set, eina_log_domain_register, eina_log_level_set, \
21 eina_log_level_get, eina_log_domain_level_get, eina_log_domain_level_set, \ 21 eina_log_level_get, eina_log_domain_level_get, eina_log_domain_level_set, \
22 eina_log_print 22 eina_log_print, EINA_LOG_DOM_DBG, EINA_LOG_DOM_INFO, EINA_LOG_DOM_WARN, \
23 EINA_LOG_DOM_ERR, EINA_LOG_DOM_CRIT
23from cpython cimport PyUnicode_AsUTF8String, PY_VERSION_HEX 24from cpython cimport PyUnicode_AsUTF8String, PY_VERSION_HEX
24 25
25import logging 26import logging
@@ -29,8 +30,8 @@ cdef extern from "stdarg.h":
29 ctypedef struct va_list: 30 ctypedef struct va_list:
30 pass 31 pass
31 32
32cdef extern from "Python.h": 33cdef extern from "stdio.h":
33 object PyUnicode_FromFormatV(char *format, va_list vargs) 34 int vsprintf(char *, const_char *fmt, va_list args)
34 35
35cdef tuple log_levels = ( 36cdef tuple log_levels = (
36 50, 37 50,
@@ -46,8 +47,14 @@ cdef void py_eina_log_print_cb(const_Eina_Log_Domain *d,
46 Eina_Log_Level level, 47 Eina_Log_Level level,
47 const_char *file, const_char *fnc, int line, 48 const_char *file, const_char *fnc, int line,
48 const_char *fmt, void *data, va_list args) with gil: 49 const_char *fmt, void *data, va_list args) with gil:
49 cdef unicode msg = PyUnicode_FromFormatV(fmt, args) 50 cdef:
50 cdef unicode name = d.name.decode("utf-8") 51 char tmp[256]
52 cdef unicode msg
53 cdef unicode name = d.name.decode("utf-8")
54
55 vsprintf(tmp, fmt, args)
56 msg = tmp.decode("utf-8")
57
51 rec = logging.LogRecord(name, log_levels[level], file, line, msg, None, None, fnc) 58 rec = logging.LogRecord(name, log_levels[level], file, line, msg, None, None, fnc)
52 logger = loggers.get(name, loggers["efl"]) 59 logger = loggers.get(name, loggers["efl"])
53 logger.handle(rec) 60 logger.handle(rec)
@@ -103,3 +110,6 @@ rootlog = add_logger("efl")
103rootlog.propagate = False 110rootlog.propagate = False
104 111
105cdef public int PY_EFL_LOG_DOMAIN = rootlog.eina_log_domain 112cdef public int PY_EFL_LOG_DOMAIN = rootlog.eina_log_domain
113
114def logger_test_dbg():
115 EINA_LOG_DOM_DBG(PY_EFL_LOG_DOMAIN, "test message", NULL)