summaryrefslogtreecommitdiff
path: root/efl/utils
diff options
context:
space:
mode:
authorKai Huuhko <kai.huuhko@gmail.com>2014-04-06 23:48:16 +0300
committerKai Huuhko <kai.huuhko@gmail.com>2014-04-06 23:48:16 +0300
commitd6dc3a2045b756e3a633fcfdac9312dc234fa00d (patch)
tree94a803961ea49b5185d3efbffb25a576a850fcd2 /efl/utils
parent9cb0bbaf8b40e7e489ed8a28b1315a942b6f0a0f (diff)
Revert "Remove Python -> C string hacks"
A quote from Cython documentation: "The other direction, i.e. automatic encoding to C strings, is only supported for the ASCII codec (and the “default encoding”, which is runtime specific and may or may not be ASCII). This is because CPython handles the memory management in this case by keeping an encoded copy of the string alive together with the original unicode string. Otherwise, there would be no way to limit the lifetime of the encoded string in any sensible way, thus rendering any attempt to extract a C string pointer from it a dangerous endeavour." Cython plays it safe and we can't live with ASCII-only; reverting to our earlier "hacks" for string conversion. This reverts commit b547ff2aa2064b98021d6f458cfc3d44a9936544. Conflicts: efl/elementary/entry.pyx efl/elementary/object.pyx
Diffstat (limited to 'efl/utils')
-rw-r--r--efl/utils/conversions.pyx3
-rw-r--r--efl/utils/deprecated.pyx3
-rw-r--r--efl/utils/logger.pyx5
3 files changed, 9 insertions, 2 deletions
diff --git a/efl/utils/conversions.pyx b/efl/utils/conversions.pyx
index d008544..173768b 100644
--- a/efl/utils/conversions.pyx
+++ b/efl/utils/conversions.pyx
@@ -17,6 +17,7 @@
17 17
18from libc.stdlib cimport malloc, free 18from libc.stdlib cimport malloc, free
19from libc.string cimport strdup 19from libc.string cimport strdup
20from cpython cimport PyUnicode_AsUTF8String
20 21
21from efl.c_eo cimport Eo as cEo 22from efl.c_eo cimport Eo as cEo
22from efl.eo cimport Eo, object_from_instance 23from efl.eo cimport Eo, object_from_instance
@@ -85,6 +86,7 @@ cdef const char ** python_list_strings_to_array_of_strings(list strings) except
85 86
86 for i in range(arr_len): 87 for i in range(arr_len):
87 s = strings[i] 88 s = strings[i]
89 if isinstance(s, unicode): s = PyUnicode_AsUTF8String(s)
88 array[i] = <const char *>strdup(s) 90 array[i] = <const char *>strdup(s)
89 91
90 return array 92 return array
@@ -148,6 +150,7 @@ cdef list eina_list_strings_to_python_list(const Eina_List *lst):
148cdef Eina_List *python_list_strings_to_eina_list(list strings): 150cdef Eina_List *python_list_strings_to_eina_list(list strings):
149 cdef Eina_List *lst = NULL 151 cdef Eina_List *lst = NULL
150 for s in strings: 152 for s in strings:
153 if isinstance(s, unicode): s = PyUnicode_AsUTF8String(s)
151 lst = eina_list_append(lst, eina_stringshare_add(s)) 154 lst = eina_list_append(lst, eina_stringshare_add(s))
152 return lst 155 return lst
153 156
diff --git a/efl/utils/deprecated.pyx b/efl/utils/deprecated.pyx
index d9179c0..1e9767a 100644
--- a/efl/utils/deprecated.pyx
+++ b/efl/utils/deprecated.pyx
@@ -19,7 +19,7 @@ import traceback
19import types 19import types
20from functools import update_wrapper 20from functools import update_wrapper
21 21
22from cpython cimport PY_VERSION_HEX 22from cpython cimport PY_VERSION_HEX, PyUnicode_AsUTF8String
23 23
24from efl.eina cimport EINA_LOG_DOM_WARN 24from efl.eina cimport EINA_LOG_DOM_WARN
25from efl.utils.logger cimport PY_EFL_LOG_DOMAIN 25from efl.utils.logger cimport PY_EFL_LOG_DOMAIN
@@ -98,6 +98,7 @@ class WRAPPER(object):
98 msg += " " + self.message 98 msg += " " + self.message
99 99
100 msg2 = msg 100 msg2 = msg
101 if isinstance(msg2, unicode): msg2 = PyUnicode_AsUTF8String(msg2)
101 102
102 EINA_LOG_DOM_WARN(PY_EFL_LOG_DOMAIN, msg2, NULL) 103 EINA_LOG_DOM_WARN(PY_EFL_LOG_DOMAIN, msg2, NULL)
103 104
diff --git a/efl/utils/logger.pyx b/efl/utils/logger.pyx
index babb6b5..11ad1a5 100644
--- a/efl/utils/logger.pyx
+++ b/efl/utils/logger.pyx
@@ -20,7 +20,7 @@ from efl.eina cimport Eina_Log_Domain, Eina_Log_Level, \
20 eina_log_level_get, eina_log_domain_level_get, eina_log_domain_level_set, \ 20 eina_log_level_get, eina_log_domain_level_get, eina_log_domain_level_set, \
21 eina_log_print, EINA_LOG_DOM_DBG, EINA_LOG_DOM_INFO, EINA_LOG_DOM_WARN, \ 21 eina_log_print, EINA_LOG_DOM_DBG, EINA_LOG_DOM_INFO, EINA_LOG_DOM_WARN, \
22 EINA_LOG_DOM_ERR, EINA_LOG_DOM_CRIT 22 EINA_LOG_DOM_ERR, EINA_LOG_DOM_CRIT
23from cpython cimport PY_VERSION_HEX 23from cpython cimport PyUnicode_AsUTF8String, PY_VERSION_HEX
24 24
25import logging 25import logging
26import types 26import types
@@ -72,6 +72,7 @@ eina_log_print_cb_set(py_eina_log_print_cb, NULL)
72 72
73def setLevel(self, lvl): 73def setLevel(self, lvl):
74 cname = self.name 74 cname = self.name
75 if isinstance(cname, unicode): cname = PyUnicode_AsUTF8String(cname)
75 eina_log_domain_level_set(cname, log_levels.index(lvl)) 76 eina_log_domain_level_set(cname, log_levels.index(lvl))
76 logging.Logger.setLevel(self, lvl) 77 logging.Logger.setLevel(self, lvl)
77 78
@@ -79,6 +80,7 @@ class PyEFLLogger(logging.Logger):
79 80
80 def __init__(self, name): 81 def __init__(self, name):
81 cname = name 82 cname = name
83 if isinstance(cname, unicode): cname = PyUnicode_AsUTF8String(cname)
82 self.eina_log_domain = eina_log_domain_register(cname, NULL) 84 self.eina_log_domain = eina_log_domain_register(cname, NULL)
83 loggers[name] = self 85 loggers[name] = self
84 logging.Logger.__init__(self, name) 86 logging.Logger.__init__(self, name)
@@ -95,6 +97,7 @@ cdef object add_logger(object name):
95 # The logger has been instantiated already so lets add our own 97 # The logger has been instantiated already so lets add our own
96 # initialization for it. 98 # initialization for it.
97 cname = name 99 cname = name
100 if isinstance(cname, unicode): cname = PyUnicode_AsUTF8String(cname)
98 log.eina_log_domain = eina_log_domain_register(cname, NULL) 101 log.eina_log_domain = eina_log_domain_register(cname, NULL)
99 loggers[name] = log 102 loggers[name] = log
100 lvl = log.getEffectiveLevel() 103 lvl = log.getEffectiveLevel()