xref: /plan9/sys/src/cmd/gs/src/istruct.h (revision 593dc095aefb2a85c828727bbfa9da139a49bdf4)
1 /* Copyright (C) 1994, 1997, 1998, 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: istruct.h,v 1.5 2002/06/16 04:47:10 lpd Exp $ */
18 /* Interpreter-level extension of gsstruct.h */
19 
20 #ifndef istruct_INCLUDED
21 #  define istruct_INCLUDED
22 
23 #include "gsstruct.h"
24 
25 /* ================ Refs ================ */
26 
27 /*
28  * Define the pointer type for refs.  Note that if a structure contains refs,
29  * both its clear_marks and its reloc_ptrs procedure must unmark them,
30  * since the GC will never see the refs during the unmarking sweep.
31  */
32 extern const gs_ptr_procs_t ptr_ref_procs;
33 #define ptr_ref_type (&ptr_ref_procs)
34 
35 /* The structure type descriptor for (blocks of) refs. */
36 /* This is defined in igc.c and exported for isave.c. */
37 extern_st(st_refs);
38 
39 /*
40  * Extend the GC procedure vector to include refs.
41  */
42 #define refs_proc_reloc(proc)\
43   void proc(ref_packed *from, ref_packed *to, gc_state_t *gcst)
44 typedef struct gc_procs_with_refs_s {
45     gc_procs_common;
46     /* Relocate a pointer to a ref[_packed]. */
47     ptr_proc_reloc((*reloc_ref_ptr), ref_packed);
48     /* Relocate a block of ref[_packed]s. */
49     refs_proc_reloc((*reloc_refs));
50 } gc_procs_with_refs_t;
51 
52 #undef gc_proc
53 #define gc_proc(gcst, proc) ((*(const gc_procs_with_refs_t **)(gcst))->proc)
54 
55 /*
56  * Define enumeration and relocation macros analogous to those for
57  * structures and strings.  (We should go back and change the names of
58  * those macros to be consistent which these, which are better, but it's
59  * not worth the trouble.)
60  */
61 #define ENUM_RETURN_REF(rptr)\
62   return (pep->ptr = (const void *)(rptr), ptr_ref_type)
63 #define ENUM_RETURN_REF_MEMBER(typ, memb)\
64   ENUM_RETURN_REF(&((typ *)vptr)->memb)
65 #define RELOC_REF_PTR_VAR(ptrvar)\
66   ptrvar = (*gc_proc(gcst, reloc_ref_ptr))((const void *)(ptrvar), gcst)
67 #define RELOC_REF_PTR_MEMBER(typ, memb)\
68   RELOC_REF_PTR_VAR(((typ *)vptr)->memb)
69 #define RELOC_REFS(from, upto)\
70   (*gc_proc(gcst, reloc_refs))((ref_packed *)(from), (ref_packed *)(upto), gcst)
71 #define RELOC_REF_VAR(refvar)\
72   RELOC_REFS(&(refvar), &(refvar) + 1)
73 
74 /*
75  * Define an object allocated as a struct, but actually containing refs.
76  * Such objects are useful as the client_data of library structures
77  * (currently only gstates and fonts).
78  */
79 struct_proc_clear_marks(ref_struct_clear_marks);
80 struct_proc_enum_ptrs(ref_struct_enum_ptrs);
81 struct_proc_reloc_ptrs(ref_struct_reloc_ptrs);
82 #define gs__st_ref_struct(scope_st, stname, stype, sname)\
83   gs__st_complex_only(scope_st, stname, stype, sname, ref_struct_clear_marks,\
84     ref_struct_enum_ptrs, ref_struct_reloc_ptrs, 0)
85 #define gs_public_st_ref_struct(stname, stype, sname)\
86   gs__st_ref_struct(public_st, stname, stype, sname)
87 #define gs_private_st_ref_struct(stname, stype, sname)\
88   gs__st_ref_struct(private_st, stname, stype, sname)
89 
90 #endif /* istruct_INCLUDED */
91