xref: /plan9/sys/src/cmd/gs/src/ialloc.h (revision 593dc095aefb2a85c828727bbfa9da139a49bdf4)
1 /* Copyright (C) 1989, 1995, 1999 Aladdin Enterprises.  All rights reserved.
2 
3   This software is provided AS-IS with no warranty, either express or
4   implied.
5 
6   This software is distributed under license and may not be copied,
7   modified or distributed except as expressly authorized under the terms
8   of the license contained in the file LICENSE in this distribution.
9 
10   For more information about licensing, please refer to
11   http://www.ghostscript.com/licensing/. For information on
12   commercial licensing, go to http://www.artifex.com/licensing/ or
13   contact Artifex Software, Inc., 101 Lucas Valley Road #110,
14   San Rafael, CA  94903, U.S.A., +1(415)492-9861.
15 */
16 
17 /* $Id: ialloc.h,v 1.6 2004/08/04 19:36:12 stefan Exp $ */
18 /* Interface to Ghostscript interpreter memory allocator */
19 
20 #ifndef ialloc_INCLUDED
21 #  define ialloc_INCLUDED
22 
23 #include "imemory.h"
24 
25 /*
26  * Define the interpreter memory manager instance.
27  */
28 #define gs_imemory (i_ctx_p->memory)
29 #define idmemory (&gs_imemory)
30 #define iimemory (gs_imemory.current)
31 #define imemory ((gs_memory_t *)iimemory)
32 #define iimemory_local (gs_imemory.space_local)
33 #define imemory_local ((gs_memory_t *)iimemory_local)
34 #define iimemory_global (gs_imemory.space_global)
35 #define imemory_global ((gs_memory_t *)iimemory_global)
36 #define iimemory_system (gs_imemory.space_system)
37 #define imemory_system ((gs_memory_t *)iimemory_system)
38 
39 /*
40  * Aliases for invoking the standard allocator interface.
41  */
42 #define ialloc_bytes(nbytes, cname)\
43   gs_alloc_bytes(imemory, nbytes, cname)
44 #define ialloc_struct(typ, pstype, cname)\
45   gs_alloc_struct(imemory, typ, pstype, cname)
46 #define ialloc_byte_array(nelts, esize, cname)\
47   gs_alloc_byte_array(imemory, nelts, esize, cname)
48 #define ialloc_struct_array(nelts, typ, pstype, cname)\
49   gs_alloc_struct_array(imemory, nelts, typ, pstype, cname)
50 #define ifree_object(data, cname)\
51   gs_free_object(imemory, data, cname)
52 #define ifree_const_object(data, cname)\
53   gs_free_const_object(imemory, data, cname)
54 #define ialloc_string(nbytes, cname)\
55   gs_alloc_string(imemory, nbytes, cname)
56 #define iresize_string(data, oldn, newn, cname)\
57   gs_resize_string(imemory, data, oldn, newn, cname)
58 #define ifree_string(data, nbytes, cname)\
59   gs_free_string(imemory, data, nbytes, cname)
60 #define ifree_const_string(data, nbytes, cname)\
61   gs_free_const_string(imemory, data, nbytes, cname)
62 
63 /* Initialize the interpreter's allocator. */
64 int ialloc_init(gs_dual_memory_t *, gs_memory_t *, uint, bool);
65 
66 /* ------ Internal routines ------ */
67 
68 /* Reset the request values that identify the cause of a GC. */
69 void ialloc_reset_requested(gs_dual_memory_t *);
70 
71 /* Validate the contents of memory. */
72 void ialloc_validate_spaces(const gs_dual_memory_t *);
73 
74 #define ivalidate_spaces() ialloc_validate_spaces(idmemory)
75 
76 /*
77  * Local/global VM management.
78  */
79 
80 /* Get the space attribute of the current allocator. */
81 #define ialloc_space(dmem) ((dmem)->current_space)
82 #define icurrent_space ialloc_space(idmemory)
83 uint imemory_space(const gs_ref_memory_t *);
84 
85 /* Select the allocation space. */
86 void ialloc_set_space(gs_dual_memory_t *, uint);
87 
88 /* Get the l_new attribute of an allocator. */
89 uint imemory_new_mask(const gs_ref_memory_t *);
90 
91 /* Get the save level of an allocator. */
92 int imemory_save_level(const gs_ref_memory_t *);
93 
94 /*
95  * Ref-related facilities.
96  */
97 
98 #ifdef r_type			/* i.e., we know about refs */
99 
100 /* Allocate and free ref arrays. */
101 #define ialloc_ref_array(paref, attrs, nrefs, cname)\
102   gs_alloc_ref_array(iimemory, paref, attrs, nrefs, cname)
103 #define iresize_ref_array(paref, nrefs, cname)\
104   gs_resize_ref_array(iimemory, paref, nrefs, cname)
105 #define ifree_ref_array(paref, cname)\
106   gs_free_ref_array(iimemory, paref, cname)
107 
108 /* Allocate a string ref. */
109 #define ialloc_string_ref(psref, attrs, nbytes, cname)\
110   gs_alloc_string_ref(iimemory, psref, attrs, nbytes, cname)
111 
112 /* Make a ref for a newly allocated structure. */
113 #define make_istruct(pref,attrs,ptr)\
114   make_struct(pref, (attrs) | icurrent_space, ptr)
115 #define make_istruct_new(pref,attrs,ptr)\
116   make_struct_new(pref, (attrs) | icurrent_space, ptr)
117 #define make_iastruct(pref,attrs,ptr)\
118   make_astruct(pref, (attrs) | icurrent_space, ptr)
119 #define make_iastruct_new(pref,attrs,ptr)\
120   make_astruct_new(pref, (attrs) | icurrent_space, ptr)
121 
122 #endif /* ifdef r_type */
123 
124 #endif /* ialloc_INCLUDED */
125