Changeset c394de8


Ignore:
Timestamp:
Sep 18, 2010, 5:07:40 PM (14 years ago)
Author:
David Benjamin <davidben@mit.edu>
Branches:
master, release-1.10, release-1.7, release-1.8, release-1.9
Children:
fc5eef4
Parents:
9190285
git-author:
David Benjamin <davidben@mit.edu> (08/14/10 01:15:47)
git-committer:
David Benjamin <davidben@mit.edu> (09/18/10 17:07:40)
Message:
Use ref-counting to make editwin ownership saner

When creating an editwin, one creates an editcontext which takes a
reference to the editwin. Likewise, the pointer in owl_global holds
reference. The reference counting manages their ownership claims. In
addition, owl_global_set_typwin_inactive now does release a reference.

Instead, the callback-calling commands take a reference and release it
later. We may wish to further improve that so that the contexts are also
ref-counted such that, when their commands are running, they will not be
deallocated, even if popped. That will avoid the callback dance.
Files:
1 added
4 edited

Legend:

Unmodified
Added
Removed
  • Makefile.am

    rd296c9a rc394de8  
    4646     aim.c buddy.c buddylist.c style.c errqueue.c \
    4747     zbuddylist.c popexec.c select.c wcwidth.c \
    48      glib_compat.c mainpanel.c msgwin.c sepbar.c
     48     glib_compat.c mainpanel.c msgwin.c sepbar.c editcontext.c
    4949
    5050NORMAL_SRCS = filterproc.c window.c windowcb.c
  • commands.c

    r9190285 rc394de8  
    26932693
    26942694  owl_global_set_typwin_inactive(&g);
    2695   owl_editwin_unref(e);
    26962695}
    26972696
     
    27462745  }
    27472746
     2747  /* Take a reference to the editwin, so that it survives the pop
     2748   * context. TODO: We should perhaps refcount or otherwise protect
     2749   * the context so that, even if a command pops a context, the
     2750   * context itself will last until the command returns. */
     2751  owl_editwin_ref(e);
    27482752  owl_global_set_typwin_inactive(&g);
    27492753  owl_global_pop_context(&g);
  • functions.c

    r08263a8 rc394de8  
    274274{
    275275  owl_editwin *e;
     276  owl_context *ctx;
    276277  char *s;
    277278
     
    286287  owl_editwin_set_cbdata(e, data, cleanup);
    287288  owl_editwin_set_callback(e, callback);
    288   owl_global_push_context(&g, OWL_CTX_EDITMULTI, e, "editmulti", owl_editwin_get_window(e));
     289  ctx = owl_editcontext_new(OWL_CTX_EDITMULTI, e, "editmulti");
     290  owl_global_push_context_obj(&g, ctx);
     291
    289292}
    290293
     
    18811884{
    18821885  owl_editwin *tw;
     1886  owl_context *ctx;
    18831887
    18841888  tw = owl_global_set_typwin_active(&g, OWL_EDITWIN_STYLE_ONELINE, owl_global_get_cmd_history(&g));
     
    18881892  owl_editwin_insert_string(tw, line);
    18891893
    1890   owl_global_push_context(&g, OWL_CTX_EDITLINE, tw, "editline", owl_editwin_get_window(tw));
     1894  ctx = owl_editcontext_new(OWL_CTX_EDITLINE, tw, "editline");
     1895  owl_global_push_context_obj(&g, ctx);
    18911896  owl_editwin_set_callback(tw, owl_callback_command);
    18921897}
     
    18951900{
    18961901  owl_editwin *tw;
     1902  owl_context *ctx;
    18971903
    18981904  tw = owl_global_set_typwin_active(&g, OWL_EDITWIN_STYLE_ONELINE, owl_global_get_cmd_history(&g));
     
    19001906  owl_editwin_set_locktext(tw, line);
    19011907
    1902   owl_global_push_context(&g, OWL_CTX_EDITRESPONSE, tw, "editresponse", owl_editwin_get_window(tw));
     1908  ctx = owl_editcontext_new(OWL_CTX_EDITRESPONSE, tw, "editresponse");
     1909  owl_global_push_context_obj(&g, ctx);
    19031910  return tw;
    19041911}
     
    19071914{
    19081915  owl_editwin *tw;
     1916  owl_context *ctx;
    19091917
    19101918  tw = owl_global_set_typwin_active(&g, OWL_EDITWIN_STYLE_ONELINE, NULL);
     
    19141922  owl_editwin_set_locktext(tw, line);
    19151923
    1916   owl_global_push_context(&g, OWL_CTX_EDITRESPONSE, tw, "editresponse", owl_editwin_get_window(tw));
     1924  ctx = owl_editcontext_new(OWL_CTX_EDITRESPONSE, tw, "editresponse");
     1925  owl_global_push_context_obj(&g, ctx);
    19171926  return tw;
    19181927}
  • global.c

    r08263a8 rc394de8  
    285285owl_editwin *owl_global_current_typwin(const owl_global *g) {
    286286  owl_context *ctx = owl_global_get_context(g);
    287   /* Get the current editwin from the context. */
    288   if (ctx && owl_context_matches(ctx, OWL_CTX_TYPWIN)) {
    289     return owl_context_get_data(ctx);
    290   }
    291   return NULL;
     287  return owl_editcontext_get_editwin(ctx);
    292288}
    293289
     
    347343  owl_window_dirty(g->mainpanel.typwin);
    348344
     345  owl_editwin_unref(g->tw);
    349346  g->tw = NULL;
    350347}
Note: See TracChangeset for help on using the changeset viewer.