Changeset 1b1cd2c


Ignore:
Timestamp:
Mar 23, 2010, 5:23:43 PM (14 years ago)
Author:
Nelson Elhage <nelhage@ksplice.com>
Branches:
master, release-1.10, release-1.6, release-1.7, release-1.8, release-1.9
Children:
8dfb59c
Parents:
6b78afb
git-author:
Nelson Elhage <nelhage@mit.edu> (03/13/10 21:18:03)
git-committer:
Nelson Elhage <nelhage@ksplice.com> (03/23/10 17:23:43)
Message:
Editwin: Add a callback to destroy cbdata
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • editwin.c

    rf449096 r1b1cd2c  
    3737  char *command;
    3838  void (*callback)(struct _owl_editwin*);
     39  void (*destroy_cbdata)(void *);
    3940  void *cbdata;
    4041};
     
    5859static int oe_copy_region(owl_editwin *e);
    5960static char *oe_chunk(owl_editwin *e, int start, int end);
     61static void oe_destroy_cbdata(owl_editwin *e);
    6062
    6163#define INCR 4096
     
    145147  e->echochar='\0';
    146148
    147   /* We get initialized multiple times, but we need to hold on to
    148      the callbacks, so we can't NULL them here. */
    149   /*
    150     e->command = NULL;
    151     e->callback = NULL;
    152     e->cbdata = NULL;
    153   */
    154149  if (win) werase(win);
    155150}
     
    210205}
    211206
    212 void owl_editwin_set_cbdata(owl_editwin *e, void *data)
    213 {
     207static void oe_destroy_cbdata(owl_editwin *e) {
     208  if (e->destroy_cbdata)
     209    e->destroy_cbdata(e->cbdata);
     210  e->cbdata = NULL;
     211  e->destroy_cbdata = NULL;
     212}
     213
     214void owl_editwin_set_cbdata(owl_editwin *e, void *data, void (*destroy)(void *))
     215{
     216  oe_destroy_cbdata(e);
    214217  e->cbdata = data;
     218  e->destroy_cbdata = destroy;
    215219}
    216220
     
    282286  owl_free(e->buff);
    283287  owl_editwin_init(e, e->curswin, e->winlines, e->wincols, e->style, e->hist);
     288  e->callback = NULL;
     289  oe_destroy_cbdata(e);
    284290}
    285291
  • functions.c

    r6b78afb r1b1cd2c  
    277277}
    278278
    279 void owl_function_start_edit_win(const char *line, void (*callback)(owl_editwin *), void *data)
     279void owl_function_start_edit_win(const char *line, void (*callback)(owl_editwin *), void *data, void (*cleanup)(void *))
    280280{
    281281  owl_editwin *e;
     
    295295  owl_global_set_typwin_active(&g);
    296296
    297   owl_editwin_set_cbdata(owl_global_get_typwin(&g), data);
     297  owl_editwin_set_cbdata(owl_global_get_typwin(&g), data, cleanup);
    298298  owl_global_set_buffercallback(&g, callback);
    299299  owl_global_push_context(&g, OWL_CTX_EDITMULTI, e, "editmulti");
     
    312312                         noun);
    313313
    314   owl_function_start_edit_win(line, callback, NULL);
     314  owl_function_start_edit_win(line, callback, NULL, NULL);
    315315  owl_global_set_buffercommand(&g, line);
    316316}
  • perlconfig.c

    r8f2d9bf r1b1cd2c  
    574574  FREETMPS;
    575575  LEAVE;
    576 
    577   SvREFCNT_dec(cb);
    578   owl_editwin_set_cbdata(e, NULL);
     576}
     577
     578void owl_perlconfig_dec_refcnt(void *data)
     579{
     580  SV *v = data;
     581  SvREFCNT_dec(v);
    579582}
    580583
  • perlglue.xs

    r8c59178 r1b1cd2c  
    179179                owl_function_start_question(line);
    180180
    181                 owl_editwin_set_cbdata(owl_global_get_typwin(&g), newSVsv(callback));
     181                owl_editwin_set_cbdata(owl_global_get_typwin(&g),
     182                                       newSVsv(callback),
     183                                       owl_perlconfig_dec_refcnt);
    182184                owl_editwin_set_callback(owl_global_get_typwin(&g), owl_perlconfig_edit_callback);
    183185        }
     
    195197                owl_function_start_password(line);
    196198
    197                 owl_editwin_set_cbdata(owl_global_get_typwin(&g), newSVsv(callback));
     199                owl_editwin_set_cbdata(owl_global_get_typwin(&g),
     200                                       newSVsv(callback),
     201                                       owl_perlconfig_dec_refcnt);
    198202                owl_editwin_set_callback(owl_global_get_typwin(&g), owl_perlconfig_edit_callback);
    199203        }
     
    208212                        croak("Callback must be a subref");
    209213
    210                 owl_function_start_edit_win(line, owl_perlconfig_edit_callback, newSVsv(callback));
     214                owl_function_start_edit_win(line,
     215                                            owl_perlconfig_edit_callback,
     216                                            newSVsv(callback),
     217                                            owl_perlconfig_dec_refcnt);
    211218        }
    212219
Note: See TracChangeset for help on using the changeset viewer.