From: Simon Tatham Date: Fri, 8 May 2015 18:04:16 +0000 (+0100) Subject: Completely remove the privdata mechanism in dialog.h. X-Git-Tag: 0.65~16 X-Git-Url: https://asedeno.scripts.mit.edu/gitweb/?a=commitdiff_plain;h=3ba1a7cf4b469ceded01c33ec5b76b7e8714d035;p=PuTTY.git Completely remove the privdata mechanism in dialog.h. The last use of it, to store the contents of the saved session name edit box, was removed nearly two years ago in svn r9923 and replaced by ctrl_alloc_with_free. The mechanism has been unused ever since then, and I suspect any further uses of it would be a bad idea for the same reasons, so let's get rid of it. (cherry picked from commit 42c592c4ef024af30af91241f651f699d6dbff0b) --- diff --git a/dialog.h b/dialog.h index 6f454f56..67751670 100644 --- a/dialog.h +++ b/dialog.h @@ -634,21 +634,6 @@ int dlg_coloursel_results(union control *ctrl, void *dlg, */ void dlg_refresh(union control *ctrl, void *dlg); -/* - * It's perfectly possible that individual controls might need to - * allocate or store per-dialog-instance data, so here's a - * mechanism. - * - * `dlg_get_privdata' and `dlg_set_privdata' allow the user to get - * and set a void * pointer associated with the control in - * question. `dlg_alloc_privdata' will allocate memory, store a - * pointer to that memory in the private data field, and arrange - * for it to be automatically deallocated on dialog cleanup. - */ -void *dlg_get_privdata(union control *ctrl, void *dlg); -void dlg_set_privdata(union control *ctrl, void *dlg, void *ptr); -void *dlg_alloc_privdata(union control *ctrl, void *dlg, size_t size); - /* * Standard helper functions for reading a controlbox structure. */ diff --git a/macosx/osxctrls.m b/macosx/osxctrls.m index 12e813c9..b4270f9d 100644 --- a/macosx/osxctrls.m +++ b/macosx/osxctrls.m @@ -243,8 +243,6 @@ struct fe_ctrl { NSTableView *tableview; NSScrollView *scrollview; int nradiobuttons; - void *privdata; - int privdata_needs_free; }; static int fe_ctrl_cmp_by_ctrl(void *av, void *bv) @@ -346,16 +344,12 @@ static struct fe_ctrl *fe_ctrl_new(union control *ctrl) c->scrollview = nil; c->radiobuttons = NULL; c->nradiobuttons = 0; - c->privdata = NULL; - c->privdata_needs_free = FALSE; return c; } static void fe_ctrl_free(struct fe_ctrl *c) { - if (c->privdata_needs_free) - sfree(c->privdata); sfree(c->radiobuttons); sfree(c); } @@ -1785,31 +1779,3 @@ void dlg_refresh(union control *ctrl, void *dv) } } } - -void *dlg_get_privdata(union control *ctrl, void *dv) -{ - struct fe_dlg *d = (struct fe_dlg *)dv; - struct fe_ctrl *c = fe_ctrl_byctrl(d, ctrl); - return c->privdata; -} - -void dlg_set_privdata(union control *ctrl, void *dv, void *ptr) -{ - struct fe_dlg *d = (struct fe_dlg *)dv; - struct fe_ctrl *c = fe_ctrl_byctrl(d, ctrl); - c->privdata = ptr; - c->privdata_needs_free = FALSE; -} - -void *dlg_alloc_privdata(union control *ctrl, void *dv, size_t size) -{ - struct fe_dlg *d = (struct fe_dlg *)dv; - struct fe_ctrl *c = fe_ctrl_byctrl(d, ctrl); - /* - * This is an internal allocation routine, so it's allowed to - * use smalloc directly. - */ - c->privdata = smalloc(size); - c->privdata_needs_free = TRUE; - return c->privdata; -} diff --git a/unix/gtkdlg.c b/unix/gtkdlg.c index 2b8fec17..86a71cd6 100644 --- a/unix/gtkdlg.c +++ b/unix/gtkdlg.c @@ -37,8 +37,6 @@ struct Shortcuts { struct uctrl { union control *ctrl; GtkWidget *toplevel; - void *privdata; - int privdata_needs_free; GtkWidget **buttons; int nbuttons; /* for radio buttons */ GtkWidget *entry; /* for editbox, filesel, fontsel */ GtkWidget *button; /* for filesel, fontsel */ @@ -189,8 +187,6 @@ static void dlg_cleanup(struct dlgparam *dp) dp->byctrl = NULL; while ( (uc = index234(dp->bywidget, 0)) != NULL) { del234(dp->bywidget, uc); - if (uc->privdata_needs_free) - sfree(uc->privdata); sfree(uc->buttons); sfree(uc); } @@ -228,34 +224,6 @@ static struct uctrl *dlg_find_bywidget(struct dlgparam *dp, GtkWidget *w) return ret; } -void *dlg_get_privdata(union control *ctrl, void *dlg) -{ - struct dlgparam *dp = (struct dlgparam *)dlg; - struct uctrl *uc = dlg_find_byctrl(dp, ctrl); - return uc->privdata; -} - -void dlg_set_privdata(union control *ctrl, void *dlg, void *ptr) -{ - struct dlgparam *dp = (struct dlgparam *)dlg; - struct uctrl *uc = dlg_find_byctrl(dp, ctrl); - uc->privdata = ptr; - uc->privdata_needs_free = FALSE; -} - -void *dlg_alloc_privdata(union control *ctrl, void *dlg, size_t size) -{ - struct dlgparam *dp = (struct dlgparam *)dlg; - struct uctrl *uc = dlg_find_byctrl(dp, ctrl); - /* - * This is an internal allocation routine, so it's allowed to - * use smalloc directly. - */ - uc->privdata = smalloc(size); - uc->privdata_needs_free = FALSE; - return uc->privdata; -} - union control *dlg_last_focused(union control *ctrl, void *dlg) { struct dlgparam *dp = (struct dlgparam *)dlg; @@ -1832,8 +1800,6 @@ GtkWidget *layout_ctrls(struct dlgparam *dp, struct Shortcuts *scs, uc = snew(struct uctrl); uc->ctrl = ctrl; - uc->privdata = NULL; - uc->privdata_needs_free = FALSE; uc->buttons = NULL; uc->entry = NULL; #if !GTK_CHECK_VERSION(2,4,0) diff --git a/windows/winctrls.c b/windows/winctrls.c index 49c13e8d..9bee9274 100644 --- a/windows/winctrls.c +++ b/windows/winctrls.c @@ -2532,23 +2532,6 @@ void dlg_set_fixed_pitch_flag(void *dlg, int flag) dp->fixed_pitch_fonts = flag; } -struct perctrl_privdata { - union control *ctrl; - void *data; - int needs_free; -}; - -static int perctrl_privdata_cmp(void *av, void *bv) -{ - struct perctrl_privdata *a = (struct perctrl_privdata *)av; - struct perctrl_privdata *b = (struct perctrl_privdata *)bv; - if (a->ctrl < b->ctrl) - return -1; - else if (a->ctrl > b->ctrl) - return +1; - return 0; -} - void dp_init(struct dlgparam *dp) { dp->nctrltrees = 0; @@ -2558,7 +2541,6 @@ void dp_init(struct dlgparam *dp) memset(dp->shortcuts, 0, sizeof(dp->shortcuts)); dp->hwnd = NULL; dp->wintitle = dp->errtitle = NULL; - dp->privdata = newtree234(perctrl_privdata_cmp); dp->fixed_pitch_fonts = TRUE; } @@ -2570,67 +2552,6 @@ void dp_add_tree(struct dlgparam *dp, struct winctrls *wc) void dp_cleanup(struct dlgparam *dp) { - struct perctrl_privdata *p; - - if (dp->privdata) { - while ( (p = index234(dp->privdata, 0)) != NULL ) { - del234(dp->privdata, p); - if (p->needs_free) - sfree(p->data); - sfree(p); - } - freetree234(dp->privdata); - dp->privdata = NULL; - } sfree(dp->wintitle); sfree(dp->errtitle); } - -void *dlg_get_privdata(union control *ctrl, void *dlg) -{ - struct dlgparam *dp = (struct dlgparam *)dlg; - struct perctrl_privdata tmp, *p; - tmp.ctrl = ctrl; - p = find234(dp->privdata, &tmp, NULL); - if (p) - return p->data; - else - return NULL; -} - -void dlg_set_privdata(union control *ctrl, void *dlg, void *ptr) -{ - struct dlgparam *dp = (struct dlgparam *)dlg; - struct perctrl_privdata tmp, *p; - tmp.ctrl = ctrl; - p = find234(dp->privdata, &tmp, NULL); - if (!p) { - p = snew(struct perctrl_privdata); - p->ctrl = ctrl; - p->needs_free = FALSE; - add234(dp->privdata, p); - } - p->data = ptr; -} - -void *dlg_alloc_privdata(union control *ctrl, void *dlg, size_t size) -{ - struct dlgparam *dp = (struct dlgparam *)dlg; - struct perctrl_privdata tmp, *p; - tmp.ctrl = ctrl; - p = find234(dp->privdata, &tmp, NULL); - if (!p) { - p = snew(struct perctrl_privdata); - p->ctrl = ctrl; - p->needs_free = FALSE; - add234(dp->privdata, p); - } - assert(!p->needs_free); - p->needs_free = TRUE; - /* - * This is an internal allocation routine, so it's allowed to - * use smalloc directly. - */ - p->data = smalloc(size); - return p->data; -}