summaryrefslogtreecommitdiffabout
path: root/doc
authorSergey Poznyakoff <gray@gnu.org.ua>2011-05-06 21:24:03 (GMT)
committer Sergey Poznyakoff <gray@gnu.org.ua>2011-05-06 21:24:03 (GMT)
commited39daa568d162617a183497010d70a55a38ae73 (patch) (side-by-side diff)
tree313c1caef8b42ab1800f5c1cef8dece9116fbd0d /doc
parent18d7db07b9f369901300bf664d07d4b39032ce64 (diff)
downloadgrecs-ed39daa568d162617a183497010d70a55a38ae73.tar.gz
grecs-ed39daa568d162617a183497010d70a55a38ae73.tar.bz2
Redo memory management (2).
* src/grecs.h (grecs_free_fun): New extern. (grecs_free): New proto. * src/format.c: Use grecs_free where appropriate. * src/grecs-lex.l: Likewise. * src/preproc.c: Likewise. * src/tree.c: Likewise. * src/lookup.c (parse_label): Use grecs_value_list_create. * src/mem.c: Initialize hooks with the default values. (grecs_free_fun): New hook. (grecs_free): New function. * doc/grecs_malloc.3: Document grecs_free. * doc/grecs_parse.3: Document the recent changes. * doc/grecs_strdup.3: Update.
Diffstat (limited to 'doc') (more/less context) (ignore whitespace changes)
-rw-r--r--doc/grecs_malloc.330
-rw-r--r--doc/grecs_parse.326
-rw-r--r--doc/grecs_strdup.36
3 files changed, 43 insertions, 19 deletions
diff --git a/doc/grecs_malloc.3 b/doc/grecs_malloc.3
index 58cc9a0..1d52eca 100644
--- a/doc/grecs_malloc.3
+++ b/doc/grecs_malloc.3
@@ -16,7 +16,7 @@
.\" This file is part of SLB.
.\" Copyright (C) 2011 Sergey Poznyakoff
.\"
-.TH GRECS_MALLOC 3 "May 3, 2011" "GRECS" "Grecs User Reference"
+.TH GRECS_MALLOC 3 "May 7, 2011" "GRECS" "Grecs User Reference"
.SH NAME
grecs_malloc, grecs_zalloc, grecs_calloc, grecs_realloc \- Allocate
dynamic memory for \fBGrecs\fR.
@@ -32,12 +32,16 @@ dynamic memory for \fBGrecs\fR.
.br
.BI "void *grecs_realloc(void " "*ptr" ", size_t " "size" );
.br
+.BI "void grecs_free(void " "*ptr" );
+.br
.BI "void grecs_alloc_die(void);"
.sp
.BI "void *(*grecs_malloc_fun)(size_t " "size" );
.br
.BI "void *(*grecs_realloc_fun)(void " "*ptr" ", size_t " "size" );
.br
+.BI "void (*grecs_free_fun)(void " "*ptr" );
+.br
.BI "void (*grecs_alloc_die_fun)(void);"
.SH DESCRIPTION
.PP
@@ -76,14 +80,24 @@ allocates
bytes and returns a pointer to the allocated memory. The memory is
set to zero.
.PP
-If \fBgrecs_malloc_fun\fR is not \fINULL\fR, it will be used by
-\fBgrecs_malloc\fR, \fBgrecs_calloc\fR and \fBgrecs_zalloc\fR to
-allocate new memory chunk. If it is not set, these function use
-\fBmalloc(3)\fR.
+.BR grecs_free ()
+frees the memory space pointed to by \fBptr\fR, which must have been
+returned by a previous call to one of the memory allocation functions
+discussed above.
+.PP
+The \fBgrecs_malloc_fun\fR hook is used \fBgrecs_malloc\fR,
+\fBgrecs_calloc\fR and \fBgrecs_zalloc\fR to allocate new memory
+chunk. By default it points to
+.BR malloc (3).
+.PP
+Similarly, the \fBgrecs_realloc_fun\fR, is used by
+\fBgrecs_realloc\fR function. By default it points to
+.BR realloc (3).
.PP
-Similarly, the \fBgrecs_realloc_fun\fR, if set, is used by
-\fBgrecs_realloc\fR function. Otherwise, this function uses
-\fBrealloc(3)\fR.
+The \fBgrecs_free_fun\fR is used by
+.BR grecs_free ().
+By default it points to
+.BR free (3).
.PP
These hooks provide a way for the calling program to use its custom
memory allocation routines.
diff --git a/doc/grecs_parse.3 b/doc/grecs_parse.3
index 357889f..c51ef95 100644
--- a/doc/grecs_parse.3
+++ b/doc/grecs_parse.3
@@ -16,7 +16,7 @@
.\" This file is part of SLB.
.\" Copyright (C) 2011 Sergey Poznyakoff
.\"
-.TH GRECS_PARSE 3 "May 4, 2011" "GRECS" "Grecs User Reference"
+.TH GRECS_PARSE 3 "May 7, 2011" "GRECS" "Grecs User Reference"
.SH NAME
grecs_parse \- parse a configuration file.
.SH SYNOPSIS
@@ -48,14 +48,18 @@ typedef struct grecs_node {
struct grecs_node *next;
struct grecs_node *prev;
char *ident;
- struct grecs_value value;
+ union {
+ struct grecs_value *value;
+ struct grecs_symtab *texttab;
+ } v;
} grecs_node_t;
.in
.fi
.PP
The \fItype\fR member describes the type of this node. Its value is
-\fBgrecs_node_stmt\fR for simple statements, and
-\fBgrecs_node_block\fR, for block statements.
+\fBgrecs_node_stmt\fR for simple statements and
+\fBgrecs_node_block\fR, for block statements. The topmost node (the
+one returned by \fBgrecs_tree_parse\fR) has type \fBgrecs_node_root\fR.
.PP
The \fIlocus\fR describes the location in the input file, which this
node described. See
@@ -97,8 +101,14 @@ pidfile "/var/run/mypid";
.sp
will have \fBident\fR pointing to the string \fB/var/run/mypid\fR.
.PP
-Finally, the \fBvalue\fR member keeps the value associated with this
-statement. It is defined as:
+The \fBv\fR union keeps data which depend on the type of this node.
+The \fBv.texttab\fR member is defined only for the root node (type
+\fBgrecs_node_root\fR). It points to a symbol table which holds shared
+strings for this tree. In particular, this table holds file names
+referenced by \fBlocus\fR members of all underlying nodes.
+.PP
+For non-root nodes,the \fBv.value\fR member is defined. It points to
+the value associated with this statement. A value is defined as:
.sp
.nf
.in +5
@@ -106,10 +116,10 @@ typedef struct grecs_value {
int type;
union {
struct grecs_list *list;
- const char *string;
+ char *string;
struct {
size_t c;
- struct grecs_value *v;
+ struct grecs_value **v;
} arg;
} v;
} grecs_value_t;
diff --git a/doc/grecs_strdup.3 b/doc/grecs_strdup.3
index 441eb23..ae861e4 100644
--- a/doc/grecs_strdup.3
+++ b/doc/grecs_strdup.3
@@ -16,7 +16,7 @@
.\" This file is part of SLB.
.\" Copyright (C) 2011 Sergey Poznyakoff
.\"
-.TH GRECS_STRDUP 3 "May 3, 2011" "GRECS" "Grecs User Reference"
+.TH GRECS_STRDUP 3 "May 7, 2011" "GRECS" "Grecs User Reference"
.SH NAME
grecs_strdup \- duplicate a string
.SH SYNOPSIS
@@ -31,8 +31,8 @@ The
function returns a pointer to a new string which is a duplicate of the
string \fIstr\fR. Memory for the new string is obtained with
.BR grecs_malloc (3),
-and can be freed with
-.BR free(3).
+and must be freed with
+.BR grecs_free (3).
.SH "RETURN VALUE"
The
.BR grecs_strdup ()

Return to:

Send suggestions and report system problems to the System administrator.