386BSD 0.1 development
[unix-history] / usr / othersrc / public / ghostscript-2.4.1 / nalloc.h
CommitLineData
520b1580
WJ
1/* Copyright (C) 1991, 1992 Aladdin Enterprises. All rights reserved.
2 Distributed by Free Software Foundation, Inc.
3
4This file is part of Ghostscript.
5
6Ghostscript is distributed in the hope that it will be useful, but
7WITHOUT ANY WARRANTY. No author or distributor accepts responsibility
8to anyone for the consequences of using it or for whether it serves any
9particular purpose or works at all, unless he says so in writing. Refer
10to the Ghostscript General Public License for full details.
11
12Everyone is granted permission to copy, modify and redistribute
13Ghostscript, but only under the conditions described in the Ghostscript
14General Public License. A copy of this license is supposed to have been
15given to you along with Ghostscript so you can know your rights and
16responsibilities. It should be in a file named COPYING. Among other
17things, the copyright notice and this notice must be preserved on all
18copies. */
19
20/* nalloc.h */
21/* Library client interface for new Ghostscript allocator */
22
23/* Define the type for the size of an object. */
24typedef uint usize_t;
25
26/* Define the type for identifying an allocator client. */
27typedef char _ds *client_name_t;
28
29/* Define the type for an allocator instance. */
30struct alloc_state_s;
31typedef struct alloc_state_s _ds *as_ptr_t;
32
33/* Define the type for a structure descriptor. */
34struct struct_type_s;
35typedef struct struct_type_s _ds *at_ptr_t;
36
37/* Define the type for allocator statistics. */
38typedef struct alloc_status_s {
39 ulong allocated;
40 ulong used;
41} alloc_status_t;
42
43/* Define the allocator client procedures */
44typedef struct alloc_procs_s alloc_procs_t;
45struct alloc_procs_s {
46
47 /* Allocate a structure */
48#define alloc_proc_alloc_struct(proc)\
49 void *proc(P3(as_ptr_t, at_ptr_t, client_name_t))
50 alloc_proc_alloc_struct((*alloc_struct));
51#define gs_alloc_struct(ap,tp,cn) (*(ap)->procs.alloc_struct)(ap,tp,cn)
52
53 /* Allocate (aligned) bytes */
54#define alloc_proc_alloc_bytes(proc)\
55 byte *proc(P4(as_ptr_t, uint, uint, client_name_t))
56 alloc_proc_alloc_bytes((*alloc_bytes));
57#define gs_alloc_bytes(ap,es,n,cn) (*(ap)->procs.alloc_bytes)(ap,es,n,cn)
58
59 /* Change the size of a byte object */
60#define alloc_proc_resize(proc)\
61 byte *proc(P5(as_ptr_t, byte *, uint, uint, client_name_t))
62 alloc_proc_resize((*resize));
63#define gs_resize(ap,p,es,n,cn) (*(ap)->procs.resize)(ap,p,es,n,cn)
64
65 /* Free an object (structure or bytes) */
66#define alloc_proc_free(proc)\
67 void proc(P3(as_ptr_t, void *, client_name_t))
68 alloc_proc_free((*free));
69#define gs_free(ap,p,cn) (*(ap)->procs.free)(ap,p,cn)
70
71 /* Report status (assigned, used) */
72#define alloc_proc_status(proc)\
73 void proc(P2(as_ptr_t, alloc_status_t *))
74 alloc_proc_status((*status));
75#define gs_alloc_status(ap,s) (*(ap)->procs.status)(ap,s)
76
77};
78
79/* Define the generic allocator state. */
80/* "Subclasses" will extend this. */
81#define alloc_state_common\
82 alloc_procs_t procs
83struct alloc_state_s {
84 alloc_state_common;
85};
86
87/* Define the standard Ghostscript allocator implementation. */
88extern alloc_procs_t gs_alloc_std_procs;
89
90/* ====== Root-registering clients ====== */
91union struct_header_s;
92struct ref_s;
93
94/* Define the type for a pointer descriptor. */
95typedef struct ptr_procs_s {
96
97 /* Mark the referent of a pointer. */
98#define ptr_proc_mark(proc)\
99 bool proc(P1(void *))
100 ptr_proc_mark((*mark));
101
102 /* Relocate a pointer. */
103#define ptr_proc_reloc(proc)\
104 void *proc(P1(void *))
105 ptr_proc_reloc((*reloc));
106
107} ptr_procs_t;
108typedef ptr_procs_t _ds *ptr_type_t;
109
110/* Define the pointer type for ordinary structure pointers. */
111extern ptr_procs_t ptr_struct_procs;
112#define ptr_struct_type (&ptr_struct_procs)
113
114/* Define the type for a GC root. */
115typedef struct gc_root_s gc_root_t;
116struct gc_root_s {
117 gc_root_t *next;
118 ptr_type_t ptype;
119 void **p;
120};
121
122/* Register/unregister a root. */
123void gs_struct_root_register(P3(as_ptr_t, gc_root_t *, union struct_header_s **));
124void gs_root_unregister(P2(as_ptr_t, gc_root_t *));
125
126/* ====== Structure-defining clients ====== */
127/* These are clients who define new types of structure. */
128
129/* Object contents enumerator type */
130#define mark_enum_proc(proc)\
131 ptr_type_t proc(P3(void *ptr, uint index, void ***pep))
132
133/* Object type */
134typedef struct struct_type_s {
135 usize_t size;
136 char _ds *sname;
137 mark_enum_proc((*gc_mark_proc));
138 void (*pre_gc_proc)(P1(void *));
139 void (*post_gc_proc)(P1(void *));
140 void (*finalize_proc)(P1(void *));
141} struct_type_t;
142/* Default object procedures */
143extern mark_enum_proc(no_gc_mark_proc);
144extern void no_pre_gc_proc(P1(void *)),
145 no_post_gc_proc(P1(void *)),
146 no_finalize_proc(P1(void *));