* mdocml: Move mdoc_hash_init() and man_hash_init() to libmandoc.h and
@ 2015-04-18 17:02 schwarze
0 siblings, 0 replies; only message in thread
From: schwarze @ 2015-04-18 17:02 UTC (permalink / raw)
To: source
Log Message:
-----------
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.
Modified Files:
--------------
mdocml:
libman.h
libmandoc.h
libmdoc.h
man.c
man_hash.c
mdoc.c
mdoc_hash.c
read.c
Revision Data
-------------
Index: man_hash.c
===================================================================
RCS file: /home/cvs/mdocml/mdocml/man_hash.c,v
retrieving revision 1.31
retrieving revision 1.32
diff -Lman_hash.c -Lman_hash.c -u -p -r1.31 -r1.32
--- man_hash.c
+++ man_hash.c
@@ -47,14 +47,13 @@
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));
Index: libmandoc.h
===================================================================
RCS file: /home/cvs/mdocml/mdocml/libmandoc.h,v
retrieving revision 1.56
retrieving revision 1.57
diff -Llibmandoc.h -Llibmandoc.h -u -p -r1.56 -r1.57
--- libmandoc.h
+++ 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 *);
Index: man.c
===================================================================
RCS file: /home/cvs/mdocml/mdocml/man.c,v
retrieving revision 1.154
retrieving revision 1.155
diff -Lman.c -Lman.c -u -p -r1.154 -r1.155
--- man.c
+++ man.c
@@ -101,8 +101,6 @@ man_alloc(struct roff *roff, struct mpar
struct roff_man *p;
p = mandoc_calloc(1, sizeof(*p));
-
- man_hash_init();
p->parse = parse;
p->defos = defos;
p->quick = quick;
Index: libman.h
===================================================================
RCS file: /home/cvs/mdocml/mdocml/libman.h,v
retrieving revision 1.71
retrieving revision 1.72
diff -Llibman.h -Llibman.h -u -p -r1.71 -r1.72
--- libman.h
+++ libman.h
@@ -43,7 +43,6 @@ void man_head_alloc(struct roff_man *
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 *);
Index: libmdoc.h
===================================================================
RCS file: /home/cvs/mdocml/mdocml/libmdoc.h,v
retrieving revision 1.100
retrieving revision 1.101
diff -Llibmdoc.h -Llibmdoc.h -u -p -r1.100 -r1.101
--- libmdoc.h
+++ libmdoc.h
@@ -80,7 +80,6 @@ struct roff_node *mdoc_endbody_alloc(str
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 *);
Index: read.c
===================================================================
RCS file: /home/cvs/mdocml/mdocml/read.c,v
retrieving revision 1.135
retrieving revision 1.136
diff -Lread.c -Lread.c -u -p -r1.135 -r1.136
--- read.c
+++ 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 mandoclev
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);
}
Index: mdoc_hash.c
===================================================================
RCS file: /home/cvs/mdocml/mdocml/mdoc_hash.c,v
retrieving revision 1.23
retrieving revision 1.24
diff -Lmdoc_hash.c -Lmdoc_hash.c -u -p -r1.23 -r1.24
--- mdoc_hash.c
+++ mdoc_hash.c
@@ -32,15 +32,14 @@
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));
Index: mdoc.c
===================================================================
RCS file: /home/cvs/mdocml/mdocml/mdoc.c,v
retrieving revision 1.243
retrieving revision 1.244
diff -Lmdoc.c -Lmdoc.c -u -p -r1.243 -r1.244
--- mdoc.c
+++ mdoc.c
@@ -187,7 +187,6 @@ mdoc_alloc(struct roff *roff, struct mpa
p->quick = quick;
p->roff = roff;
- mdoc_hash_init();
mdoc_alloc1(p);
return(p);
}
--
To unsubscribe send an email to source+unsubscribe@mdocml.bsd.lv
^ permalink raw reply [flat|nested] only message in thread
only message in thread, other threads:[~2015-04-18 17:02 UTC | newest]
Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2015-04-18 17:02 mdocml: Move mdoc_hash_init() and man_hash_init() to libmandoc.h and schwarze
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).