diff options
author | Ingo Schwarze <schwarze@cvs.openbsd.org> | 2015-04-18 17:01:29 +0000 |
---|---|---|
committer | Ingo Schwarze <schwarze@cvs.openbsd.org> | 2015-04-18 17:01:29 +0000 |
commit | dc444622db6500b04f7ba654ef9ed2568aa406b5 (patch) | |
tree | 15260d6108050b8bd90fb766ab87ebaff9f165cf /usr.bin/mandoc | |
parent | 7f5a971c67d6f29296dc382f491b457b8fd8f8b1 (diff) |
Move mdoc_hash_init() and man_hash_init() to libmandoc.h
and call them from mparse_alloc() and choose_parser(),
preparing unified allocation of struct roff_man.
Diffstat (limited to 'usr.bin/mandoc')
-rw-r--r-- | usr.bin/mandoc/libman.h | 3 | ||||
-rw-r--r-- | usr.bin/mandoc/libmandoc.h | 4 | ||||
-rw-r--r-- | usr.bin/mandoc/libmdoc.h | 3 | ||||
-rw-r--r-- | usr.bin/mandoc/man.c | 4 | ||||
-rw-r--r-- | usr.bin/mandoc/man_hash.c | 9 | ||||
-rw-r--r-- | usr.bin/mandoc/mdoc.c | 3 | ||||
-rw-r--r-- | usr.bin/mandoc/mdoc_hash.c | 9 | ||||
-rw-r--r-- | usr.bin/mandoc/read.c | 12 |
8 files changed, 24 insertions, 23 deletions
diff --git a/usr.bin/mandoc/libman.h b/usr.bin/mandoc/libman.h index a736ce74ca7..573af9d4c4d 100644 --- a/usr.bin/mandoc/libman.h +++ b/usr.bin/mandoc/libman.h @@ -1,4 +1,4 @@ -/* $OpenBSD: libman.h,v 1.46 2015/04/18 16:04:40 schwarze Exp $ */ +/* $OpenBSD: libman.h,v 1.47 2015/04/18 17:01:28 schwarze Exp $ */ /* * Copyright (c) 2009, 2010, 2011 Kristaps Dzonsons <kristaps@bsd.lv> * Copyright (c) 2014, 2015 Ingo Schwarze <schwarze@openbsd.org> @@ -43,7 +43,6 @@ void man_head_alloc(struct roff_man *, int, int, int); void man_body_alloc(struct roff_man *, int, int, int); void man_elem_alloc(struct roff_man *, int, int, int); void man_node_delete(struct roff_man *, struct roff_node *); -void man_hash_init(void); int man_hash_find(const char *); void man_macroend(struct roff_man *); void man_valid_post(struct roff_man *); diff --git a/usr.bin/mandoc/libmandoc.h b/usr.bin/mandoc/libmandoc.h index 169a98a480f..6034e158fa0 100644 --- a/usr.bin/mandoc/libmandoc.h +++ b/usr.bin/mandoc/libmandoc.h @@ -1,4 +1,4 @@ -/* $OpenBSD: libmandoc.h,v 1.42 2015/04/18 16:04:40 schwarze Exp $ */ +/* $OpenBSD: libmandoc.h,v 1.43 2015/04/18 17:01:28 schwarze Exp $ */ /* * Copyright (c) 2009, 2010, 2011, 2012 Kristaps Dzonsons <kristaps@bsd.lv> * Copyright (c) 2013, 2014, 2015 Ingo Schwarze <schwarze@openbsd.org> @@ -55,6 +55,7 @@ void mdoc_free(struct roff_man *); struct roff_man *mdoc_alloc(struct roff *, struct mparse *, const char *, int); void mdoc_reset(struct roff_man *); +void mdoc_hash_init(void); int mdoc_parseln(struct roff_man *, int, char *, int); void mdoc_endparse(struct roff_man *); void mdoc_addspan(struct roff_man *, const struct tbl_span *); @@ -64,6 +65,7 @@ void man_free(struct roff_man *); struct roff_man *man_alloc(struct roff *, struct mparse *, const char *, int); void man_reset(struct roff_man *); +void man_hash_init(void); int man_parseln(struct roff_man *, int, char *, int); void man_endparse(struct roff_man *); void man_addspan(struct roff_man *, const struct tbl_span *); diff --git a/usr.bin/mandoc/libmdoc.h b/usr.bin/mandoc/libmdoc.h index be4c7e569c0..054b38f786c 100644 --- a/usr.bin/mandoc/libmdoc.h +++ b/usr.bin/mandoc/libmdoc.h @@ -1,4 +1,4 @@ -/* $OpenBSD: libmdoc.h,v 1.71 2015/04/18 16:04:40 schwarze Exp $ */ +/* $OpenBSD: libmdoc.h,v 1.72 2015/04/18 17:01:28 schwarze Exp $ */ /* * Copyright (c) 2008, 2009, 2010, 2011 Kristaps Dzonsons <kristaps@bsd.lv> * Copyright (c) 2013, 2014, 2015 Ingo Schwarze <schwarze@openbsd.org> @@ -80,7 +80,6 @@ struct roff_node *mdoc_endbody_alloc(struct roff_man *, int, int, int, struct roff_node *, enum mdoc_endbody); void mdoc_node_delete(struct roff_man *, struct roff_node *); void mdoc_node_relink(struct roff_man *, struct roff_node *); -void mdoc_hash_init(void); int mdoc_hash_find(const char *); const char *mdoc_a2att(const char *); const char *mdoc_a2st(const char *); diff --git a/usr.bin/mandoc/man.c b/usr.bin/mandoc/man.c index 010590b415e..62c0faea752 100644 --- a/usr.bin/mandoc/man.c +++ b/usr.bin/mandoc/man.c @@ -1,4 +1,4 @@ -/* $OpenBSD: man.c,v 1.102 2015/04/18 16:34:03 schwarze Exp $ */ +/* $OpenBSD: man.c,v 1.103 2015/04/18 17:01:28 schwarze Exp $ */ /* * Copyright (c) 2008, 2009, 2010, 2011 Kristaps Dzonsons <kristaps@bsd.lv> * Copyright (c) 2013, 2014, 2015 Ingo Schwarze <schwarze@openbsd.org> @@ -99,8 +99,6 @@ man_alloc(struct roff *roff, struct mparse *parse, struct roff_man *p; p = mandoc_calloc(1, sizeof(*p)); - - man_hash_init(); p->parse = parse; p->defos = defos; p->quick = quick; diff --git a/usr.bin/mandoc/man_hash.c b/usr.bin/mandoc/man_hash.c index d80a9257879..6d6f780cc29 100644 --- a/usr.bin/mandoc/man_hash.c +++ b/usr.bin/mandoc/man_hash.c @@ -1,4 +1,4 @@ -/* $OpenBSD: man_hash.c,v 1.21 2015/04/02 22:06:17 schwarze Exp $ */ +/* $OpenBSD: man_hash.c,v 1.22 2015/04/18 17:01:28 schwarze Exp $ */ /* * Copyright (c) 2008, 2009, 2010 Kristaps Dzonsons <kristaps@bsd.lv> * @@ -45,15 +45,14 @@ static unsigned char table[26 * HASH_DEPTH]; -/* - * XXX - this hash has global scope, so if intended for use as a library - * with multiple callers, it will need re-invocation protection. - */ void man_hash_init(void) { int i, j, x; + if (*table != '\0') + return; + memset(table, UCHAR_MAX, sizeof(table)); assert(MAN_MAX < UCHAR_MAX); diff --git a/usr.bin/mandoc/mdoc.c b/usr.bin/mandoc/mdoc.c index f17ade34b77..b0ce838de8f 100644 --- a/usr.bin/mandoc/mdoc.c +++ b/usr.bin/mandoc/mdoc.c @@ -1,4 +1,4 @@ -/* $OpenBSD: mdoc.c,v 1.132 2015/04/18 16:34:03 schwarze Exp $ */ +/* $OpenBSD: mdoc.c,v 1.133 2015/04/18 17:01:28 schwarze Exp $ */ /* * Copyright (c) 2008, 2009, 2010, 2011 Kristaps Dzonsons <kristaps@bsd.lv> * Copyright (c) 2010, 2012-2015 Ingo Schwarze <schwarze@openbsd.org> @@ -185,7 +185,6 @@ mdoc_alloc(struct roff *roff, struct mparse *parse, p->quick = quick; p->roff = roff; - mdoc_hash_init(); mdoc_alloc1(p); return(p); } diff --git a/usr.bin/mandoc/mdoc_hash.c b/usr.bin/mandoc/mdoc_hash.c index 5df9b4c5eb4..3d0ada9d09a 100644 --- a/usr.bin/mandoc/mdoc_hash.c +++ b/usr.bin/mandoc/mdoc_hash.c @@ -1,4 +1,4 @@ -/* $OpenBSD: mdoc_hash.c,v 1.18 2015/04/02 22:06:17 schwarze Exp $ */ +/* $OpenBSD: mdoc_hash.c,v 1.19 2015/04/18 17:01:28 schwarze Exp $ */ /* * Copyright (c) 2008, 2009 Kristaps Dzonsons <kristaps@bsd.lv> * @@ -30,16 +30,15 @@ static unsigned char table[27 * 12]; -/* - * XXX - this hash has global scope, so if intended for use as a library - * with multiple callers, it will need re-invocation protection. - */ void mdoc_hash_init(void) { int i, j, major; const char *p; + if (*table != '\0') + return; + memset(table, UCHAR_MAX, sizeof(table)); for (i = 0; i < (int)MDOC_MAX; i++) { diff --git a/usr.bin/mandoc/read.c b/usr.bin/mandoc/read.c index 3df1956d8b7..5d849d2fc8c 100644 --- a/usr.bin/mandoc/read.c +++ b/usr.bin/mandoc/read.c @@ -1,4 +1,4 @@ -/* $OpenBSD: read.c,v 1.110 2015/04/18 16:34:03 schwarze Exp $ */ +/* $OpenBSD: read.c,v 1.111 2015/04/18 17:01:28 schwarze Exp $ */ /* * Copyright (c) 2008, 2009, 2010, 2011 Kristaps Dzonsons <kristaps@bsd.lv> * Copyright (c) 2010-2015 Ingo Schwarze <schwarze@openbsd.org> @@ -291,6 +291,7 @@ choose_parser(struct mparse *curp) MPARSE_QUICK & curp->options ? 1 : 0); else curp->man->macroset = MACROSET_MDOC; + mdoc_hash_init(); return; } @@ -302,6 +303,7 @@ choose_parser(struct mparse *curp) MPARSE_QUICK & curp->options ? 1 : 0); else curp->man->macroset = MACROSET_MAN; + man_hash_init(); } /* @@ -868,14 +870,18 @@ mparse_alloc(int options, enum mandoclevel wlevel, mandocmsg mmsg, curp->mchars = mchars; curp->roff = roff_alloc(curp, curp->mchars, options); - if (curp->options & MPARSE_MDOC) + if (curp->options & MPARSE_MDOC) { curp->man = mdoc_alloc( curp->roff, curp, curp->defos, curp->options & MPARSE_QUICK ? 1 : 0); - if (curp->options & MPARSE_MAN) + mdoc_hash_init(); + } + if (curp->options & MPARSE_MAN) { curp->man = man_alloc( curp->roff, curp, curp->defos, curp->options & MPARSE_QUICK ? 1 : 0); + man_hash_init(); + } return(curp); } |