summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKai Huuhko <kai.huuhko@gmail.com>2015-03-12 14:27:36 +0200
committerKai Huuhko <kai.huuhko@gmail.com>2015-03-12 14:27:36 +0200
commit179404e2796cd9ec3bb077403f6be46317b7722a (patch)
treecf8720fc716b0cdde8060ccc70d1fe0e72ee6113
parent8b594d4bd889a24facf54b969ffda958b1180cce (diff)
Evas.SmartObject: Change SmartCb spec into a custom object
This allows faster C access to the values, avoids casting the conv_func pointer to an integer and back.
-rw-r--r--efl/evas/efl.evas_object_smart.pxi52
1 files changed, 26 insertions, 26 deletions
diff --git a/efl/evas/efl.evas_object_smart.pxi b/efl/evas/efl.evas_object_smart.pxi
index 129e46e..4831749 100644
--- a/efl/evas/efl.evas_object_smart.pxi
+++ b/efl/evas/efl.evas_object_smart.pxi
@@ -25,10 +25,6 @@ from cpython cimport PyMem_Malloc, Py_INCREF, Py_DECREF
25#_smart_classes = list() 25#_smart_classes = list()
26 26
27 27
28cdef object _smart_cb_pass_conv(void *addr):
29 return <object>addr
30
31
32cdef void _smart_object_delete(Evas_Object *o) with gil: 28cdef void _smart_object_delete(Evas_Object *o) with gil:
33 cdef: 29 cdef:
34 void *tmp 30 void *tmp
@@ -323,50 +319,46 @@ cdef void _smart_object_member_del(Evas_Object *o, Evas_Object *clip) with gil:
323 traceback.print_exc() 319 traceback.print_exc()
324 320
325 321
326cdef void _smart_callback(void *data, Evas_Object *o, void *event_info) with gil: 322cdef class _SmartCb:
327
328 cdef: 323 cdef:
324 const char *event
329 SmartObject obj 325 SmartObject obj
330 object(*event_conv)(void*) 326 object(*event_conv)(void*)
331 uintptr_t conv 327 uintptr_t conv
332 object func 328 object func
333 tuple args 329 tuple args
334 dict kargs 330 dict kargs
335 tuple tmp
336 331
332
333cdef object _smart_cb_pass_conv(void *addr):
334 return <object>addr
335
336
337cdef void _smart_callback(void *data, Evas_Object *o, void *event_info) with gil:
337 if data == NULL: 338 if data == NULL:
338 EINA_LOG_DOM_ERR(PY_EFL_EVAS_LOG_DOMAIN, "data is NULL!", NULL) 339 EINA_LOG_DOM_ERR(PY_EFL_EVAS_LOG_DOMAIN, "data is NULL!", NULL)
339 return 340 return
340 341
341 #obj, conv, func, args, kargs = <tuple>data 342 cdef _SmartCb spec = <_SmartCb>data
342
343 tmp = <tuple>data
344 obj = <SmartObject>tmp[0]
345 conv = <uintptr_t>tmp[1]
346 func = tmp[2]
347 args = <tuple>tmp[3]
348 kargs = <dict>tmp[4]
349 343
350 if event_info == NULL: 344 if event_info == NULL:
351 try: 345 try:
352 func(obj, *args, **kargs) 346 spec.func(spec.obj, *spec.args, **spec.kargs)
353 except Exception: 347 except Exception:
354 traceback.print_exc() 348 traceback.print_exc()
355 elif conv == 0: 349 elif spec.event_conv == NULL:
356 EINA_LOG_DOM_WARN( 350 EINA_LOG_DOM_WARN(
357 PY_EFL_EVAS_LOG_DOMAIN, 351 PY_EFL_EVAS_LOG_DOMAIN,
358 "event_info is not NULL and there is no event_conv!", 352 'event_info for event "%s" is not NULL and there is no event_conv!',
359 NULL 353 spec.event
360 ) 354 )
361 try: 355 try:
362 func(obj, *args, **kargs) 356 spec.func(spec.obj, *spec.args, **spec.kargs)
363 except Exception: 357 except Exception:
364 traceback.print_exc() 358 traceback.print_exc()
365 else: 359 else:
366 event_conv = <object(*)(void*)><void *>conv
367 try: 360 try:
368 ei = event_conv(event_info) 361 spec.func(spec.obj, spec.event_conv(event_info), *spec.args, **spec.kargs)
369 func(obj, ei, *args, **kargs)
370 except Exception: 362 except Exception:
371 traceback.print_exc() 363 traceback.print_exc()
372 364
@@ -769,9 +761,17 @@ cdef class SmartObject(Object):
769 """ 761 """
770 if not callable(func): 762 if not callable(func):
771 raise TypeError("func must be callable") 763 raise TypeError("func must be callable")
764
772 if isinstance(event, unicode): event = PyUnicode_AsUTF8String(event) 765 if isinstance(event, unicode): event = PyUnicode_AsUTF8String(event)
773 766
774 spec = (self, <uintptr_t><void *>event_conv, func, args, kargs) 767 cdef _SmartCb spec = _SmartCb()
768 spec.event = event
769 spec.obj = self
770 spec.event_conv = event_conv
771 spec.func = func
772 spec.args = args
773 spec.kargs = kargs
774
775 lst = self._smart_callback_specs.setdefault(event, []) 775 lst = self._smart_callback_specs.setdefault(event, [])
776 lst.append(spec) 776 lst.append(spec)
777 777
@@ -800,7 +800,7 @@ cdef class SmartObject(Object):
800 800
801 """ 801 """
802 cdef: 802 cdef:
803 tuple spec 803 _SmartCb spec
804 int found = 0 804 int found = 0
805 int i 805 int i
806 void *tmp 806 void *tmp
@@ -813,7 +813,7 @@ cdef class SmartObject(Object):
813 raise ValueError("No callbacks registered for the given event type") 813 raise ValueError("No callbacks registered for the given event type")
814 814
815 for i, spec in enumerate(lst): 815 for i, spec in enumerate(lst):
816 if spec[2] is func: 816 if spec.func is func:
817 found = 1 817 found = 1
818 break 818 break
819 819