diff options
author | Kristaps Dzonsons <kristaps@bsd.lv> | 2011-03-17 08:49:34 +0000 |
---|---|---|
committer | Kristaps Dzonsons <kristaps@bsd.lv> | 2011-03-17 08:49:34 +0000 |
commit | b115f948b8e55e6c3cef4bfa81f62c190af37a59 (patch) | |
tree | 36b8ace377de1911ede7b7fca7e4ce75035928c9 | |
parent | 684938dc1d7c8591d0b63657a1d36b25b24eaea8 (diff) | |
download | mandoc-b115f948b8e55e6c3cef4bfa81f62c190af37a59.tar.gz |
Move mandoc_{realloc,malloc,calloc} out of libmandoc.h and into mandoc.h
so that everybody can use them. This follows the convention of
libXXXX.h being internal to a library and XXXX.h being the external
interface. Not only does this allow the removal of lots of redundant
NULL-checking code, it also sets the tone for adding new mandoc-global
routines.
-rw-r--r-- | chars.c | 13 | ||||
-rw-r--r-- | html.c | 12 | ||||
-rw-r--r-- | libmandoc.h | 3 | ||||
-rw-r--r-- | main.c | 6 | ||||
-rw-r--r-- | mandoc.h | 12 | ||||
-rw-r--r-- | out.c | 2 | ||||
-rw-r--r-- | term.c | 13 | ||||
-rw-r--r-- | term_ps.c | 7 |
8 files changed, 15 insertions, 53 deletions
@@ -92,17 +92,8 @@ chars_init(enum chars type) * (they're in-line re-ordered during lookup). */ - tab = malloc(sizeof(struct ctab)); - if (NULL == tab) { - perror(NULL); - exit((int)MANDOCLEVEL_SYSERR); - } - - htab = calloc(PRINT_HI - PRINT_LO + 1, sizeof(struct ln **)); - if (NULL == htab) { - perror(NULL); - exit((int)MANDOCLEVEL_SYSERR); - } + tab = mandoc_malloc(sizeof(struct ctab)); + htab = mandoc_calloc(PRINT_HI - PRINT_LO + 1, sizeof(struct ln **)); for (i = 0; i < LINES_MAX; i++) { hash = (int)lines[i].code[0] - PRINT_LO; @@ -120,11 +120,7 @@ ml_alloc(char *outopts, enum htmltype type) toks[2] = "includes"; toks[3] = NULL; - h = calloc(1, sizeof(struct html)); - if (NULL == h) { - perror(NULL); - exit((int)MANDOCLEVEL_SYSERR); - } + h = mandoc_calloc(1, sizeof(struct html)); h->type = type; h->tags.head = NULL; @@ -400,11 +396,7 @@ print_otag(struct html *h, enum htmltag tag, /* Push this tags onto the stack of open scopes. */ if ( ! (HTML_NOSTACK & htmltags[tag].flags)) { - t = malloc(sizeof(struct tag)); - if (NULL == t) { - perror(NULL); - exit((int)MANDOCLEVEL_SYSERR); - } + t = mandoc_malloc(sizeof(struct tag)); t->tag = tag; t->next = h->tags.head; h->tags.head = t; diff --git a/libmandoc.h b/libmandoc.h index 83409a82..f7a54f2b 100644 --- a/libmandoc.h +++ b/libmandoc.h @@ -20,10 +20,7 @@ __BEGIN_DECLS int mandoc_special(char *); -void *mandoc_calloc(size_t, size_t); char *mandoc_strdup(const char *); -void *mandoc_malloc(size_t); -void *mandoc_realloc(void *, size_t); char *mandoc_getarg(char **, mandocmsg, void *, int, int *); char *mandoc_normdate(char *, mandocmsg, void *, int, int); int mandoc_eos(const char *, size_t, int); @@ -405,11 +405,7 @@ resize_buf(struct buf *buf, size_t initial) { buf->sz = buf->sz > initial/2 ? 2 * buf->sz : initial; - buf->buf = realloc(buf->buf, buf->sz); - if (NULL == buf->buf) { - perror(NULL); - exit((int)MANDOCLEVEL_SYSERR); - } + buf->buf = mandoc_realloc(buf->buf, buf->sz); } @@ -312,14 +312,14 @@ struct regset { struct reg regs[REG__MAX]; }; +typedef int (*mandocmsg)(enum mandocerr, void *, + int, int, const char *); + __BEGIN_DECLS -/* - * Callback function for warnings, errors, and fatal errors as they - * occur in the compilers libroff, libmdoc, and libman. - */ -typedef int (*mandocmsg)(enum mandocerr, void *, - int, int, const char *); +void *mandoc_calloc(size_t, size_t); +void *mandoc_malloc(size_t); +void *mandoc_realloc(void *, size_t); __END_DECLS @@ -431,7 +431,7 @@ tblcalc(struct rofftbl *tbl, const struct tbl_span *sp) */ assert(NULL == tbl->cols); - tbl->cols = calloc + tbl->cols = mandoc_calloc ((size_t)sp->tbl->cols, sizeof(struct roffcol)); hp = sp->head; @@ -80,12 +80,7 @@ term_alloc(enum termenc enc) { struct termp *p; - p = calloc(1, sizeof(struct termp)); - if (NULL == p) { - perror(NULL); - exit((int)MANDOCLEVEL_SYSERR); - } - + p = mandoc_calloc(1, sizeof(struct termp)); p->enc = enc; return(p); } @@ -579,11 +574,7 @@ adjbuf(struct termp *p, size_t sz) while (sz >= p->maxcols) p->maxcols <<= 2; - p->buf = realloc(p->buf, p->maxcols); - if (NULL == p->buf) { - perror(NULL); - exit((int)MANDOCLEVEL_SYSERR); - } + p->buf = mandoc_realloc(p->buf, p->maxcols); } @@ -366,14 +366,9 @@ ps_growbuf(struct termp *p, size_t sz) p->engine.ps.psmargsz += sz; - p->engine.ps.psmarg = realloc + p->engine.ps.psmarg = mandoc_realloc (p->engine.ps.psmarg, p->engine.ps.psmargsz); - - if (NULL == p->engine.ps.psmarg) { - perror(NULL); - exit((int)MANDOCLEVEL_SYSERR); - } } static double ps_hspan(const struct termp *, |