aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/mdoc.c
diff options
context:
space:
mode:
authorKristaps Dzonsons <kristaps@bsd.lv>2010-12-24 14:00:40 +0000
committerKristaps Dzonsons <kristaps@bsd.lv>2010-12-24 14:00:40 +0000
commit59221c379641a8d3a180c8b0cca2022c763c2a6b (patch)
tree6c5d517b8524c16e1b33aaeea7477c395876ea30 /mdoc.c
parentd1f1f8d600d26e5bb01736ad53269bed555043d5 (diff)
downloadmandoc-59221c379641a8d3a180c8b0cca2022c763c2a6b.tar.gz
mandoc-59221c379641a8d3a180c8b0cca2022c763c2a6b.tar.zst
mandoc-59221c379641a8d3a180c8b0cca2022c763c2a6b.zip
As per schwarze@'s suggestions, roll back the refcount structure in
favour of a simpler shim for normalised data in the node allocation and free routines. This removes the need to bump and copy references within validator handlers, removes a pointer redirect, and also kills the refcount structure itself. Data is assumed to "live" either in a MDOC_BLOCK or MDOC_ELEM and is copied accordingly.
Diffstat (limited to 'mdoc.c')
-rw-r--r--mdoc.c52
1 files changed, 45 insertions, 7 deletions
diff --git a/mdoc.c b/mdoc.c
index a2cd83f1..a30e8be5 100644
--- a/mdoc.c
+++ b/mdoc.c
@@ -1,4 +1,4 @@
-/* $Id: mdoc.c,v 1.171 2010/12/22 11:15:16 kristaps Exp $ */
+/* $Id: mdoc.c,v 1.172 2010/12/24 14:00:40 kristaps Exp $ */
/*
* Copyright (c) 2008, 2009, 2010 Kristaps Dzonsons <kristaps@bsd.lv>
* Copyright (c) 2010 Ingo Schwarze <schwarze@openbsd.org>
@@ -328,6 +328,23 @@ node_append(struct mdoc *mdoc, struct mdoc_node *p)
p->parent->nchild++;
+ /*
+ * Copy over the normalised-data pointer of our parent. Not
+ * everybody has one, but copying a null pointer is fine.
+ */
+
+ switch (p->type) {
+ case (MDOC_BODY):
+ /* FALLTHROUGH */
+ case (MDOC_TAIL):
+ /* FALLTHROUGH */
+ case (MDOC_HEAD):
+ p->norm = p->parent->norm;
+ break;
+ default:
+ break;
+ }
+
if ( ! mdoc_valid_pre(mdoc, p))
return(0);
@@ -460,6 +477,19 @@ mdoc_block_alloc(struct mdoc *m, int line, int pos,
p->args = args;
if (p->args)
(args->refcnt)++;
+
+ switch (tok) {
+ case (MDOC_Bd):
+ /* FALLTHROUGH */
+ case (MDOC_Bf):
+ /* FALLTHROUGH */
+ case (MDOC_Bl):
+ p->norm = mandoc_calloc(1, sizeof(union mdoc_data));
+ break;
+ default:
+ break;
+ }
+
if ( ! node_append(m, p))
return(0);
m->next = MDOC_NEXT_CHILD;
@@ -477,6 +507,15 @@ mdoc_elem_alloc(struct mdoc *m, int line, int pos,
p->args = args;
if (p->args)
(args->refcnt)++;
+
+ switch (tok) {
+ case (MDOC_An):
+ p->norm = mandoc_calloc(1, sizeof(union mdoc_data));
+ break;
+ default:
+ break;
+ }
+
if ( ! node_append(m, p))
return(0);
m->next = MDOC_NEXT_CHILD;
@@ -511,9 +550,8 @@ static void
mdoc_node_free(struct mdoc_node *p)
{
- if (p->norm && 0 == --(p->norm->refcnt))
+ if (MDOC_BLOCK == p->type || MDOC_ELEM == p->type)
free(p->norm);
-
if (p->string)
free(p->string);
if (p->args)
@@ -608,7 +646,7 @@ mdoc_ptext(struct mdoc *m, int line, char *buf, int offs)
*/
if (MDOC_Bl == n->tok && MDOC_BODY == n->type &&
- LIST_column == n->norm->d.Bl.type) {
+ LIST_column == n->norm->Bl.type) {
/* `Bl' is open without any children. */
m->flags |= MDOC_FREECOL;
return(mdoc_macro(m, MDOC_It, line, offs, &offs, buf));
@@ -617,7 +655,7 @@ mdoc_ptext(struct mdoc *m, int line, char *buf, int offs)
if (MDOC_It == n->tok && MDOC_BLOCK == n->type &&
NULL != n->parent &&
MDOC_Bl == n->parent->tok &&
- LIST_column == n->parent->norm->d.Bl.type) {
+ LIST_column == n->parent->norm->Bl.type) {
/* `Bl' has block-level `It' children. */
m->flags |= MDOC_FREECOL;
return(mdoc_macro(m, MDOC_It, line, offs, &offs, buf));
@@ -798,7 +836,7 @@ mdoc_pmacro(struct mdoc *m, int ln, char *buf, int offs)
*/
if (MDOC_Bl == n->tok && MDOC_BODY == n->type &&
- LIST_column == n->norm->d.Bl.type) {
+ LIST_column == n->norm->Bl.type) {
m->flags |= MDOC_FREECOL;
if ( ! mdoc_macro(m, MDOC_It, ln, sv, &sv, buf))
goto err;
@@ -814,7 +852,7 @@ mdoc_pmacro(struct mdoc *m, int ln, char *buf, int offs)
if (MDOC_It == n->tok && MDOC_BLOCK == n->type &&
NULL != n->parent &&
MDOC_Bl == n->parent->tok &&
- LIST_column == n->parent->norm->d.Bl.type) {
+ LIST_column == n->parent->norm->Bl.type) {
m->flags |= MDOC_FREECOL;
if ( ! mdoc_macro(m, MDOC_It, ln, sv, &sv, buf))
goto err;