Author: toshok
Date: 2007-11-20 15:17:55 -0500 (Tue, 20 Nov 2007)
New Revision: 90025
Modified:
trunk/moon/src/ChangeLog
trunk/moon/src/dependencyobject.cpp
Log:
2007-11-20 Chris Toshok <[EMAIL PROTECTED]>
* dependencyobject.cpp: add a ctor for EventClosure, and do a deep
copy before emitting an event.
Modified: trunk/moon/src/ChangeLog
===================================================================
--- trunk/moon/src/ChangeLog 2007-11-20 20:06:57 UTC (rev 90024)
+++ trunk/moon/src/ChangeLog 2007-11-20 20:17:55 UTC (rev 90025)
@@ -1,3 +1,8 @@
+2007-11-20 Chris Toshok <[EMAIL PROTECTED]>
+
+ * dependencyobject.cpp: add a ctor for EventClosure, and do a deep
+ copy before emitting an event.
+
2007-11-20 Jeffrey Stedfast <[EMAIL PROTECTED]>
* runtime.cpp (surface_get_toplevel): Removed.
Modified: trunk/moon/src/dependencyobject.cpp
===================================================================
--- trunk/moon/src/dependencyobject.cpp 2007-11-20 20:06:57 UTC (rev 90024)
+++ trunk/moon/src/dependencyobject.cpp 2007-11-20 20:17:55 UTC (rev 90025)
@@ -56,10 +56,12 @@
#endif
// event handlers for c++
-typedef struct {
+struct EventClosure {
+ EventClosure (EventHandler func, gpointer data) { this->func = func;
this->data = data; }
+
EventHandler func;
gpointer data;
-} EventClosure;
+};
int EventObject::DestroyedEvent = -1;
@@ -104,11 +106,7 @@
events = (GSList**)g_new0 (GSList*, GetType()->GetEventCount());
}
- EventClosure *closure = new EventClosure ();
- closure->func = handler;
- closure->data = data;
-
- events[event_id] = g_slist_append (events[event_id], closure);
+ events[event_id] = g_slist_append (events[event_id], new EventClosure
(handler, data));
}
void
@@ -173,7 +171,20 @@
if (events == NULL || events[event_id] == NULL)
return;
+ /* XXX yuck. this is 5 passes over the same length list.
+
+ 1 for g_slist_copy
+ 1 to deep copy the EventClosures in the list's data
+ 1 to emit
+ 1 to free up the deep copies
+ 1 to free the list
+ */
+
GSList *copy = g_slist_copy (events[event_id]);
+ for (GSList *l = copy; l; l = l->next) {
+ EventClosure *orig = (EventClosure*)l->data;
+ l->data = new EventClosure (orig->func, orig->data);
+ }
for (GSList *l = copy; l; l = l->next) {
EventClosure *closure = (EventClosure*)l->data;
@@ -181,6 +192,7 @@
closure->func (this, calldata, closure->data);
}
+ g_slist_foreach (copy, (GFunc)deleter, NULL);
g_slist_free (copy);
}
_______________________________________________
Mono-patches maillist - [email protected]
http://lists.ximian.com/mailman/listinfo/mono-patches