From 24719645e5444a6acaeb47260a958a471c5eeffe Mon Sep 17 00:00:00 2001 From: Ingo Schwarze Date: Sat, 18 Apr 2015 17:01:58 +0000 Subject: 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. --- libman.h | 3 +-- libmandoc.h | 4 +++- libmdoc.h | 3 +-- man.c | 4 +--- man_hash.c | 9 ++++----- mdoc.c | 3 +-- mdoc_hash.c | 9 ++++----- read.c | 12 +++++++++--- 8 files changed, 24 insertions(+), 23 deletions(-) diff --git a/libman.h b/libman.h index d5166ed3..916d9576 100644 --- a/libman.h +++ b/libman.h @@ -1,4 +1,4 @@ -/* $Id: libman.h,v 1.71 2015/04/18 16:06:39 schwarze Exp $ */ +/* $Id: libman.h,v 1.72 2015/04/18 17:01:58 schwarze Exp $ */ /* * Copyright (c) 2009, 2010, 2011 Kristaps Dzonsons * Copyright (c) 2014, 2015 Ingo Schwarze @@ -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/libmandoc.h b/libmandoc.h index 5aac4253..c16cf4d3 100644 --- a/libmandoc.h +++ b/libmandoc.h @@ -1,4 +1,4 @@ -/* $Id: libmandoc.h,v 1.56 2015/04/18 16:06:39 schwarze Exp $ */ +/* $Id: libmandoc.h,v 1.57 2015/04/18 17:01:58 schwarze Exp $ */ /* * Copyright (c) 2009, 2010, 2011, 2012 Kristaps Dzonsons * Copyright (c) 2013, 2014, 2015 Ingo Schwarze @@ -58,6 +58,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 *); @@ -67,6 +68,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/libmdoc.h b/libmdoc.h index 50c0c5fd..98123f71 100644 --- a/libmdoc.h +++ b/libmdoc.h @@ -1,4 +1,4 @@ -/* $Id: libmdoc.h,v 1.100 2015/04/18 16:06:39 schwarze Exp $ */ +/* $Id: libmdoc.h,v 1.101 2015/04/18 17:01:58 schwarze Exp $ */ /* * Copyright (c) 2008, 2009, 2010, 2011 Kristaps Dzonsons * Copyright (c) 2013, 2014, 2015 Ingo Schwarze @@ -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_a2lib(const char *); diff --git a/man.c b/man.c index 105dd9c1..f2ee0c18 100644 --- a/man.c +++ b/man.c @@ -1,4 +1,4 @@ -/* $Id: man.c,v 1.154 2015/04/18 16:34:25 schwarze Exp $ */ +/* $Id: man.c,v 1.155 2015/04/18 17:01:58 schwarze Exp $ */ /* * Copyright (c) 2008, 2009, 2010, 2011 Kristaps Dzonsons * Copyright (c) 2013, 2014, 2015 Ingo Schwarze @@ -101,8 +101,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/man_hash.c b/man_hash.c index 8726614a..c3023799 100644 --- a/man_hash.c +++ b/man_hash.c @@ -1,4 +1,4 @@ -/* $Id: man_hash.c,v 1.31 2015/04/02 22:48:17 schwarze Exp $ */ +/* $Id: man_hash.c,v 1.32 2015/04/18 17:01:58 schwarze Exp $ */ /* * Copyright (c) 2008, 2009, 2010 Kristaps Dzonsons * @@ -47,15 +47,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/mdoc.c b/mdoc.c index 04b2a21a..69abb376 100644 --- a/mdoc.c +++ b/mdoc.c @@ -1,4 +1,4 @@ -/* $Id: mdoc.c,v 1.243 2015/04/18 16:34:25 schwarze Exp $ */ +/* $Id: mdoc.c,v 1.244 2015/04/18 17:01:58 schwarze Exp $ */ /* * Copyright (c) 2008, 2009, 2010, 2011 Kristaps Dzonsons * Copyright (c) 2010, 2012-2015 Ingo Schwarze @@ -187,7 +187,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/mdoc_hash.c b/mdoc_hash.c index cd576511..0da3c9a1 100644 --- a/mdoc_hash.c +++ b/mdoc_hash.c @@ -1,4 +1,4 @@ -/* $Id: mdoc_hash.c,v 1.23 2015/04/02 22:48:17 schwarze Exp $ */ +/* $Id: mdoc_hash.c,v 1.24 2015/04/18 17:01:58 schwarze Exp $ */ /* * Copyright (c) 2008, 2009 Kristaps Dzonsons * @@ -32,16 +32,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/read.c b/read.c index bde299c9..1417aeca 100644 --- a/read.c +++ b/read.c @@ -1,4 +1,4 @@ -/* $Id: read.c,v 1.135 2015/04/18 16:34:25 schwarze Exp $ */ +/* $Id: read.c,v 1.136 2015/04/18 17:01:58 schwarze Exp $ */ /* * Copyright (c) 2008, 2009, 2010, 2011 Kristaps Dzonsons * Copyright (c) 2010-2015 Ingo Schwarze @@ -296,6 +296,7 @@ choose_parser(struct mparse *curp) MPARSE_QUICK & curp->options ? 1 : 0); else curp->man->macroset = MACROSET_MDOC; + mdoc_hash_init(); return; } @@ -307,6 +308,7 @@ choose_parser(struct mparse *curp) MPARSE_QUICK & curp->options ? 1 : 0); else curp->man->macroset = MACROSET_MAN; + man_hash_init(); } /* @@ -890,14 +892,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); } -- cgit v1.2.3-56-ge451