Move the Mac port over to using snew/snewn/sresize.
authorben <ben@cda61777-01e9-0310-a592-d414129be87e>
Sat, 29 Mar 2003 23:07:55 +0000 (23:07 +0000)
committerben <ben@cda61777-01e9-0310-a592-d414129be87e>
Sat, 29 Mar 2003 23:07:55 +0000 (23:07 +0000)
git-svn-id: svn://svn.tartarus.org/sgt/putty@3024 cda61777-01e9-0310-a592-d414129be87e

mac/macabout.c
mac/macctrls.c
mac/macdlg.c
mac/macevlog.c
mac/macmisc.c
mac/macpgkey.c
mac/macstore.c
mac/macterm.c
mac/mtcpnet.c
mac/otnet.c

index af92b55..3b7732d 100644 (file)
@@ -1,4 +1,4 @@
-/* $Id: macabout.c,v 1.2 2003/02/16 13:44:18 ben Exp $ */
+/* $Id: macabout.c,v 1.3 2003/03/29 23:07:55 ben Exp $ */
 /*
  * Copyright (c) 1999, 2002, 2003 Ben Harris
  * All rights reserved.
@@ -149,7 +149,7 @@ void mac_openabout(void)
     else {
        windows.about =
            GetDialogWindow(GetNewDialog(wAbout, NULL, (WindowPtr)-1));
-       wi = smalloc(sizeof(*wi));
+       wi = snew(WinInfo);
        memset(wi, 0, sizeof(*wi));
        wi->wtype = wAbout;
        wi->update = &mac_updateabout;
@@ -177,7 +177,7 @@ static void mac_openlicence(void)
        SelectWindow(windows.licence);
     else {
        windows.licence = GetNewWindow(wLicence, NULL, (WindowPtr)-1);
-       wi = smalloc(sizeof(*wi));
+       wi = snew(WinInfo);
        memset(wi, 0, sizeof(*wi));
        wi->wtype = wLicence;
        wi->update = &mac_updatelicence;
index 24b8775..5390c8a 100644 (file)
@@ -1,4 +1,4 @@
-/* $Id: macctrls.c,v 1.20 2003/03/29 22:04:21 ben Exp $ */
+/* $Id: macctrls.c,v 1.21 2003/03/29 23:07:55 ben Exp $ */
 /*
  * Copyright (c) 2003 Ben Harris
  * All rights reserved.
@@ -223,7 +223,7 @@ void macctrl_layoutbox(struct controlbox *cb, WindowPtr window,
     for (i = 1; i < cb->nctrlsets; i++)
        if (strcmp(cb->ctrlsets[i]->pathname, cb->ctrlsets[i-1]->pathname))
            mcs->npanels++;
-    mcs->panels = smalloc(sizeof(*mcs->panels) * mcs->npanels);
+    mcs->panels = snewn(mcs->npanels, union macctrl *);
     memset(mcs->panels, 0, sizeof(*mcs->panels) * mcs->npanels);
     curstate.panelnum = 0;
     for (i = 0; i < cb->nctrlsets; i++) {
@@ -379,7 +379,7 @@ static void macctrl_text(struct macctrls *mcs, WindowPtr window,
                         struct mac_layoutstate *curstate,
                         union control *ctrl)
 {
-    union macctrl *mc = smalloc(sizeof *mc);
+    union macctrl *mc = snew(union macctrl);
     Rect bounds;
     SInt16 height;
 
@@ -426,7 +426,7 @@ static void macctrl_editbox(struct macctrls *mcs, WindowPtr window,
                            struct mac_layoutstate *curstate,
                            union control *ctrl)
 {
-    union macctrl *mc = smalloc(sizeof *mc);
+    union macctrl *mc = snew(union macctrl);
     Rect lbounds, bounds;
 
     fprintf(stderr, "    label = %s\n", ctrl->editbox.label);
@@ -553,7 +553,7 @@ static void macctrl_radio(struct macctrls *mcs, WindowPtr window,
                          struct mac_layoutstate *curstate,
                          union control *ctrl)
 {
-    union macctrl *mc = smalloc(sizeof *mc);
+    union macctrl *mc = snew(union macctrl);
     Rect bounds;
     Str255 title;
     unsigned int i, colwidth;
@@ -562,8 +562,7 @@ static void macctrl_radio(struct macctrls *mcs, WindowPtr window,
     mc->generic.type = MACCTRL_RADIO;
     mc->generic.ctrl = ctrl;
     mc->generic.privdata = NULL;
-    mc->radio.tbctrls =
-       smalloc(sizeof(*mc->radio.tbctrls) * ctrl->radio.nbuttons);
+    mc->radio.tbctrls = snewn(ctrl->radio.nbuttons, ControlRef);
     colwidth = (curstate->width + 13) /        ctrl->radio.ncolumns;
     bounds.top = curstate->pos.v;
     bounds.bottom = bounds.top + 16;
@@ -611,7 +610,7 @@ static void macctrl_checkbox(struct macctrls *mcs, WindowPtr window,
                             struct mac_layoutstate *curstate,
                             union control *ctrl)
 {
-    union macctrl *mc = smalloc(sizeof *mc);
+    union macctrl *mc = snew(union macctrl);
     Rect bounds;
     Str255 title;
 
@@ -637,7 +636,7 @@ static void macctrl_button(struct macctrls *mcs, WindowPtr window,
                           struct mac_layoutstate *curstate,
                           union control *ctrl)
 {
-    union macctrl *mc = smalloc(sizeof *mc);
+    union macctrl *mc = snew(union macctrl);
     Rect bounds;
     Str255 title;
 
@@ -723,7 +722,7 @@ static void macctrl_popup(struct macctrls *mcs, WindowPtr window,
                          struct mac_layoutstate *curstate,
                          union control *ctrl)
 {
-    union macctrl *mc = smalloc(sizeof *mc);
+    union macctrl *mc = snew(union macctrl);
     Rect bounds;
     Str255 title;
     unsigned int labelwidth;
@@ -1299,8 +1298,7 @@ static void dlg_macpopup_addwithid(union control *ctrl, void *dlg,
     index = CountMenuItems(menu) - 1;
     if (mc->popup.nids <= index) {
        mc->popup.nids = index + 1;
-       mc->popup.ids = srealloc(mc->popup.ids,
-                                mc->popup.nids * sizeof(*mc->popup.ids));
+       mc->popup.ids = sresize(mc->popup.ids, mc->popup.nids, int);
     }
     mc->popup.ids[index] = id;
 }
index 93a2a3f..ec18aea 100644 (file)
@@ -1,4 +1,4 @@
-/* $Id: macdlg.c,v 1.16 2003/03/25 23:18:59 ben Exp $ */
+/* $Id: macdlg.c,v 1.17 2003/03/29 23:07:55 ben Exp $ */
 /*
  * Copyright (c) 2002 Ben Harris
  * All rights reserved.
@@ -54,7 +54,7 @@ void mac_newsession(void)
     WinInfo *wi;
     static struct sesslist sesslist;
 
-    s = smalloc(sizeof(*s));
+    s = snew(Session);
     memset(s, 0, sizeof(*s));
     do_defaults(NULL, &s->cfg);
     s->hasfile = FALSE;
@@ -71,7 +71,7 @@ void mac_newsession(void)
     s->settings_ctrls.data = &s->cfg;
     macctrl_layoutbox(s->ctrlbox, s->settings_window, &s->settings_ctrls);
 
-    wi = smalloc(sizeof(*wi));
+    wi = snew(WinInfo);
     memset(wi, 0, sizeof(*wi));
     wi->s = s;
     wi->mcs = &s->settings_ctrls;
@@ -102,7 +102,7 @@ void mac_dupsession(void)
     Session *s1 = mac_windowsession(FrontWindow());
     Session *s2;
 
-    s2 = smalloc(sizeof(*s2));
+    s2 = snew(Session);
     memset(s2, 0, sizeof(*s2));
     s2->cfg = s1->cfg;
     s2->hasfile = s1->hasfile;
@@ -118,7 +118,7 @@ static OSErr mac_opensessionfrom(FSSpec *fss)
     void *sesshandle;
     OSErr err;
 
-    s = smalloc(sizeof(*s));
+    s = snew(Session);
     memset(s, 0, sizeof(*s));
 
     err = FSpGetFInfo(fss, &fi);
index 7eb047e..60283ed 100644 (file)
@@ -1,4 +1,4 @@
-/* $Id: macevlog.c,v 1.5 2003/02/23 13:00:38 ben Exp $ */
+/* $Id: macevlog.c,v 1.6 2003/03/29 23:07:55 ben Exp $ */
 /*
  * Copyright (c) 2003 Ben Harris
  * All rights reserved.
@@ -58,7 +58,7 @@ static void mac_createeventlog(Session *s)
     WinInfo *wi;
 
     s->eventlog_window = GetNewWindow(wEventLog, NULL, (WindowPtr)-1);
-    wi = smalloc(sizeof(*wi));
+    wi = snew(WinInfo);
     memset(wi, 0, sizeof(*wi));
     wi->s = s;
     wi->wtype = wEventLog;
index b247978..7255b3d 100644 (file)
@@ -1,4 +1,4 @@
-/* $Id: macmisc.c,v 1.2 2003/02/20 22:31:52 ben Exp $ */
+/* $Id: macmisc.c,v 1.3 2003/03/29 23:07:55 ben Exp $ */
 /*
  * Copyright (c) 1999, 2003 Ben Harris
  * All rights reserved.
@@ -119,7 +119,7 @@ const char *filename_to_str(const Filename *fn)
     char *newpath;
 
     if (path != NULL) sfree(path);
-    path = smalloc(fn->fss.name[0]);
+    path = snewn(fn->fss.name[0], char);
     p2cstrcpy(path, fn->fss.name);
     pb.dirInfo.ioNamePtr = dirname;
     pb.dirInfo.ioVRefNum = fn->fss.vRefNum;
@@ -130,7 +130,7 @@ const char *filename_to_str(const Filename *fn)
        err = PBGetCatInfoSync(&pb);
 
        /* XXX Assume not A/UX */
-       newpath = smalloc(strlen(path) + dirname[0] + 2);
+       newpath = snewn(strlen(path) + dirname[0] + 2, char);
        p2cstrcpy(newpath, dirname);
        strcat(newpath, ":");
        strcat(newpath, path);
index a174067..49809fc 100644 (file)
@@ -1,4 +1,4 @@
-/* $Id: macpgkey.c,v 1.3 2003/02/20 22:55:09 ben Exp $ */
+/* $Id: macpgkey.c,v 1.4 2003/03/29 23:07:55 ben Exp $ */
 /*
  * Copyright (c) 2003 Ben Harris
  * Copyright (c) 1997-2003 Simon Tatham
@@ -123,7 +123,7 @@ static void mac_clickkey(WindowPtr window, EventRecord *event)
        switch (item) {
          case wiKeyGenerate:
            SetControlMaximum(ks->progress, 1024);
-           ks->entropy = smalloc(1024 * sizeof(*ks->entropy));
+           ks->entropy = snewn(1024, long);
            ks->entropy_required = 1024;
            ks->entropy_got = 0;
            ks->collecting_entropy = TRUE;
@@ -174,11 +174,11 @@ void mac_newkey(void)
     short type;
     Rect rect;
 
-    ks = smalloc(sizeof(*ks));
+    ks = snew(KeyState);
     ks->box = GetNewDialog(wKey, NULL, (WindowPtr)-1);
     GetDialogItem(ks->box, wiKeyProgress, &type, &h, &rect);
     ks->progress = (ControlHandle)h;
-    wi = smalloc(sizeof(*wi));
+    wi = snew(WinInfo);
     memset(wi, 0, sizeof(*wi));
     wi->ks = ks;
     wi->wtype = wKey;
index 30eb1cf..5425efa 100644 (file)
@@ -1,4 +1,4 @@
-/* $Id: macstore.c,v 1.17 2003/03/27 22:46:28 ben Exp $ */
+/* $Id: macstore.c,v 1.18 2003/03/29 23:07:55 ben Exp $ */
 
 /*
  * macstore.c: Macintosh-specific impementation of the interface
@@ -149,7 +149,7 @@ void *open_settings_w_fsp(FSSpec *dstfile)
     OSErr error;
     Str255 tmpname;
 
-    ws = smalloc(sizeof *ws);
+    ws = snew(struct write_settings);
     ws->dstfile = *dstfile;
 
     /* Create a temporary file to save to first. */
@@ -278,7 +278,7 @@ void *open_settings_r_fsp(FSSpec *sessfile)
     fd = FSpOpenResFile(sessfile, fsRdPerm);
     if (fd == 0) {error = ResError(); goto out;}
 
-    handle = smalloc(sizeof *handle);
+    handle = snew(int);
     *handle = fd;
     return handle;
 
index d04abd3..b9478e9 100644 (file)
@@ -1,4 +1,4 @@
-/* $Id: macterm.c,v 1.71 2003/02/15 16:22:15 ben Exp $ */
+/* $Id: macterm.c,v 1.72 2003/03/29 23:07:55 ben Exp $ */
 /*
  * Copyright (c) 1999 Simon Tatham
  * Copyright (c) 1999, 2002 Ben Harris
@@ -129,7 +129,7 @@ void mac_startsession(Session *s)
        s->window = GetNewCWindow(wTerminal, NULL, (WindowPtr)-1);
     else
        s->window = GetNewWindow(wTerminal, NULL, (WindowPtr)-1);
-    wi = smalloc(sizeof(*wi));
+    wi = snew(WinInfo);
     memset(wi, 0, sizeof(*wi));
     wi->s = s;
     wi->wtype = wTerminal;
@@ -629,7 +629,7 @@ void write_clip(void *cookie, wchar_t *data, int len, int must_deselect)
        if (data[i] == 0x2028)
            data[i] = 0x000d;
 
-    mactextbuf = smalloc(len); /* XXX DBCS */
+    mactextbuf = snewn(len, char); /* XXX DBCS */
     if (s->uni_to_font != NULL) {
        err = ConvertFromUnicodeToText(s->uni_to_font, len * sizeof(UniChar),
                                       (UniChar *)data,
@@ -702,7 +702,7 @@ void get_clip(void *frontend, wchar_t **p, int *lenp)
            texth = NewHandle(0);
            textlen = GetScrap(texth, kScrapFlavorTypeText, &offset);
            HLock(texth);
-           data = smalloc(textlen * 2);
+           data = snewn(textlen, wchar_t);
            /* XXX should use 'styl' scrap if it's there. */
            if (mac_gestalts.encvvers != 0 &&
                UpgradeScriptInfoToTextEncoding(smSystemScript,
index 754ce18..7644ddf 100644 (file)
@@ -275,7 +275,7 @@ static ResultUPP mactcp_lookupdone_upp;
 
 SockAddr mactcp_namelookup(char const *host, char **canonicalname)
 {
-    SockAddr ret = smalloc(sizeof(struct SockAddr_tag));
+    SockAddr ret = snew(struct SockAddr_tag);
     OSErr err;
     volatile int done = FALSE;
     char *realhost;
@@ -305,7 +305,7 @@ SockAddr mactcp_namelookup(char const *host, char **canonicalname)
            realhost[realhostlen - 1] = '\0';
     } else
        realhost = "";
-    *canonicalname = smalloc(1+strlen(realhost));
+    *canonicalname = snewn(1 + strlen(realhost), char);
     strcpy(*canonicalname, realhost);
     return ret;
 }
@@ -319,7 +319,7 @@ static pascal void mactcp_lookupdone(struct hostInfo *hi, char *cookie)
 
 SockAddr mactcp_nonamelookup(char const *host)
 {
-    SockAddr ret = smalloc(sizeof(struct SockAddr_tag));
+    SockAddr ret = snew(struct SockAddr_tag);
 
     ret->resolved = FALSE;
     ret->hostinfo.rtnCode = noErr;
@@ -432,7 +432,7 @@ Socket mactcp_new(SockAddr addr, int port, int privport, int oobinline,
     /*
      * Create Socket structure.
      */
-    ret = smalloc(sizeof(struct Socket_tag));
+    ret = snew(struct Socket_tag);
     ret->s = 0;
     ret->fn = &fn_table;
     ret->err = noErr;
@@ -473,7 +473,7 @@ Socket mactcp_new(SockAddr addr, int port, int privport, int oobinline,
     GetCurrentProcess(&mactcp.self);
     pb.ioCRefNum = mactcp.refnum;
     pb.csCode = TCPCreate;
-    pb.csParam.create.rcvBuff = smalloc(buflen);
+    pb.csParam.create.rcvBuff = snewn(buflen, char);
     pb.csParam.create.rcvBuffLen = buflen;
     pb.csParam.create.notifyProc = mactcp_asr_upp;
     pb.csParam.create.userDataPtr = (Ptr)ret;
index 06fbea2..809906b 100644 (file)
@@ -81,7 +81,7 @@ void ot_cleanup(void)
 
 SockAddr ot_namelookup(char const *host, char **canonicalname)
 {
-    SockAddr ret = smalloc(sizeof(struct SockAddr_tag));
+    SockAddr ret = snew(struct SockAddr_tag);
     char *realhost;
 
     /* Casting away const -- hope OTInetStringToAddress is sensible */
@@ -93,14 +93,14 @@ SockAddr ot_namelookup(char const *host, char **canonicalname)
        realhost = ret->hostinfo.name;
     else
        realhost = "";
-    *canonicalname = smalloc(1+strlen(realhost));
+    *canonicalname = snewn(1+strlen(realhost), char);
     strcpy(*canonicalname, realhost);
     return ret;
 }
 
 SockAddr ot_nonamelookup(char const *host)
 {
-    SockAddr ret = smalloc(sizeof(struct SockAddr_tag));
+    SockAddr ret = snew(struct SockAddr_tag);
     
     ret->resolved = FALSE;
     ret->error = kOTNoError;
@@ -205,7 +205,7 @@ Socket ot_register(void *sock, Plug plug)
     
     Actual_Socket ret;
 
-    ret = smalloc(sizeof(struct Socket_tag));
+    ret = snew(struct Socket_tag);
     ret->fn = &fn_table;
     ret->error = kOTNoError;
     ret->plug = plug;
@@ -254,7 +254,7 @@ Socket ot_new(SockAddr addr, int port, int privport, int oobinline,
     InetAddress dest;
     TCall connectCall;
 
-    ret = smalloc(sizeof(struct Socket_tag));
+    ret = snew(struct Socket_tag);
     ret->fn = &fn_table;
     ret->error = kOTNoError;
     ret->plug = plug;