1 /* Copyright (C) 2001-2012 Artifex Software, Inc.
2    All Rights Reserved.
3 
4    This software is provided AS-IS with no warranty, either express or
5    implied.
6 
7    This software is distributed under license and may not be copied,
8    modified or distributed except as expressly authorized under the terms
9    of the license contained in the file LICENSE in this distribution.
10 
11    Refer to licensing information at http://www.artifex.com or contact
12    Artifex Software, Inc.,  7 Mt. Lassen Drive - Suite A-134, San Rafael,
13    CA  94903, U.S.A., +1(415)492-9861, for further information.
14 */
15 
16 
17 /* Implementation definitions for zlib interface */
18 /* Must be compiled with -I$(ZSRCDIR) */
19 
20 #ifndef szlibxx_INCLUDED
21 #  define szlibxx_INCLUDED
22 
23 #include "szlibx.h"
24 #include "zlib.h"
25 
26 /*
27  * We don't want to allocate zlib's private data directly from
28  * the C heap, but we must allocate it as immovable; and to avoid
29  * garbage collection issues, we must keep GC-traceable pointers
30  * to every block allocated.  Since the stream state itself is movable,
31  * we have to allocate an immovable block for the z_stream state as well.
32  */
33 typedef struct zlib_block_s zlib_block_t;
34 struct zlib_block_s {
35     void *data;
36     zlib_block_t *next;
37     zlib_block_t *prev;
38 };
39 #define private_st_zlib_block()	/* in szlibc.c */\
40   gs_private_st_ptrs3(st_zlib_block, zlib_block_t, "zlib_block_t",\
41     zlib_block_enum_ptrs, zlib_block_reloc_ptrs, next, prev, data)
42 /* The typedef is in szlibx.h */
43 /*typedef*/ struct zlib_dynamic_state_s {
44     gs_memory_t *memory;
45     zlib_block_t *blocks;
46     z_stream zstate;
47 } /*zlib_dynamic_state_t*/;
48 #define private_st_zlib_dynamic_state()	/* in szlibc.c */\
49   gs_private_st_ptrs1(st_zlib_dynamic_state, zlib_dynamic_state_t,\
50     "zlib_dynamic_state_t", zlib_dynamic_enum_ptrs, zlib_dynamic_reloc_ptrs,\
51     blocks)
52 
53 /*
54  * Provide zlib-compatible allocation and freeing functions.
55  * The mem pointer actually points to the dynamic state.
56  */
57 void *s_zlib_alloc(void *mem, uint items, uint size);
58 void s_zlib_free(void *mem, void *address);
59 
60 /* Internal procedure to allocate and free the dynamic state. */
61 int s_zlib_alloc_dynamic_state(stream_zlib_state *ss);
62 void s_zlib_free_dynamic_state(stream_zlib_state *ss);
63 
64 #endif /* szlibxx_INCLUDED */
65