2 * Copyright (c) 1999-2001
3 * The Regents of the University of California. All rights reserved.
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
8 * 1. Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer.
10 * 2. Redistributions in binary form must reproduce the above copyright
11 * notice, this list of conditions and the following disclaimer in the
12 * documentation and/or other materials provided with the distribution.
13 * 3. Neither the name of the University nor the names of its contributors
14 * may be used to endorse or promote products derived from this software
15 * without specific prior written permission.
17 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
18 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
19 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
20 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
21 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
22 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
23 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
24 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
25 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
26 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
35 typedef struct Region
*region
;
39 void region_init(void); /* You MUST call this function before using any
40 part of this library */
42 region
newregion(void);
43 region
newsubregion(region parent
);
46 #define rctypeof(type) 0
48 /* Low-level alloc with dynamic type info */
49 void *typed_ralloc(region r
, size_t size
, type_t type
);
50 void *typed_rarrayalloc(region r
, size_t n
, size_t size
, type_t type
);
51 void *typed_rarrayextend(region r
, void *old
, size_t n
, size_t size
, type_t type
);
52 void typed_rarraycopy(void *to
, void *from
, size_t n
, size_t size
, type_t type
);
54 #define ralloc(r, type) typed_ralloc((r), sizeof(type), rctypeof(type))
55 #define rarrayalloc(r, n, type) typed_rarrayalloc((r), (n), sizeof(type), rctypeof(type))
56 #define rarrayextend(r, old, n, type) typed_rarrayextend((r), (old), (n), sizeof(type), rctypeof(type))
57 #define rarraycopy(to, from, n, type) typed_rarraycopy((to), (from), (n), sizeof(type), rctypeof(type))
59 char *rstralloc(region r
, size_t size
);
60 char *rstralloc0(region r
, size_t size
);
61 char *rstrdup(region r
, const char *s
);
63 /* rstrextend is used to extend an old string. The string MUST have been
64 initially allocated by a call to rstrextend with old == NULL (you cannot
65 initially allocate the string with rstralloc) */
66 char *rstrextend(region r
, const char *old
, size_t newsize
);
67 char *rstrextend0(region r
, const char *old
, size_t newsize
);
69 void deleteregion(region r
);
70 void deleteregion_ptr(region
*r
);
71 void deleteregion_array(int n
, region
*regions
);
72 region
regionof(void *ptr
);
74 typedef void (*nomem_handler
)(void);
75 nomem_handler
set_nomem_handler(nomem_handler newhandler
);
77 /* Debugging support */
78 void findrefs(region r
, void *from
, void *to
);
79 void findgrefs(region r
);
80 void findrrefs(region r
, region from
);