change ui_reg_destructor behavior: registered destructors are called before the context mempool is destroyed default tip

Sun, 19 Apr 2026 20:05:11 +0200

author
Olaf Wintermann <olaf.wintermann@gmail.com>
date
Sun, 19 Apr 2026 20:05:11 +0200
changeset 1097
d44c895e9ee9
parent 1096
655349c3021e

change ui_reg_destructor behavior: registered destructors are called before the context mempool is destroyed

ui/common/context.c file | annotate | diff | comparison | revisions
ui/common/context.h file | annotate | diff | comparison | revisions
ui/common/object.c file | annotate | diff | comparison | revisions
ui/ui/toolkit.h file | annotate | diff | comparison | revisions
--- a/ui/common/context.c	Sun Apr 19 15:25:45 2026 +0200
+++ b/ui/common/context.c	Sun Apr 19 20:05:11 2026 +0200
@@ -108,16 +108,23 @@
     }
     
     UiEvent ev;
-    ev.window = NULL;
+    ev.obj = ctx->obj;
+    ev.window = ev.obj ? ev.obj->window : NULL;
     ev.document = document;
-    ev.obj = NULL;
     ev.eventdata = NULL;
     ev.eventdatatype = 0;
     ev.intval = 0;
+    ev.set = 0;
 
     if(ctx->close_callback) {
         ctx->close_callback(&ev, ctx->close_data);
     }
+    
+    CxIterator i = cxListIterator(ctx->destroy_handler);
+    cx_foreach(UiDestroyHandler *, h, i) {
+        h->destructor(h->data);
+    }
+    
     cxMempoolFree(ctx->mp);
 }
 
@@ -552,14 +559,6 @@
     ctx->close_data = udata;
 }
 
-void ui_context_destroy(UiContext *ctx) {
-    CxIterator i = cxListIterator(ctx->destroy_handler);
-    cx_foreach(UiDestroyHandler *, h, i) {
-        h->destructor(h->data);
-    }
-    cxMempoolFree(ctx->mp);
-}
-
 UiContext* ui_context_parent(UiContext *ctx) {
     return ctx->parent;
 }
@@ -730,7 +729,8 @@
 }
 
 void  ui_reg_destructor(UiContext *ctx, void *data, ui_destructor_func destr) {
-    cxMempoolRegister(ctx->mp, data, (cx_destructor_func)destr);
+    //cxMempoolRegister(ctx->mp, data, (cx_destructor_func)destr);
+    uic_context_add_destructor(ctx, destr, data);
 }
 
 void  ui_set_destructor(void *mem, ui_destructor_func destr) {
--- a/ui/common/context.h	Sun Apr 19 15:25:45 2026 +0200
+++ b/ui/common/context.h	Sun Apr 19 20:05:11 2026 +0200
@@ -62,7 +62,7 @@
 struct UiContext {
     UiContext     *parent;
     UiObject      *obj;
-    CxMempool *mp;
+    CxMempool     *mp;
     const CxAllocator *allocator;
     CxList *destroy_handler;
     
--- a/ui/common/object.c	Sun Apr 19 15:25:45 2026 +0200
+++ b/ui/common/object.c	Sun Apr 19 20:05:11 2026 +0200
@@ -98,18 +98,8 @@
 }
 
 void uic_object_destroy(UiObject *obj) {
-    if(obj->ctx->close_callback) {
-        UiEvent ev;
-        ev.window = obj->window;
-        ev.document = obj->ctx->document;
-        ev.obj = obj;
-        ev.eventdata = NULL;
-        ev.eventdatatype = 0;
-        ev.intval = 0;
-        obj->ctx->close_callback(&ev, obj->ctx->close_data);
-    }
     uic_object_destroyed(obj);
-    cxMempoolFree(obj->ctx->mp);
+    uic_context_destroy(obj->ctx, obj->ctx->document);
 }
 
 UiObject* uic_object_new_toplevel(void) {
--- a/ui/ui/toolkit.h	Sun Apr 19 15:25:45 2026 +0200
+++ b/ui/ui/toolkit.h	Sun Apr 19 20:05:11 2026 +0200
@@ -539,8 +539,6 @@
 
 UIEXPORT void ui_context_closefunc(UiContext *ctx, ui_callback fnc, void *udata);
 
-UIEXPORT void ui_context_destroy(UiContext *ctx);
-
 UIEXPORT UiContext* ui_context_parent(UiContext *ctx);
 
 UIEXPORT void ui_object_ref(UiObject *obj);

mercurial