diff options
author | Kai Huuhko <kai.huuhko@gmail.com> | 2015-03-11 11:36:50 +0200 |
---|---|---|
committer | Kai Huuhko <kai.huuhko@gmail.com> | 2015-03-11 11:36:50 +0200 |
commit | d36b61e97e98e2067f50a3aa510071f420cf6c30 (patch) | |
tree | e467cc27021bbf900706eb0d472014128ca8659d | |
parent | 7fad9e3ff4ab12b996e8f37577131519cd258977 (diff) |
Evas.SmartObject: Keep refs in a list
Using Py_INCREF/DECREF in add/del we could have dangling references when
the object is deleted without user calling callback_del.
-rw-r--r-- | efl/evas/efl.evas_object_smart.pxi | 9 | ||||
-rw-r--r-- | include/efl.evas.pxd | 12 |
2 files changed, 14 insertions, 7 deletions
diff --git a/efl/evas/efl.evas_object_smart.pxi b/efl/evas/efl.evas_object_smart.pxi index 091da06..e505178 100644 --- a/efl/evas/efl.evas_object_smart.pxi +++ b/efl/evas/efl.evas_object_smart.pxi | |||
@@ -591,6 +591,9 @@ cdef class SmartObject(Object): | |||
591 | should be instantiated and passed to this classes constructor as | 591 | should be instantiated and passed to this classes constructor as |
592 | parameter ``smart`` | 592 | parameter ``smart`` |
593 | """ | 593 | """ |
594 | def __cinit__(self): | ||
595 | self._owned_references = list() | ||
596 | |||
594 | def __init__(self, Canvas canvas not None, Smart smart not None, **kwargs): | 597 | def __init__(self, Canvas canvas not None, Smart smart not None, **kwargs): |
595 | #_smart_classes.append(<uintptr_t>cls_def) | 598 | #_smart_classes.append(<uintptr_t>cls_def) |
596 | self._set_obj(evas_object_smart_add(canvas.obj, smart.cls)) | 599 | self._set_obj(evas_object_smart_add(canvas.obj, smart.cls)) |
@@ -749,7 +752,8 @@ cdef class SmartObject(Object): | |||
749 | if isinstance(event, unicode): event = PyUnicode_AsUTF8String(event) | 752 | if isinstance(event, unicode): event = PyUnicode_AsUTF8String(event) |
750 | 753 | ||
751 | spec = (event_conv, func, args, kargs) | 754 | spec = (event_conv, func, args, kargs) |
752 | Py_INCREF(spec) | 755 | self._owned_references.append(spec) |
756 | #Py_INCREF(spec) | ||
753 | 757 | ||
754 | evas_object_smart_callback_add(self.obj, | 758 | evas_object_smart_callback_add(self.obj, |
755 | <const char *>event if event is not None else NULL, | 759 | <const char *>event if event is not None else NULL, |
@@ -789,7 +793,8 @@ cdef class SmartObject(Object): | |||
789 | return 1 | 793 | return 1 |
790 | else: | 794 | else: |
791 | spec = <tuple>tmp | 795 | spec = <tuple>tmp |
792 | Py_DECREF(spec) | 796 | self._owned_references.remove(spec) |
797 | #Py_DECREF(spec) | ||
793 | 798 | ||
794 | return 1 | 799 | return 1 |
795 | 800 | ||
diff --git a/include/efl.evas.pxd b/include/efl.evas.pxd index ffb3170..6eebd65 100644 --- a/include/efl.evas.pxd +++ b/include/efl.evas.pxd | |||
@@ -1205,11 +1205,13 @@ cdef class Textblock(Object): | |||
1205 | 1205 | ||
1206 | 1206 | ||
1207 | cdef class SmartObject(Object): | 1207 | cdef class SmartObject(Object): |
1208 | cdef int _set_obj(self, cEo *obj) except 0 | 1208 | cdef: |
1209 | cdef int _callback_add_full(self, event, event_conv, func, tuple args, dict kargs) except 0 | 1209 | list _owned_references |
1210 | cdef int _callback_del_full(self, event, event_conv, func) except 0 | 1210 | int _set_obj(self, cEo *obj) except 0 |
1211 | cdef int _callback_add(self, event, func, args, kargs) except 0 | 1211 | int _callback_add_full(self, event, event_conv, func, tuple args, dict kargs) except 0 |
1212 | cdef int _callback_del(self, event, func) except 0 | 1212 | int _callback_del_full(self, event, event_conv, func) except 0 |
1213 | int _callback_add(self, event, func, args, kargs) except 0 | ||
1214 | int _callback_del(self, event, func) except 0 | ||
1213 | 1215 | ||
1214 | 1216 | ||
1215 | cdef class ClippedSmartObject(SmartObject): | 1217 | cdef class ClippedSmartObject(SmartObject): |