~ubuntu-branches/ubuntu/hardy/ghostscript/hardy

« back to all changes in this revision

Viewing changes to src/gsmalloc.c

  • Committer: Bazaar Package Importer
  • Author(s): Till Kamppeter
  • Date: 2007-11-22 12:17:43 UTC
  • mfrom: (1.1.7 upstream)
  • Revision ID: james.westby@ubuntu.com-20071122121743-cd70s3ypq0r243mp
Tags: 8.61.dfsg.1-0ubtuntu1
* New upstream release
  o Final 8.61 release
* debian/patches/09_ijs_krgb_support.dpatch: Adapted to upstream changes.
* debian/rules: Updated CUPS-related variables for "make install" calls.
* debian/rules: Remove /usr/include/ghostscript from the ghostscript
  package, they go into lings-dev.

Show diffs side-by-side

added added

removed removed

Lines of Context:
11
11
   San Rafael, CA  94903, U.S.A., +1(415)492-9861, for further information.
12
12
*/
13
13
 
14
 
/* $Id: gsmalloc.c 8022 2007-06-05 22:23:38Z giles $ */
 
14
/* $Id: gsmalloc.c 8250 2007-09-25 13:31:24Z giles $ */
15
15
/* C heap allocator */
16
16
#include "malloc_.h"
17
17
#include "gdebug.h"
34
34
 * blocks so we can free them at cleanup time.
35
35
 */
36
36
/* Raw memory procedures */
37
 
private gs_memory_proc_alloc_bytes(gs_heap_alloc_bytes);
38
 
private gs_memory_proc_resize_object(gs_heap_resize_object);
39
 
private gs_memory_proc_free_object(gs_heap_free_object);
40
 
private gs_memory_proc_stable(gs_heap_stable);
41
 
private gs_memory_proc_status(gs_heap_status);
42
 
private gs_memory_proc_free_all(gs_heap_free_all);
 
37
static gs_memory_proc_alloc_bytes(gs_heap_alloc_bytes);
 
38
static gs_memory_proc_resize_object(gs_heap_resize_object);
 
39
static gs_memory_proc_free_object(gs_heap_free_object);
 
40
static gs_memory_proc_stable(gs_heap_stable);
 
41
static gs_memory_proc_status(gs_heap_status);
 
42
static gs_memory_proc_free_all(gs_heap_free_all);
43
43
 
44
44
/* Object memory procedures */
45
 
private gs_memory_proc_alloc_struct(gs_heap_alloc_struct);
46
 
private gs_memory_proc_alloc_byte_array(gs_heap_alloc_byte_array);
47
 
private gs_memory_proc_alloc_struct_array(gs_heap_alloc_struct_array);
48
 
private gs_memory_proc_object_size(gs_heap_object_size);
49
 
private gs_memory_proc_object_type(gs_heap_object_type);
50
 
private gs_memory_proc_alloc_string(gs_heap_alloc_string);
51
 
private gs_memory_proc_resize_string(gs_heap_resize_string);
52
 
private gs_memory_proc_free_string(gs_heap_free_string);
53
 
private gs_memory_proc_register_root(gs_heap_register_root);
54
 
private gs_memory_proc_unregister_root(gs_heap_unregister_root);
55
 
private gs_memory_proc_enable_free(gs_heap_enable_free);
56
 
private const gs_memory_procs_t gs_malloc_memory_procs =
 
45
static gs_memory_proc_alloc_struct(gs_heap_alloc_struct);
 
46
static gs_memory_proc_alloc_byte_array(gs_heap_alloc_byte_array);
 
47
static gs_memory_proc_alloc_struct_array(gs_heap_alloc_struct_array);
 
48
static gs_memory_proc_object_size(gs_heap_object_size);
 
49
static gs_memory_proc_object_type(gs_heap_object_type);
 
50
static gs_memory_proc_alloc_string(gs_heap_alloc_string);
 
51
static gs_memory_proc_resize_string(gs_heap_resize_string);
 
52
static gs_memory_proc_free_string(gs_heap_free_string);
 
53
static gs_memory_proc_register_root(gs_heap_register_root);
 
54
static gs_memory_proc_unregister_root(gs_heap_unregister_root);
 
55
static gs_memory_proc_enable_free(gs_heap_enable_free);
 
56
static const gs_memory_procs_t gs_malloc_memory_procs =
57
57
{
58
58
    /* Raw memory procedures */
59
59
    gs_heap_alloc_bytes,
103
103
};
104
104
 
105
105
/* Initialize a malloc allocator. */
106
 
private long heap_available(void);
 
106
static long heap_available(void);
107
107
gs_malloc_memory_t *
108
108
gs_malloc_memory_init(void)
109
109
{
128
128
 */
129
129
#define max_malloc_probes 20
130
130
#define malloc_probe_size 64000
131
 
private long
 
131
static long
132
132
heap_available()
133
133
{
134
134
    long avail = 0;
148
148
}
149
149
 
150
150
/* Allocate various kinds of blocks. */
151
 
private byte *
 
151
static byte *
152
152
gs_heap_alloc_bytes(gs_memory_t * mem, uint size, client_name_t cname)
153
153
{
154
154
    gs_malloc_memory_t *mmem = (gs_malloc_memory_t *) mem;
206
206
    return ptr;
207
207
#undef set_msg
208
208
}
209
 
private void *
 
209
static void *
210
210
gs_heap_alloc_struct(gs_memory_t * mem, gs_memory_type_ptr_t pstype,
211
211
                     client_name_t cname)
212
212
{
218
218
    ((gs_malloc_block_t *) ptr)[-1].type = pstype;
219
219
    return ptr;
220
220
}
221
 
private byte *
 
221
static byte *
222
222
gs_heap_alloc_byte_array(gs_memory_t * mem, uint num_elements, uint elt_size,
223
223
                         client_name_t cname)
224
224
{
228
228
        return 0;
229
229
    return gs_heap_alloc_bytes(mem, (uint) lsize, cname);
230
230
}
231
 
private void *
 
231
static void *
232
232
gs_heap_alloc_struct_array(gs_memory_t * mem, uint num_elements,
233
233
                           gs_memory_type_ptr_t pstype, client_name_t cname)
234
234
{
241
241
    ((gs_malloc_block_t *) ptr)[-1].type = pstype;
242
242
    return ptr;
243
243
}
244
 
private void *
 
244
static void *
245
245
gs_heap_resize_object(gs_memory_t * mem, void *obj, uint new_num_elements,
246
246
                      client_name_t cname)
247
247
{
273
273
                      gs_alloc_fill_alloc, new_size - old_size);
274
274
    return new_ptr + 1;
275
275
}
276
 
private uint
 
276
static uint
277
277
gs_heap_object_size(gs_memory_t * mem, const void *ptr)
278
278
{
279
279
    return ((const gs_malloc_block_t *)ptr)[-1].size;
280
280
}
281
 
private gs_memory_type_ptr_t
 
281
static gs_memory_type_ptr_t
282
282
gs_heap_object_type(const gs_memory_t * mem, const void *ptr)
283
283
{
284
284
    return ((const gs_malloc_block_t *)ptr)[-1].type;
285
285
}
286
 
private void
 
286
static void
287
287
gs_heap_free_object(gs_memory_t * mem, void *ptr, client_name_t cname)
288
288
{
289
289
    gs_malloc_memory_t *mmem = (gs_malloc_memory_t *) mem;
342
342
        free((char *)((gs_malloc_block_t *) ptr - 1));
343
343
    }
344
344
}
345
 
private byte *
 
345
static byte *
346
346
gs_heap_alloc_string(gs_memory_t * mem, uint nbytes, client_name_t cname)
347
347
{
348
348
    return gs_heap_alloc_bytes(mem, nbytes, cname);
349
349
}
350
 
private byte *
 
350
static byte *
351
351
gs_heap_resize_string(gs_memory_t * mem, byte * data, uint old_num, uint new_num,
352
352
                      client_name_t cname)
353
353
{
356
356
                 client_name_string(cname), (ulong) data);
357
357
    return gs_heap_resize_object(mem, data, new_num, cname);
358
358
}
359
 
private void
 
359
static void
360
360
gs_heap_free_string(gs_memory_t * mem, byte * data, uint nbytes,
361
361
                    client_name_t cname)
362
362
{
363
363
    /****** SHOULD CHECK SIZE IF DEBUGGING ******/
364
364
    gs_heap_free_object(mem, data, cname);
365
365
}
366
 
private int
 
366
static int
367
367
gs_heap_register_root(gs_memory_t * mem, gs_gc_root_t * rp,
368
368
                      gs_ptr_type_t ptype, void **up, client_name_t cname)
369
369
{
370
370
    return 0;
371
371
}
372
 
private void
 
372
static void
373
373
gs_heap_unregister_root(gs_memory_t * mem, gs_gc_root_t * rp,
374
374
                        client_name_t cname)
375
375
{
376
376
}
377
 
private gs_memory_t *
 
377
static gs_memory_t *
378
378
gs_heap_stable(gs_memory_t *mem)
379
379
{
380
380
    return mem;                 /* heap memory is stable */
381
381
}
382
 
private void
 
382
static void
383
383
gs_heap_status(gs_memory_t * mem, gs_memory_status_t * pstat)
384
384
{
385
385
    gs_malloc_memory_t *mmem = (gs_malloc_memory_t *) mem;
387
387
    pstat->allocated = mmem->used + heap_available();
388
388
    pstat->used = mmem->used;
389
389
}
390
 
private void
 
390
static void
391
391
gs_heap_enable_free(gs_memory_t * mem, bool enable)
392
392
{
393
393
    if (enable)
399
399
}
400
400
 
401
401
/* Release all memory acquired by this allocator. */
402
 
private void
 
402
static void
403
403
gs_heap_free_all(gs_memory_t * mem, uint free_mask, client_name_t cname)
404
404
{
405
405
    gs_malloc_memory_t *const mmem = (gs_malloc_memory_t *) mem;