Switch the memory allocation macros from the Halibut ones
authorsimon <simon@cda61777-01e9-0310-a592-d414129be87e>
Sat, 12 Jun 2004 20:31:03 +0000 (20:31 +0000)
committersimon <simon@cda61777-01e9-0310-a592-d414129be87e>
Sat, 12 Jun 2004 20:31:03 +0000 (20:31 +0000)
(mknew/mknewa/resize) to the PuTTY ones (snew/snewn/sresize). snewn
and mknewa have their arguments opposite ways round; this may make
the change initially painful but in the long term will free me of a
nasty context switch every time I move between codebases. Also
sresize takes an explicit type operand which is used to cast the
return value from realloc, thus enforcing that it must be correct,
and arranging that if anyone tries to compile Halibut with a C++
compiler there should be a lot less pain.

git-svn-id: svn://svn.tartarus.org/sgt/halibut@4276 cda61777-01e9-0310-a592-d414129be87e

18 files changed:
bk_html.c
bk_info.c
bk_man.c
bk_paper.c
bk_pdf.c
bk_text.c
bk_whlp.c
contents.c
halibut.h
index.c
input.c
keywords.c
main.c
malloc.c
misc.c
tree234.c
ustring.c
winhelp.c

index 936126d..92a374a 100644 (file)
--- a/bk_html.c
+++ b/bk_html.c
@@ -207,7 +207,7 @@ static htmlconfig html_configure(paragraph *source) {
     ret.achapter.just_numbers = FALSE;
     ret.achapter.number_suffix = L": ";
     ret.nasect = 1;
-    ret.asect = mknewa(sectlevel, ret.nasect);
+    ret.asect = snewn(ret.nasect, sectlevel);
     ret.asect[0].just_numbers = TRUE;
     ret.asect[0].number_suffix = L" ";
     ret.ncdepths = 0;
@@ -293,7 +293,7 @@ static htmlconfig html_configure(paragraph *source) {
                }
                if (n >= ret.nasect) {
                    int i;
-                   ret.asect = resize(ret.asect, n+1);
+                   ret.asect = sresize(ret.asect, n+1, sectlevel);
                    for (i = ret.nasect; i <= n; i++)
                        ret.asect[i] = ret.asect[ret.nasect-1];
                    ret.nasect = n+1;
@@ -308,7 +308,7 @@ static htmlconfig html_configure(paragraph *source) {
                }
                if (n >= ret.nasect) {
                    int i;
-                   ret.asect = resize(ret.asect, n+1);
+                   ret.asect = sresize(ret.asect, n+1, sectlevel);
                    for (i = ret.nasect; i <= n; i++) {
                        ret.asect[i] = ret.asect[ret.nasect-1];
                    }
@@ -332,7 +332,8 @@ static htmlconfig html_configure(paragraph *source) {
                }
                if (n >= ret.ncdepths) {
                    int i;
-                   ret.contents_depths = resize(ret.contents_depths, n+1);
+                   ret.contents_depths =
+                       sresize(ret.contents_depths, n+1, int);
                    for (i = ret.ncdepths; i <= n; i++) {
                        ret.contents_depths[i] = i+2;
                    }
@@ -540,7 +541,7 @@ void html_backend(paragraph *sourceform, keywordlist *keywords,
                 * configuration template. For the moment I'll just
                 * invent something completely stupid.
                 */
-               sect->fragment = mknewa(char, 40);
+               sect->fragment = snewn(40, char);
                sprintf(sect->fragment, "frag%p", sect);
            }
        }
@@ -571,7 +572,7 @@ void html_backend(paragraph *sourceform, keywordlist *keywords,
         */
 
        for (i = 0; (entry = index234(idx->entries, i)) != NULL; i++) {
-           htmlindex *hi = mknew(htmlindex);
+           htmlindex *hi = snew(htmlindex);
 
            hi->nrefs = hi->refsize = 0;
            hi->refs = NULL;
@@ -595,7 +596,7 @@ void html_backend(paragraph *sourceform, keywordlist *keywords,
 
            for (w = p->words; w; w = w->next)
                if (w->type == word_IndexRef) {
-                   htmlindexref *hr = mknew(htmlindexref);
+                   htmlindexref *hr = snew(htmlindexref);
                    indextag *tag;
                    int i;
 
@@ -619,7 +620,7 @@ void html_backend(paragraph *sourceform, keywordlist *keywords,
 
                        if (hi->nrefs >= hi->refsize) {
                            hi->refsize += 32;
-                           hi->refs = resize(hi->refs, hi->refsize);
+                           hi->refs = sresize(hi->refs, hi->refsize, word *);
                        }
 
                        hi->refs[hi->nrefs++] = w;
@@ -858,7 +859,7 @@ void html_backend(paragraph *sourceform, keywordlist *keywords,
                        if (adepth <= a->contents_depth) {
                            if (ntoc >= tocsize) {
                                tocsize += 64;
-                               toc = resize(toc, tocsize);
+                               toc = sresize(toc, tocsize, htmlsect *);
                            }
                            toc[ntoc++] = s;
                        }
@@ -978,7 +979,7 @@ void html_backend(paragraph *sourceform, keywordlist *keywords,
                     * Now display the section text.
                     */
                    if (s->text) {
-                       stackhead = mknew(struct stackelement);
+                       stackhead = snew(struct stackelement);
                        stackhead->next = NULL;
                        stackhead->listtype = NOLIST;
                        stackhead->itemtype = NOITEM;
@@ -1027,7 +1028,7 @@ void html_backend(paragraph *sourceform, keywordlist *keywords,
                                break;
 
                              case para_LcontPush:
-                               se = mknew(struct stackelement);
+                               se = snew(struct stackelement);
                                se->next = stackhead;
                                se->listtype = NOLIST;
                                se->itemtype = NOITEM;
@@ -1373,7 +1374,7 @@ static void html_file_section(htmlconfig *cfg, htmlfilelist *files,
 
 static htmlfile *html_new_file(htmlfilelist *list, char *filename)
 {
-    htmlfile *ret = mknew(htmlfile);
+    htmlfile *ret = snew(htmlfile);
 
     ret->next = NULL;
     if (list->tail)
@@ -1392,7 +1393,7 @@ static htmlfile *html_new_file(htmlfilelist *list, char *filename)
 
 static htmlsect *html_new_sect(htmlsectlist *list, paragraph *title)
 {
-    htmlsect *ret = mknew(htmlsect);
+    htmlsect *ret = snew(htmlsect);
 
     ret->next = NULL;
     if (list->tail)
index 5c05817..03f8926 100644 (file)
--- a/bk_info.c
+++ b/bk_info.c
@@ -279,7 +279,7 @@ void info_backend(paragraph *sourceform, keywordlist *keywords,
        indexentry *entry;
 
        for (i = 0; (entry = index234(idx->entries, i)) != NULL; i++) {
-           info_idx *ii = mknew(info_idx);
+           info_idx *ii = snew(info_idx);
            info_data id = EMPTY_INFO_DATA;
 
            id.charset = conf.charset;
@@ -631,7 +631,7 @@ void info_backend(paragraph *sourceform, keywordlist *keywords,
 
                if (fp)
                    fclose(fp);
-               fname = mknewa(char, strlen(conf.filename) + 40);
+               fname = snewn(strlen(conf.filename) + 40, char);
                sprintf(fname, "%s-%d", conf.filename, filenum);
                fp = fopen(fname, "w");
                if (!fp) {
@@ -678,7 +678,7 @@ static int info_check_index(word *w, node *n, indexdata *idx)
 
                if (ii->nnodes >= ii->nodesize) {
                    ii->nodesize += 32;
-                   ii->nodes = resize(ii->nodes, ii->nodesize);
+                   ii->nodes = sresize(ii->nodes, ii->nodesize, node *);
                }
 
                ii->nodes[ii->nnodes++] = n;
@@ -1024,7 +1024,7 @@ static node *info_node_new(char *name, int charset)
 {
     node *n;
 
-    n = mknew(node);
+    n = snew(node);
     n->text = empty_info_data;
     n->text.charset = charset;
     n->up = n->next = n->prev = n->lastchild = n->listnext = NULL;
index 3b92aeb..b2db5bb 100644 (file)
--- a/bk_man.c
+++ b/bk_man.c
@@ -66,7 +66,7 @@ static manconfig man_configure(paragraph *source) {
                while (*ep)
                    ep = uadv(ep);
                sfree(ret.th);
-               ret.th = mknewa(wchar_t, ep - wp + 1);
+               ret.th = snewn(ep - wp + 1, wchar_t);
                memcpy(ret.th, wp, (ep - wp + 1) * sizeof(wchar_t));
            } else if (!ustricmp(p->keyword, L"man-charset")) {
                char *csname = utoa_dup(uadv(p->keyword), CS_ASCII);
@@ -321,7 +321,7 @@ static int man_convert(wchar_t const *s, int maxlen,
 
     psize = 384;
     plen = 0;
-    p = mknewa(char, psize);
+    p = snewn(psize, char);
     err = 0;
 
     while (slen > 0) {
@@ -331,7 +331,7 @@ static int man_convert(wchar_t const *s, int maxlen,
                    plen += ret;
            if (psize - plen < 256) {
                psize = plen + 256;
-               p = resize(p, psize);
+               p = sresize(p, psize, char);
            }
        }
     }
index f6b18b8..b38060f 100644 (file)
@@ -399,7 +399,7 @@ void *paper_pre_backend(paragraph *sourceform, keywordlist *keywords,
     paragraph index_placeholder_para;
     page_data *first_index_page;
 
-    fontlist = mknew(font_list);
+    fontlist = snew(font_list);
     fontlist->head = fontlist->tail = NULL;
 
     ourconf = paper_configure(sourceform, fontlist);
@@ -416,7 +416,7 @@ void *paper_pre_backend(paragraph *sourceform, keywordlist *keywords,
        has_index = FALSE;
 
        for (i = 0; (entry = index234(idx->entries, i)) != NULL; i++) {
-           paper_idx *pi = mknew(paper_idx);
+           paper_idx *pi = snew(paper_idx);
 
            has_index = TRUE;
 
@@ -682,7 +682,7 @@ void *paper_pre_backend(paragraph *sourceform, keywordlist *keywords,
        }
 
        if (has_index) {
-           first_index_page = mknew(page_data);
+           first_index_page = snew(page_data);
            first_index_page->next = first_index_page->prev = NULL;
            first_index_page->first_line = NULL;
            first_index_page->last_line = NULL;
@@ -910,7 +910,7 @@ void *paper_pre_backend(paragraph *sourceform, keywordlist *keywords,
      * Start putting together the overall document structure we're
      * going to return.
      */
-    doc = mknew(document);
+    doc = snew(document);
     doc->fonts = fontlist;
     doc->pages = pages;
     doc->paper_width = conf->paper_width;
@@ -925,7 +925,7 @@ void *paper_pre_backend(paragraph *sourceform, keywordlist *keywords,
     {
        int osize = 20;
 
-       doc->outline_elements = mknewa(outline_element, osize);
+       doc->outline_elements = snewn(osize, outline_element);
        doc->n_outline_elements = 0;
 
        /* First find the title. */
@@ -944,7 +944,7 @@ void *paper_pre_backend(paragraph *sourceform, keywordlist *keywords,
                if (doc->n_outline_elements >= osize) {
                    osize += 20;
                    doc->outline_elements =
-                       resize(doc->outline_elements, osize);
+                       sresize(doc->outline_elements, osize, outline_element);
                }
 
                doc->outline_elements[doc->n_outline_elements].level =
@@ -967,7 +967,7 @@ static para_data *make_para_data(int ptype, int paux, int indent, int rmargin,
     int extra_indent, firstline_indent, aux_indent;
     word *aux, *aux2;
 
-    pdata = mknew(para_data);
+    pdata = snew(para_data);
     pdata->outline_level = -1;
     pdata->outline_title = NULL;
     pdata->rect_type = RECT_NONE;
@@ -1227,7 +1227,7 @@ static font_encoding *new_font_encoding(font_data *font)
     font_encoding *fe;
     int i;
 
-    fe = mknew(font_encoding);
+    fe = snew(font_encoding);
     fe->next = NULL;
 
     if (font->list->tail)
@@ -1262,14 +1262,14 @@ static font_data *make_std_font(font_list *fontlist, char const *name)
 
     for (nglyphs = 0; ps_std_glyphs[nglyphs] != NULL; nglyphs++);
 
-    f = mknew(font_data);
+    f = snew(font_data);
 
     f->list = fontlist;
     f->name = name;
     f->nglyphs = nglyphs;
     f->glyphs = ps_std_glyphs;
     f->widths = widths;
-    f->subfont_map = mknewa(subfont_map_entry, nglyphs);
+    f->subfont_map = snewn(nglyphs, subfont_map_entry);
 
     /*
      * Our first subfont will contain all of US-ASCII. This isn't
@@ -1466,7 +1466,7 @@ static void wrap_paragraph(para_data *pdata, word *words,
        word *wd;
        int len, wid, spaces;
 
-       ldata = mknew(line_data);
+       ldata = snew(line_data);
 
        ldata->pdata = pdata;
        ldata->first = p->begin;
@@ -1546,11 +1546,11 @@ static page_data *page_breaks(line_data *first, line_data *last,
      */
 
     for (l = last; l; l = l->prev) {
-       l->bestcost = mknewa(int, ncols+1);
-       l->vshortfall = mknewa(int, ncols+1);
-       l->text = mknewa(int, ncols+1);
-       l->space = mknewa(int, ncols+1);
-       l->page_last = mknewa(line_data *, ncols+1);
+       l->bestcost = snewn(ncols+1, int);
+       l->vshortfall = snewn(ncols+1, int);
+       l->text = snewn(ncols+1, int);
+       l->space = snewn(ncols+1, int);
+       l->page_last = snewn(ncols+1, line_data *);
 
        for (n = 0; n <= ncols; n++) {
            int minheight, text = 0, space = 0;
@@ -1654,7 +1654,7 @@ static page_data *page_breaks(line_data *first, line_data *last,
        page_data *page;
        int text, space, head;
 
-       page = mknew(page_data);
+       page = snew(page_data);
        page->next = NULL;
        page->prev = pt;
        if (pt)
@@ -1712,7 +1712,7 @@ static page_data *page_breaks(line_data *first, line_data *last,
 
 static void add_rect_to_page(page_data *page, int x, int y, int w, int h)
 {
-    rect *r = mknew(rect);
+    rect *r = snew(rect);
 
     r->next = NULL;
     if (page->last_rect)
@@ -1733,7 +1733,7 @@ static void add_string_to_page(page_data *page, int x, int y,
 {
     text_fragment *frag;
 
-    frag = mknew(text_fragment);
+    frag = snew(text_fragment);
     frag->next = NULL;
 
     if (page->last_text)
@@ -1760,7 +1760,7 @@ static int render_string(page_data *page, font_data *font, int fontsize,
     int textpos, textwid, glyph;
     font_encoding *subfont = NULL, *sf;
 
-    text = mknewa(char, 1 + ustrlen(str));
+    text = snewn(1 + ustrlen(str), char);
     textpos = textwid = 0;
 
     while (*str) {
@@ -1876,7 +1876,7 @@ static int render_text(page_data *page, para_data *pdata, line_data *ldata,
                }
            }
            if (dest.type != NONE) {
-               *xr = mknew(xref);
+               *xr = snew(xref);
                (*xr)->dest = dest;    /* structure copy */
                if (page->last_xref)
                    page->last_xref->next = *xr;
@@ -2036,7 +2036,7 @@ static int render_line(line_data *ldata, int left_x, int top_y,
         * previous line.
         */
        if (dest->type != NONE) {
-           xr = mknew(xref);
+           xr = snew(xref);
            xr->next = NULL;
            xr->dest = *dest;    /* structure copy */
            if (ldata->page->last_xref)
@@ -2118,7 +2118,7 @@ static void render_para(para_data *pdata, paper_conf *conf,
         */
        if (pdata->contents_entry && ldata->page != cxref_page) {
            cxref_page = ldata->page;
-           cxref = mknew(xref);
+           cxref = snew(xref);
            cxref->next = NULL;
            cxref->dest.type = PAGE;
            if (pdata->contents_entry == index_placeholder) {
@@ -2222,7 +2222,7 @@ static void render_para(para_data *pdata, paper_conf *conf,
 
 static para_data *code_paragraph(int indent, word *words, paper_conf *conf)
 {
-    para_data *pdata = mknew(para_data);
+    para_data *pdata = snew(para_data);
 
     /*
      * For code paragraphs, I'm going to hack grievously and
@@ -2284,12 +2284,12 @@ static para_data *code_paragraph(int indent, word *words, paper_conf *conf)
             * which has the same emphasis. Form it into a word
             * structure.
             */
-           w = mknew(word);
+           w = snew(word);
            w->next = NULL;
            w->alt = NULL;
            w->type = (prev == 0 ? word_WeakCode :
                      prev == 1 ? word_Emph : word_Normal);
-           w->text = mknewa(wchar_t, t-start+1);
+           w->text = snewn(t-start+1, wchar_t);
            memcpy(w->text, start, (t-start) * sizeof(wchar_t));
            w->text[t-start] = '\0';
            w->breaks = FALSE;
@@ -2304,7 +2304,7 @@ static para_data *code_paragraph(int indent, word *words, paper_conf *conf)
            prev = -1;
        }
 
-       ldata = mknew(line_data);
+       ldata = snew(line_data);
 
        ldata->pdata = pdata;
        ldata->first = lhead;
@@ -2339,10 +2339,10 @@ static para_data *code_paragraph(int indent, word *words, paper_conf *conf)
 
 static para_data *rule_paragraph(int indent, paper_conf *conf)
 {
-    para_data *pdata = mknew(para_data);
+    para_data *pdata = snew(para_data);
     line_data *ldata;
 
-    ldata = mknew(line_data);
+    ldata = snew(line_data);
 
     ldata->pdata = pdata;
     ldata->first = NULL;
@@ -2448,7 +2448,7 @@ static wchar_t *prepare_outline_title(word *first, wchar_t *separator,
 
 static word *fake_word(wchar_t *text)
 {
-    word *ret = mknew(word);
+    word *ret = snew(word);
     ret->next = NULL;
     ret->alt = NULL;
     ret->type = word_Normal;
@@ -2460,7 +2460,7 @@ static word *fake_word(wchar_t *text)
 
 static word *fake_space_word(void)
 {
-    word *ret = mknew(word);
+    word *ret = snew(word);
     ret->next = NULL;
     ret->alt = NULL;
     ret->type = word_WhiteSpace;
@@ -2472,7 +2472,7 @@ static word *fake_space_word(void)
 
 static word *fake_page_ref(page_data *page)
 {
-    word *ret = mknew(word);
+    word *ret = snew(word);
     ret->next = NULL;
     ret->alt = NULL;
     ret->type = word_PageXref;
@@ -2485,7 +2485,7 @@ static word *fake_page_ref(page_data *page)
 
 static word *fake_end_ref(void)
 {
-    word *ret = mknew(word);
+    word *ret = snew(word);
     ret->next = NULL;
     ret->alt = NULL;
     ret->type = word_XrefEnd;
index ce71c5e..6aba554 100644 (file)
--- a/bk_pdf.c
+++ b/bk_pdf.c
@@ -464,7 +464,7 @@ void pdf_backend(paragraph *sourceform, keywordlist *keywords,
 
 static object *new_object(objlist *list)
 {
-    object *obj = mknew(object);
+    object *obj = snew(object);
 
     obj->list = list;
 
index e4a2d81..d7c539c 100644 (file)
--- a/bk_text.c
+++ b/bk_text.c
@@ -83,7 +83,7 @@ static textconfig text_configure(paragraph *source) {
     ret.achapter.number_suffix = L": ";
     ret.achapter.underline = L"\x203E\0-\0\0";
     ret.nasect = 1;
-    ret.asect = mknewa(alignstruct, ret.nasect);
+    ret.asect = snewn(ret.nasect, alignstruct);
     ret.asect[0].align = LEFTPLUS;
     ret.asect[0].just_numbers = TRUE;
     ret.asect[0].number_suffix = L" ";
@@ -157,7 +157,7 @@ static textconfig text_configure(paragraph *source) {
                }
                if (n >= ret.nasect) {
                    int i;
-                   ret.asect = resize(ret.asect, n+1);
+                   ret.asect = sresize(ret.asect, n+1, alignstruct);
                    for (i = ret.nasect; i <= n; i++)
                        ret.asect[i] = ret.asect[ret.nasect-1];
                    ret.nasect = n+1;
@@ -172,7 +172,7 @@ static textconfig text_configure(paragraph *source) {
                }
                if (n >= ret.nasect) {
                    int i;
-                   ret.asect = resize(ret.asect, n+1);
+                   ret.asect = sresize(ret.asect, n+1, alignstruct);
                    for (i = ret.nasect; i <= n; i++)
                        ret.asect[i] = ret.asect[ret.nasect-1];
                    ret.nasect = n+1;
@@ -187,7 +187,7 @@ static textconfig text_configure(paragraph *source) {
                }
                if (n >= ret.nasect) {
                    int i;
-                   ret.asect = resize(ret.asect, n+1);
+                   ret.asect = sresize(ret.asect, n+1, alignstruct);
                    for (i = ret.nasect; i <= n; i++)
                        ret.asect[i] = ret.asect[ret.nasect-1];
                    ret.nasect = n+1;
@@ -202,7 +202,7 @@ static textconfig text_configure(paragraph *source) {
                }
                if (n >= ret.nasect) {
                    int i;
-                   ret.asect = resize(ret.asect, n+1);
+                   ret.asect = sresize(ret.asect, n+1, alignstruct);
                    for (i = ret.nasect; i <= n; i++) {
                        ret.asect[i] = ret.asect[ret.nasect-1];
                    }
index 08f2532..ca15b61 100644 (file)
--- a/bk_whlp.c
+++ b/bk_whlp.c
@@ -201,13 +201,13 @@ void whlp_backend(paragraph *sourceform, keywordlist *keywords,
            tolower(conf.filename[len-2] != 'l') ||
            tolower(conf.filename[len-1] != 'p')) {
            char *newf;
-           newf = mknewa(char, len + 5);
+           newf = snewn(len + 5, char);
            sprintf(newf, "%s.hlp", conf.filename);
            sfree(conf.filename);
            conf.filename = newf;
            len = strlen(newf);
        }
-       cntname = mknewa(char, len+1);
+       cntname = snewn(len+1, char);
        sprintf(cntname, "%.*s.cnt", len-4, conf.filename);
     }
 
@@ -552,7 +552,7 @@ void whlp_backend(paragraph *sourceform, keywordlist *keywords,
                        whlp_set_font(h, FONT_BOLD_CODE);
                    else
                        whlp_set_font(h, FONT_CODE);
-                   tmp = mknewa(wchar_t, n+1);
+                   tmp = snewn(n+1, wchar_t);
                    ustrncpy(tmp, t, n);
                    tmp[n] = L'\0';
                    whlp_wtext(&state, tmp);
index f6bedba..35143cd 100644 (file)
@@ -25,14 +25,14 @@ struct numberstate_Tag {
 };
 
 numberstate *number_init(void) {
-    numberstate *ret = mknew(numberstate);
+    numberstate *ret = snew(numberstate);
     ret->chapternum = 0;
     ret->appendixnum = -1;
     ret->ischapter = 1;
     ret->oklevel = -1;                /* not even in a chapter yet */
     ret->maxsectlevel = 32;
-    ret->sectionlevels = mknewa(int, ret->maxsectlevel);
-    ret->currentsects = mknewa(paragraph *, ret->maxsectlevel+1);
+    ret->sectionlevels = snewn(ret->maxsectlevel, int);
+    ret->currentsects = snewn(ret->maxsectlevel+1, paragraph *);
     memset(ret->currentsects, 0, (ret->maxsectlevel+1)*sizeof(paragraph *));
     ret->lastsect = NULL;
     ret->listitem = -1;
@@ -48,7 +48,7 @@ void number_free(numberstate *state) {
 }
 
 static void dotext(word ***wret, wchar_t *text) {
-    word *mnewword = mknew(word);
+    word *mnewword = snew(word);
     mnewword->text = ustrdup(text);
     mnewword->type = word_Normal;
     mnewword->alt = NULL;
@@ -58,7 +58,7 @@ static void dotext(word ***wret, wchar_t *text) {
 }
 
 static void dospace(word ***wret) {
-    word *mnewword = mknew(word);
+    word *mnewword = snew(word);
     mnewword->text = NULL;
     mnewword->type = word_WhiteSpace;
     mnewword->alt = NULL;
@@ -162,8 +162,8 @@ word *number_mktext(numberstate *state, paragraph *p, wchar_t *category,
        state->oklevel = level+1;
        if (state->maxsectlevel <= level) {
            state->maxsectlevel = level + 32;
-           state->sectionlevels = resize(state->sectionlevels,
-                                         state->maxsectlevel);
+           state->sectionlevels = sresize(state->sectionlevels,
+                                          state->maxsectlevel, int);
        }
        state->sectionlevels[level]++;
        for (i = level+1; i < state->maxsectlevel; i++)
@@ -205,7 +205,7 @@ word *number_mktext(numberstate *state, paragraph *p, wchar_t *category,
        donumber(&pret, state->listitem);
        break;
       case para_LcontPush:
-       lse = mknew(struct listitem_stack_entry);
+       lse = snew(struct listitem_stack_entry);
        lse->listitem = state->listitem;
        lse->prev = *prev;
        stk_push(state->listitem_stack, lse);
index 62b87db..dfd92c1 100644 (file)
--- a/halibut.h
+++ b/halibut.h
@@ -261,9 +261,10 @@ void free_para_list(paragraph *p);
 word *dup_word_list(word *w);
 char *dupstr(char *s);
 
-#define mknew(type) ( (type *) smalloc (sizeof (type)) )
-#define mknewa(type, number) ( (type *) smalloc ((number) * sizeof (type)) )
-#define resize(array, len) ( srealloc ((array), (len) * sizeof (*(array))) )
+#define snew(type) ( (type *) smalloc (sizeof (type)) )
+#define snewn(number, type) ( (type *) smalloc ((number) * sizeof (type)) )
+#define sresize(array, number, type) \
+       ( (type *) srealloc ((array), (number) * sizeof (type)) )
 #define lenof(array) ( sizeof(array) / sizeof(*(array)) )
 
 /*
diff --git a/index.c b/index.c
index 9a2d9df..5dde59f 100644 (file)
--- a/index.c
+++ b/index.c
@@ -10,14 +10,14 @@ static int compare_tags(void *av, void *bv);
 static int compare_entries(void *av, void *bv);
 
 indexdata *make_index(void) {
-    indexdata *ret = mknew(indexdata);
+    indexdata *ret = snew(indexdata);
     ret->tags = newtree234(compare_tags);
     ret->entries = newtree234(compare_entries);
     return ret;
 }
 
 static indextag *make_indextag(void) {
-    indextag *ret = mknew(indextag);
+    indextag *ret = snew(indextag);
     ret->name = NULL;
     ret->implicit_text = NULL;
     ret->explicit_texts = NULL;
@@ -131,10 +131,10 @@ void index_merge(indexdata *idx, int is_explicit, wchar_t *tags, word *text,
                }
                if (t->nexplicit >= t->explicit_size) {
                    t->explicit_size = t->nexplicit + 8;
-                   t->explicit_texts = resize(t->explicit_texts,
-                                              t->explicit_size);
-                   t->explicit_fpos = resize(t->explicit_fpos,
-                                             t->explicit_size);
+                   t->explicit_texts = sresize(t->explicit_texts,
+                                               t->explicit_size, word *);
+                   t->explicit_fpos = sresize(t->explicit_fpos,
+                                              t->explicit_size, filepos);
                }
                t->explicit_texts[t->nexplicit] = text;
                t->explicit_fpos[t->nexplicit] = *fpos;
@@ -169,9 +169,9 @@ void build_index(indexdata *i) {
            fa = t->explicit_fpos;
        }
        if (t->nrefs) {
-           t->refs = mknewa(indexentry *, t->nrefs);
+           t->refs = snewn(t->nrefs, indexentry *);
            for (j = 0; j < t->nrefs; j++) {
-               indexentry *ent = mknew(indexentry);
+               indexentry *ent = snew(indexentry);
                ent->text = *ta++;
                ent->fpos = *fa++;
                t->refs[j] = add234(i->entries, ent);
diff --git a/input.c b/input.c
index 7531d62..59ea326 100644 (file)
--- a/input.c
+++ b/input.c
@@ -18,7 +18,7 @@ static void setpos(input *in, char *fname) {
 static void unget(input *in, int c, filepos *pos) {
     if (in->npushback >= in->pushbacksize) {
        in->pushbacksize = in->npushback + 16;
-       in->pushback = resize(in->pushback, in->pushbacksize);
+       in->pushback = sresize(in->pushback, in->pushbacksize, pushback);
     }
     in->pushback[in->npushback].chr = c;
     in->pushback[in->npushback].pos = *pos;   /* structure copy */
@@ -45,7 +45,7 @@ static int macrocmp(void *av, void *bv) {
 }
 static void macrodef(tree234 *macros, wchar_t *name, wchar_t *text,
                     filepos fpos) {
-    macro *m = mknew(macro);
+    macro *m = snew(macro);
     m->name = name;
     m->text = text;
     if (add234(macros, m) != m) {
@@ -60,7 +60,7 @@ static int macrolookup(tree234 *macros, input *in, wchar_t *name,
     m.name = name;
     gotit = find234(macros, &m, NULL);
     if (gotit) {
-       macrostack *expansion = mknew(macrostack);
+       macrostack *expansion = snew(macrostack);
        expansion->next = in->stack;
        expansion->text = gotit->text;
        expansion->pos = *pos;         /* structure copy */
@@ -560,7 +560,7 @@ static word *addword(word newword, word ***hptrptr) {
     word *mnewword;
     if (!hptrptr)
        return NULL;
-    mnewword = mknew(word);
+    mnewword = snew(word);
     *mnewword = newword;              /* structure copy */
     mnewword->next = NULL;
     **hptrptr = mnewword;
@@ -572,7 +572,7 @@ static word *addword(word newword, word ***hptrptr) {
  * Adds a new paragraph to a linked list
  */
 static paragraph *addpara(paragraph newpara, paragraph ***hptrptr) {
-    paragraph *mnewpara = mknew(paragraph);
+    paragraph *mnewpara = snew(paragraph);
     *mnewpara = newpara;              /* structure copy */
     mnewpara->next = NULL;
     **hptrptr = mnewpara;
@@ -739,7 +739,7 @@ static void read_file(paragraph ***ret, input *in, indexdata *idx) {
                 * nested lists, code paras etc). Hence, the previous
                 * paragraph must be of a list type.
                 */
-               sitem = mknew(struct crossparaitem);
+               sitem = snew(struct crossparaitem);
                stop = (struct crossparaitem *)stk_top(crossparastk);
                if (stop)
                    *sitem = *stop;
@@ -769,7 +769,7 @@ static void read_file(paragraph ***ret, input *in, indexdata *idx) {
                 * block-quoted (typically they will be indented a
                 * bit).
                 */
-               sitem = mknew(struct crossparaitem);
+               sitem = snew(struct crossparaitem);
                stop = (struct crossparaitem *)stk_top(crossparastk);
                if (stop)
                    *sitem = *stop;
@@ -1088,7 +1088,7 @@ static void read_file(paragraph ***ret, input *in, indexdata *idx) {
              case tok_lbrace:
                error(err_unexbrace, &t.pos);
                /* Error recovery: push nop */
-               sitem = mknew(struct stack_item);
+               sitem = snew(struct stack_item);
                sitem->type = stack_nop;
                sitem->fpos = t.pos;
                stk_push(parsestk, sitem);
@@ -1213,7 +1213,7 @@ static void read_file(paragraph ***ret, input *in, indexdata *idx) {
                            rdadd(&indexstr, L'"');
                            addword(wd, &idximplicit);
                        }
-                       sitem = mknew(struct stack_item);
+                       sitem = snew(struct stack_item);
                        sitem->fpos = t.pos;
                        sitem->type = stack_quote;
                        stk_push(parsestk, sitem);
@@ -1290,7 +1290,7 @@ static void read_file(paragraph ***ret, input *in, indexdata *idx) {
                         * delimiting the text marked by the link.
                         */
                        dtor(t), t = get_token(in);
-                       sitem = mknew(struct stack_item);
+                       sitem = snew(struct stack_item);
                        sitem->fpos = wd.fpos;
                        sitem->type = stack_hyper;
                        /*
@@ -1356,7 +1356,7 @@ static void read_file(paragraph ***ret, input *in, indexdata *idx) {
                        error(err_nestedstyles, &t.pos);
                        /* Error recovery: eat lbrace, push nop. */
                        dtor(t), t = get_token(in);
-                       sitem = mknew(struct stack_item);
+                       sitem = snew(struct stack_item);
                        sitem->fpos = t.pos;
                        sitem->type = stack_nop;
                        stk_push(parsestk, sitem);
@@ -1369,7 +1369,7 @@ static void read_file(paragraph ***ret, input *in, indexdata *idx) {
                                 type == c_cw ? word_WeakCode :
                                 word_Emph);
                        spcstyle = tospacestyle(style);
-                       sitem = mknew(struct stack_item);
+                       sitem = snew(struct stack_item);
                        sitem->fpos = t.pos;
                        sitem->type = stack_style;
                        stk_push(parsestk, sitem);
@@ -1383,12 +1383,12 @@ static void read_file(paragraph ***ret, input *in, indexdata *idx) {
                        error(err_nestedindex, &t.pos);
                        /* Error recovery: eat lbrace, push nop. */
                        dtor(t), t = get_token(in);
-                       sitem = mknew(struct stack_item);
+                       sitem = snew(struct stack_item);
                        sitem->fpos = t.pos;
                        sitem->type = stack_nop;
                        stk_push(parsestk, sitem);
                    }
-                   sitem = mknew(struct stack_item);
+                   sitem = snew(struct stack_item);
                    sitem->fpos = t.pos;
                    sitem->type = stack_idx;
                    dtor(t), t = get_token(in);
@@ -1458,7 +1458,7 @@ static void read_file(paragraph ***ret, input *in, indexdata *idx) {
                         * sidetrack from the main thread of the
                         * paragraph.
                         */
-                       sitem = mknew(struct stack_item);
+                       sitem = snew(struct stack_item);
                        sitem->fpos = t.pos;
                        sitem->type = stack_ualt;
                        sitem->whptr = whptr;
index eef96a6..8101282 100644 (file)
@@ -33,7 +33,7 @@ keyword *kw_lookup(keywordlist *kl, wchar_t *str) {
  */
 keywordlist *get_keywords(paragraph *source) {
     int errors = FALSE;
-    keywordlist *kl = mknew(keywordlist);
+    keywordlist *kl = snew(keywordlist);
     numberstate *n = number_init();
     int prevpara = para_NotParaType;
 
@@ -68,7 +68,7 @@ keywordlist *get_keywords(paragraph *source) {
            if (source->kwtext || source->type == para_Biblio) {
                keyword *kw, *ret;
 
-               kw = mknew(keyword);
+               kw = snew(keyword);
                kw->key = p;
                kw->text = source->kwtext;
                kw->para = source;
@@ -82,7 +82,8 @@ keywordlist *get_keywords(paragraph *source) {
        } else {
            if (kl->nlooseends >= kl->looseendssize) {
                kl->looseendssize = kl->nlooseends + 32;
-               kl->looseends = resize(kl->looseends, kl->looseendssize);
+               kl->looseends = sresize(kl->looseends, kl->looseendssize,
+                                       word *);
            }
            kl->looseends[kl->nlooseends++] = source->kwtext;
        }
@@ -133,7 +134,7 @@ void subst_keywords(paragraph *source, keywordlist *kl) {
                    kw->para->type != para_BiblioCited)
                    ustrlow(subst->text);
 
-               close = mknew(word);
+               close = snew(word);
                close->text = NULL;
                close->alt = NULL;
                close->type = word_XrefEnd;
diff --git a/main.c b/main.c
index 87a5fd0..f09b33e 100644 (file)
--- a/main.c
+++ b/main.c
@@ -54,7 +54,7 @@ int main(int argc, char **argv) {
     /*
      * Set up initial (default) parameters.
      */
-    infiles = mknewa(char *, argc);
+    infiles = snewn(argc, char *);
     nfiles = 0;
     nogo = errs = FALSE;
     reportcols = 0;
index 1635b47..6612fef 100644 (file)
--- a/malloc.c
+++ b/malloc.c
@@ -104,7 +104,7 @@ word *dup_word_list(word *w) {
     word *head, **eptr = &head;
 
     while (w) {
-       word *newwd = mknew(word);
+       word *newwd = snew(word);
        *newwd = *w;                   /* structure copy */
        newwd->text = ustrdup(w->text);
        if (w->alt)
diff --git a/misc.c b/misc.c
index aa05878..0d488d4 100644 (file)
--- a/misc.c
+++ b/misc.c
@@ -18,7 +18,7 @@ struct stackTag {
 stack stk_new(void) {
     stack s;
 
-    s = mknew(struct stackTag);
+    s = snew(struct stackTag);
     s->sp = 0;
     s->size = 0;
     s->data = NULL;
@@ -34,7 +34,7 @@ void stk_free(stack s) {
 void stk_push(stack s, void *item) {
     if (s->size <= s->sp) {
        s->size = s->sp + 32;
-       s->data = resize(s->data, s->size);
+       s->data = sresize(s->data, s->size, void *);
     }
     s->data[s->sp++] = item;
 }
@@ -62,7 +62,7 @@ const rdstringc empty_rdstringc = {0, 0, NULL};
 void rdadd(rdstring *rs, wchar_t c) {
     if (rs->pos >= rs->size-1) {
        rs->size = rs->pos + 128;
-       rs->text = resize(rs->text, rs->size);
+       rs->text = sresize(rs->text, rs->size, wchar_t);
     }
     rs->text[rs->pos++] = c;
     rs->text[rs->pos] = 0;
@@ -71,20 +71,20 @@ void rdadds(rdstring *rs, wchar_t const *p) {
     int len = ustrlen(p);
     if (rs->pos >= rs->size - len) {
        rs->size = rs->pos + len + 128;
-       rs->text = resize(rs->text, rs->size);
+       rs->text = sresize(rs->text, rs->size, wchar_t);
     }
     ustrcpy(rs->text + rs->pos, p);
     rs->pos += len;
 }
 wchar_t *rdtrim(rdstring *rs) {
-    rs->text = resize(rs->text, rs->pos + 1);
+    rs->text = sresize(rs->text, rs->pos + 1, wchar_t);
     return rs->text;
 }
 
 void rdaddc(rdstringc *rs, char c) {
     if (rs->pos >= rs->size-1) {
        rs->size = rs->pos + 128;
-       rs->text = resize(rs->text, rs->size);
+       rs->text = sresize(rs->text, rs->size, char);
     }
     rs->text[rs->pos++] = c;
     rs->text[rs->pos] = 0;
@@ -93,13 +93,13 @@ void rdaddsc(rdstringc *rs, char const *p) {
     int len = strlen(p);
     if (rs->pos >= rs->size - len) {
        rs->size = rs->pos + len + 128;
-       rs->text = resize(rs->text, rs->size);
+       rs->text = sresize(rs->text, rs->size, char);
     }
     strcpy(rs->text + rs->pos, p);
     rs->pos += len;
 }
 char *rdtrimc(rdstringc *rs) {
-    rs->text = resize(rs->text, rs->pos + 1);
+    rs->text = sresize(rs->text, rs->pos + 1, char);
     return rs->text;
 }
 
@@ -462,7 +462,7 @@ wrappedline *wrap_para(word *text, int width, int subsequentwidth,
      */
     i = 0;
     while (i < nwords) {
-       wrappedline *w = mknew(wrappedline);
+       wrappedline *w = snew(wrappedline);
        *ptr = w;
        ptr = &w->next;
        w->next = NULL;
@@ -515,13 +515,13 @@ void cmdline_cfg_add(paragraph *cfg, char *string)
 
     upos = ulen;
     ulen += 2 + ustrlen(ustring);
-    cfg->keyword = resize(cfg->keyword, ulen);
+    cfg->keyword = sresize(cfg->keyword, ulen, wchar_t);
     ustrcpy(cfg->keyword+upos, ustring);
     cfg->keyword[ulen-1] = L'\0';
 
     pos = len;
     len += 2 + strlen(string);
-    cfg->origkeyword = resize(cfg->origkeyword, len);
+    cfg->origkeyword = sresize(cfg->origkeyword, len, char);
     strcpy(cfg->origkeyword+pos, string);
     cfg->origkeyword[len-1] = '\0';
 
@@ -532,7 +532,7 @@ paragraph *cmdline_cfg_new(void)
 {
     paragraph *p;
 
-    p = mknew(paragraph);
+    p = snew(paragraph);
     memset(p, 0, sizeof(*p));
     p->type = para_Config;
     p->next = NULL;
index bc88039..06738cb 100644 (file)
--- a/tree234.c
+++ b/tree234.c
@@ -34,7 +34,7 @@
 #define smalloc malloc
 #define sfree free
 
-#define mknew(typ) ( (typ *) smalloc (sizeof (typ)) )
+#define snew(typ) ( (typ *) smalloc (sizeof (typ)) )
 
 #ifdef TEST
 #define LOG(x) (printf x)
@@ -60,7 +60,7 @@ struct node234_Tag {
  * Create a 2-3-4 tree.
  */
 tree234 *newtree234(cmpfn234 cmp) {
-    tree234 *ret = mknew(tree234);
+    tree234 *ret = snew(tree234);
     LOG(("created tree %p\n", ret));
     ret->root = NULL;
     ret->cmp = cmp;
@@ -187,7 +187,7 @@ static int add234_insert(node234 *left, void *e, node234 *right,
            LOG(("  done\n"));
            break;
        } else {
-           node234 *m = mknew(node234);
+           node234 *m = snew(node234);
            m->parent = n->parent;
            LOG(("  splitting a 4-node; created new node %p\n", m));
            /*
@@ -283,7 +283,7 @@ static int add234_insert(node234 *left, void *e, node234 *right,
        return 0;                      /* root unchanged */
     } else {
        LOG(("  root is overloaded, split into two\n"));
-       (*root) = mknew(node234);
+       (*root) = snew(node234);
        (*root)->kids[0] = left;     (*root)->counts[0] = lcount;
        (*root)->elems[0] = e;
        (*root)->kids[1] = right;    (*root)->counts[1] = rcount;
@@ -314,7 +314,7 @@ static void *add234_internal(tree234 *t, void *e, int index) {
 
     LOG(("adding element \"%s\" to tree %p\n", e, t));
     if (t->root == NULL) {
-       t->root = mknew(node234);
+       t->root = snew(node234);
        t->root->elems[1] = t->root->elems[2] = NULL;
        t->root->kids[0] = t->root->kids[1] = NULL;
        t->root->kids[2] = t->root->kids[3] = NULL;
@@ -1040,7 +1040,7 @@ static node234 *join234_internal(node234 *left, void *sep,
         * nodes.
         */
        node234 *newroot;
-       newroot = mknew(node234);
+       newroot = snew(node234);
        newroot->kids[0] = left;     newroot->counts[0] = countnode234(left);
        newroot->elems[0] = sep;
        newroot->kids[1] = right;    newroot->counts[1] = countnode234(right);
@@ -1215,7 +1215,7 @@ static node234 *split234_internal(tree234 *t, int index) {
         * new node pointers in halves[0] and halves[1], and go up
         * a level.
         */
-       sib = mknew(node234);
+       sib = snew(node234);
        for (i = 0; i < 3; i++) {
            if (i+ki < 3 && n->elems[i+ki]) {
                sib->elems[i] = n->elems[i+ki];
@@ -1415,7 +1415,7 @@ tree234 *split234(tree234 *t, void *e, cmpfn234 cmp, int rel) {
 
 static node234 *copynode234(node234 *n, copyfn234 copyfn, void *copyfnstate) {
     int i;
-    node234 *n2 = mknew(node234);
+    node234 *n2 = snew(node234);
 
     for (i = 0; i < 3; i++) {
        if (n->elems[i] && copyfn)
index 3f52972..8cf8554 100644 (file)
--- a/ustring.c
+++ b/ustring.c
 wchar_t *ustrdup(wchar_t const *s) {
     wchar_t *r;
     if (s) {
-       r = mknewa(wchar_t, 1+ustrlen(s));
+       r = snewn(1+ustrlen(s), wchar_t);
        ustrcpy(r, s);
     } else {
-       r = mknew(wchar_t);
+       r = snew(wchar_t);
        *r = 0;
     }
     return r;
@@ -100,7 +100,7 @@ char *utoa_internal_dup(wchar_t const *s, int charset, int *lenp, int careful)
     len = ustrlen(s);
 
     outlen = len + 10;
-    outbuf = mknewa(char, outlen);
+    outbuf = snewn(outlen, char);
 
     outpos = 0;
     outbuf[outpos] = '\0';
@@ -116,7 +116,7 @@ char *utoa_internal_dup(wchar_t const *s, int charset, int *lenp, int careful)
        }
        if (!ret) {
            outlen = outlen * 3 / 2;
-           outbuf = resize(outbuf, outlen);
+           outbuf = sresize(outbuf, outlen, char);
        }
        outpos += ret;
        outbuf[outpos] = '\0';
@@ -125,7 +125,7 @@ char *utoa_internal_dup(wchar_t const *s, int charset, int *lenp, int careful)
      * Clean up
      */
     outlen = outpos + 32;
-    outbuf = resize(outbuf, outlen);
+    outbuf = sresize(outbuf, outlen, char);
     ret = charset_from_unicode(NULL, 0,
                               outbuf + outpos, outlen - outpos + 1,
                               charset, &state, NULL);
@@ -157,12 +157,12 @@ wchar_t *ufroma_dup(char const *s, int charset) {
 
     len = strlen(s) + 1;
     do {
-       buf = resize(buf, len);
+       buf = sresize(buf, len, wchar_t);
        ustrfroma(s, buf, len, charset);
        len = (3 * len) / 2 + 1;       /* this guarantees a strict increase */
     } while (ustrlen(buf) >= len-1);
 
-    buf = resize(buf, ustrlen(buf)+1);
+    buf = sresize(buf, ustrlen(buf)+1, wchar_t);
     return buf;
 }
 
@@ -177,14 +177,14 @@ char *utoa_locale_dup(wchar_t const *s)
 
     len = ustrlen(s);
 
-    ret = mknewa(char, 1 + MB_CUR_MAX * len);
+    ret = snewn(1 + MB_CUR_MAX * len, char);
 
     siz = wcstombs(ret, s, len);
 
     if (siz) {
        assert(siz <= MB_CUR_MAX * len);
        ret[siz] = '\0';
-       ret = resize(ret, siz+1);
+       ret = sresize(ret, siz+1, char);
        return ret;
     }
 
@@ -208,14 +208,14 @@ wchar_t *ufroma_locale_dup(char const *s)
 
     len = strlen(s);
 
-    ret = mknewa(wchar_t, 1 + 2*len);  /* be conservative */
+    ret = snewn(1 + 2*len, wchar_t);  /* be conservative */
 
     siz = mbstowcs(ret, s, len);
 
     if (siz) {
        assert(siz <= (size_t)(2 * len));
        ret[siz] = L'\0';
-       ret = resize(ret, siz+1);
+       ret = sresize(ret, siz+1, wchar_t);
        return ret;
     }
 
@@ -386,7 +386,7 @@ static void ustrftime_internal(rdstring *rs, char formatchr,
     size = 0;
     do {
        size += USTRFTIME_DELTA;
-       buf = resize(buf, size);
+       buf = sresize(buf, size, wchar_t);
        ret = (int) wcsftime(buf, size, fmt, timespec);
     } while (ret == 0);
 
@@ -406,7 +406,7 @@ static void ustrftime_internal(rdstring *rs, char formatchr,
     size = 0;
     do {
        size += USTRFTIME_DELTA;
-       buf = resize(buf, size);
+       buf = sresize(buf, size, char);
        ret = (int) strftime(buf, size, fmt, timespec);
     } while (ret == 0);
 
index 005409e..c41503d 100644 (file)
--- a/winhelp.c
+++ b/winhelp.c
 #define smalloc malloc
 #define srealloc realloc
 #define sfree free
-#define mknew(type) ( (type *) smalloc (sizeof (type)) )
-#define mknewa(type, number) ( (type *) smalloc ((number) * sizeof (type)) )
-#define resize(array, len) ( srealloc ((array), (len) * sizeof (*(array))) )
+#define snew(type) ( (type *) smalloc (sizeof (type)) )
+#define snewn(number, type) ( (type *) smalloc ((number) * sizeof (type)) )
+#define sresize(array, len, type) \
+               ( (type *) srealloc ((array), (len) * sizeof (type)) )
 #define lenof(array) ( sizeof(array) / sizeof(*(array)) )
 char *dupstr(char *s) {
-    char *r = mknewa(char, 1+strlen(s)); strcpy(r,s); return r;
+    char *r = snewn(1+strlen(s), char); strcpy(r,s); return r;
 }
 #endif
 
@@ -403,7 +404,7 @@ static unsigned long context_hash(char *context)
 
 WHLP_TOPIC whlp_register_topic(WHLP h, char *context_name, char **clash)
 {
-    context *ctx = mknew(context);
+    context *ctx = snew(context);
     context *otherctx;
 
     /*
@@ -463,7 +464,7 @@ void whlp_prepare(WHLP h)
 
     while ( (ctx = index234(h->pre_contexts, 0)) != NULL ) {
        delpos234(h->pre_contexts, 0);
-       ctx->name = mknewa(char, 20);
+       ctx->name = snewn(20, char);
        do {
            sprintf(ctx->name, "t%08d", ctx_num++);
            ctx->hash = context_hash(ctx->name);
@@ -485,7 +486,7 @@ char *whlp_topic_id(WHLP_TOPIC topic)
 
 void whlp_begin_topic(WHLP h, WHLP_TOPIC topic, char *title, ...)
 {
-    struct topiclink *link = mknew(struct topiclink);
+    struct topiclink *link = snew(struct topiclink);
     int len, slen;
     char *macro;
     va_list ap;
@@ -501,7 +502,7 @@ void whlp_begin_topic(WHLP h, WHLP_TOPIC topic, char *title, ...)
 
     link->recordtype = 2;             /* topic header */
     link->len1 = 4*7;                 /* standard linkdata1 size */
-    link->data1 = mknewa(unsigned char, link->len1);
+    link->data1 = snewn(link->len1, unsigned char);
     
     slen = strlen(title);
     assert(slen+1 <= TOPIC_BLKSIZE);
@@ -519,7 +520,7 @@ void whlp_begin_topic(WHLP h, WHLP_TOPIC topic, char *title, ...)
     len--;                            /* lose the last \0 on the last macro */
 
     link->len2 = len;
-    link->data2 = mknewa(unsigned char, link->len2);
+    link->data2 = snewn(link->len2, unsigned char);
     memcpy(link->data2, h->linkdata2, link->len2);
 
     topic->title = dupstr(title);
@@ -643,7 +644,7 @@ void whlp_set_tabstop(WHLP h, int tabstop, int alignment)
     if (alignment == WHLP_ALIGN_RIGHT)
         tabstop |= 0x10000;
 
-    p = mknew(int);
+    p = snew(int);
     *p = tabstop;
     add234(h->tabstops, p);
     h->para_flags |= 0x0200;
@@ -651,7 +652,7 @@ void whlp_set_tabstop(WHLP h, int tabstop, int alignment)
 
 void whlp_begin_para(WHLP h, int para_type)
 {
-    struct topiclink *link = mknew(struct topiclink);
+    struct topiclink *link = snew(struct topiclink);
     int i;
 
     /*
@@ -800,10 +801,10 @@ void whlp_end_para(WHLP h)
     whlp_linkdata_cslong(h, 1, data1cut);
     whlp_linkdata_cushort(h, 1, h->link->len2);
 
-    h->link->data1 = mknewa(unsigned char, h->link->len1);
+    h->link->data1 = snewn(h->link->len1, unsigned char);
     memcpy(h->link->data1, h->linkdata1 + data1cut, h->link->len1 - data1cut);
     memcpy(h->link->data1 + h->link->len1 - data1cut, h->linkdata1, data1cut);
-    h->link->data2 = mknewa(unsigned char, h->link->len2);
+    h->link->data2 = snewn(h->link->len2, unsigned char);
     memcpy(h->link->data2, h->linkdata2, h->link->len2);
 
     addpos234(h->text, h->link, count234(h->text));
@@ -870,12 +871,12 @@ static void whlp_topic_layout(WHLP h)
     /*
      * Create a final TOPICLINK containing no usable data.
      */
-    link = mknew(struct topiclink);
+    link = snew(struct topiclink);
     link->nexttopic = NULL;
     if (h->prevtopic)
        h->prevtopic->nexttopic = link;
     h->prevtopic = link;
-    link->data1 = mknewa(unsigned char, 0x1c);
+    link->data1 = snewn(0x1c, unsigned char);
     link->block_size = 0;
     link->data2 = NULL;
     link->len1 = 0x1c;
@@ -1043,7 +1044,7 @@ static void whlp_topic_layout(WHLP h)
 
 void whlp_index_term(WHLP h, char *index, WHLP_TOPIC topic)
 {
-    struct indexrec *idx = mknew(struct indexrec);
+    struct indexrec *idx = snew(struct indexrec);
 
     idx->term = dupstr(index);
     idx->topic = topic;
@@ -1168,7 +1169,7 @@ int whlp_create_font(WHLP h, char *font, int family, int halfpoints,
        sfree(fontname);
     }
 
-    fontdesc = mknew(struct fontdesc);
+    fontdesc = snew(struct fontdesc);
     fontdesc->font = font;
     fontdesc->family = family;
     fontdesc->halfpoints = halfpoints;
@@ -1302,7 +1303,7 @@ static void whlp_make_btree(struct file *f, int flags, int pagesize,
        npages_this_level++;
        if (npages >= pagessize) {
            pagessize = npages + 32;
-           page_elements = resize(page_elements, pagessize);
+           page_elements = sresize(page_elements, pagessize, void *);
        }
        page_elements[npages++] = element;
 
@@ -1388,7 +1389,7 @@ static void whlp_make_btree(struct file *f, int flags, int pagesize,
            npages_this_level++;
            if (npages >= pagessize) {
                pagessize = npages + 32;
-               page_elements = resize(page_elements, pagessize);
+               page_elements = sresize(page_elements, pagessize, void *);
            }
            page_elements[npages++] = page_elements[current];
 
@@ -1458,7 +1459,7 @@ static void whlp_make_btree(struct file *f, int flags, int pagesize,
 static struct file *whlp_new_file(WHLP h, char *name)
 {
     struct file *f;
-    f = mknew(struct file);
+    f = snew(struct file);
     f->data = NULL;
     f->pos = f->len = f->size = 0;
     if (name) {
@@ -1481,7 +1482,7 @@ static void whlp_file_add(struct file *f, const void *data, int len)
 {
     if (f->pos + len > f->size) {
        f->size = f->pos + len + 1024;
-       f->data = resize(f->data, f->size);
+       f->data = sresize(f->data, f->size, unsigned char);
     }
     memcpy(f->data + f->pos, data, len);
     f->pos += len;
@@ -1514,7 +1515,7 @@ static void whlp_file_fill(struct file *f, int len)
 {
     if (f->pos + len > f->size) {
        f->size = f->pos + len + 1024;
-       f->data = resize(f->data, f->size);
+       f->data = sresize(f->data, f->size, unsigned char);
     }
     memset(f->data + f->pos, 0, len);
     f->pos += len;
@@ -1541,7 +1542,7 @@ WHLP whlp_new(void)
     WHLP ret;
     struct file *f;
 
-    ret = mknew(struct WHLP_tag);
+    ret = snew(struct WHLP_tag);
 
     /*
      * Internal B-trees.