summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorIngo Schwarze <schwarze@openbsd.org>2015-04-18 17:01:58 +0000
committerIngo Schwarze <schwarze@openbsd.org>2015-04-18 17:01:58 +0000
commit4534f390e036ac23ee5e8f0373ffb9f4d785a17d (patch)
treeccd3380730c698bd52e2e5ea394772f7ac6e1e41
parent19dfb5cab356150bf46d159f43ead732a6a6ade5 (diff)
downloadmandoc-4534f390e036ac23ee5e8f0373ffb9f4d785a17d.tar.gz
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.
-rw-r--r--libman.h1
-rw-r--r--libmandoc.h2
-rw-r--r--libmdoc.h1
-rw-r--r--man.c2
-rw-r--r--man_hash.c7
-rw-r--r--mdoc.c1
-rw-r--r--mdoc_hash.c7
-rw-r--r--read.c10
8 files changed, 16 insertions, 15 deletions
diff --git a/libman.h b/libman.h
index 658dddb6..f1cc1c7c 100644
--- a/libman.h
+++ b/libman.h
@@ -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 779e3c11..c46fa691 100644
--- a/libmandoc.h
+++ b/libmandoc.h
@@ -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 da14cbd4..24fa4e04 100644
--- a/libmdoc.h
+++ b/libmdoc.h
@@ -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 337f9a99..364e58e7 100644
--- a/man.c
+++ b/man.c
@@ -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 52d67a2b..a0aed934 100644
--- a/man_hash.c
+++ b/man_hash.c
@@ -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 ba9cccc4..cb204910 100644
--- a/mdoc.c
+++ b/mdoc.c
@@ -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 2615c764..7f7a47b1 100644
--- a/mdoc_hash.c
+++ b/mdoc_hash.c
@@ -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 c0b566f5..16687bce 100644
--- a/read.c
+++ b/read.c
@@ -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);
}