1 /* b-divvy.h --- dynamic memory manglement
2 
3    Copyright (C) 2010-2020 Thien-Thi Nguyen
4 
5    This file is part of GNU RCS.
6 
7    GNU RCS is free software: you can redistribute it and/or modify it
8    under the terms of the GNU General Public License as published by
9    the Free Software Foundation, either version 3 of the License, or
10    (at your option) any later version.
11 
12    GNU RCS is distributed in the hope that it will be useful,
13    but WITHOUT ANY WARRANTY; without even the implied warranty
14    of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
15    See the GNU General Public License for more details.
16 
17    You should have received a copy of the GNU General Public License
18    along with this program.  If not, see <http://www.gnu.org/licenses/>.
19 */
20 
21 #include <obstack.h>
22 
23 struct divvy
24 {
25   char const *name;
26   struct obstack space;
27   void *first;
28   size_t count;
29 };
30 
31 extern struct divvy *plexus;
32 extern struct divvy *single;
33 
34 extern struct divvy *make_space (char const name[])
35   ALL_NONNULL;
36 extern void *alloc (struct divvy *divvy, size_t len)
37   ALL_NONNULL;
38 extern void *zlloc (struct divvy *divvy, size_t len)
39   ALL_NONNULL;
40 extern char *intern (struct divvy *divvy, char const *s, size_t len)
41   ALL_NONNULL;
42 extern void brush_off (struct divvy *divvy, void *ptr)
43   ALL_NONNULL;
44 extern void forget (struct divvy *divvy)
45   ALL_NONNULL;
46 extern void accf (struct divvy *divvy, char const *fmt, ...)
47   ARG_NONNULL ((1, 2));
48 extern void accumulate_nbytes (struct divvy *divvy,
49                                char const *start, size_t count)
50   ALL_NONNULL;
51 extern void accumulate_byte (struct divvy *divvy, int c)
52   ALL_NONNULL;
53 extern void accumulate_range (struct divvy *divvy,
54                               char const *beg, char const *end)
55   ALL_NONNULL;
56 extern void accs (struct divvy *divvy, char const *string)
57   ALL_NONNULL;
58 extern char *finish_string (struct divvy *divvy, size_t *result_len)
59   ALL_NONNULL;
60 extern void *pointer_array (struct divvy *divvy, size_t count)
61   ALL_NONNULL;
62 extern void close_space (struct divvy *divvy)
63   ALL_NONNULL;
64 
65 /* Idioms.  */
66 
67 #define PLEXUS  plexus
68 #define SINGLE  single
69 
70 #define ZLLOC(n,type)          (zlloc (PLEXUS, sizeof (type) * n))
71 #define FALLOC(type)           (alloc (SINGLE, sizeof (type)))
72 #define FZLLOC(type)           (zlloc (SINGLE, sizeof (type)))
73 
74 #define SHACCR(b,e)      accumulate_range (PLEXUS, b, e)
75 #define SHSTR(szp)       finish_string (PLEXUS, szp)
76 #define SHSNIP(szp,b,e)  (SHACCR (b, e), SHSTR (szp))
77 
78 /* b-divvy.h ends here */
79