1 #ifndef MP_STRTAB_H
2 #define MP_STRTAB_H
3 
4 
5 /*
6  * mpatrol
7  * A library for controlling and tracing dynamic memory allocations.
8  * Copyright (C) 1997-2002 Graeme S. Roy <graeme.roy@analog.com>
9  *
10  * This library is free software; you can redistribute it and/or
11  * modify it under the terms of the GNU Library General Public
12  * License as published by the Free Software Foundation; either
13  * version 2 of the License, or (at your option) any later version.
14  *
15  * This library is distributed in the hope that it will be useful,
16  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
18  * Library General Public License for more details.
19  *
20  * You should have received a copy of the GNU Library General Public
21  * License along with this library; if not, write to the Free
22  * Software Foundation, Inc., 59 Temple Place, Suite 330, Boston,
23  * MA 02111-1307, USA.
24  */
25 
26 
27 /*
28  * String tables.  Any strings that require to be preserved by the
29  * symbol table module are stored in a string table allocated by this
30  * module.
31  */
32 
33 
34 /*
35  * $Id: strtab.h,v 1.11 2002/01/08 20:13:59 graeme Exp $
36  */
37 
38 
39 #include "config.h"
40 #include "list.h"
41 #include "heap.h"
42 
43 
44 /* A hash entry is used to maintain a hash table of strings so that
45  * only unique strings are ever stored in the string table.
46  */
47 
48 typedef struct hashentry
49 {
50     listnode node;   /* list node */
51     union
52     {
53         void *block; /* pointer to internal block */
54         char *key;   /* pointer to string in table */
55     }
56     data;
57     size_t size;     /* size of internal block or string */
58 }
59 hashentry;
60 
61 
62 /* A strnode belongs to a binary search tree of strnodes, ordered
63  * by available space, and contains details of a single allocated block
64  * of memory, as well as a pointer to the first available character.
65  * A strnode structure actually occupies the first bytes of its
66  * block of memory.
67  */
68 
69 typedef struct strnode
70 {
71     treenode node; /* tree node */
72     void *block;   /* pointer to block of memory */
73     char *next;    /* pointer to first available character */
74     size_t avail;  /* available space left in block */
75     size_t size;   /* size of block of memory */
76 }
77 strnode;
78 
79 
80 /* A strtab holds the hash table of strings and the tree of strnodes
81  * that comprise the string table.  A new strnode is added to the string
82  * table if there is not enough space to store a particular string.
83  */
84 
85 typedef struct strtab
86 {
87     heaphead *heap;                  /* pointer to heap */
88     slottable table;                 /* table of hash entries */
89     listhead slots[MP_HASHTAB_SIZE]; /* array of lists for hash entries */
90     listhead list;                   /* internal list of memory blocks */
91     treeroot tree;                   /* allocation tree */
92     size_t size;                     /* allocation total */
93     size_t align;                    /* alignment for each strnode */
94     memaccess prot;                  /* protection status */
95     size_t protrecur;                /* protection recursion count */
96 }
97 strtab;
98 
99 
100 #ifdef __cplusplus
101 extern "C"
102 {
103 #endif /* __cplusplus */
104 
105 
106 MP_EXPORT void __mp_newstrtab(strtab *, heaphead *);
107 MP_EXPORT void __mp_deletestrtab(strtab *);
108 MP_EXPORT char *__mp_addstring(strtab *, char *);
109 MP_EXPORT int __mp_protectstrtab(strtab *, memaccess);
110 
111 
112 #ifdef __cplusplus
113 }
114 #endif /* __cplusplus */
115 
116 
117 #endif /* MP_STRTAB_H */
118