~ubuntu-branches/ubuntu/oneiric/ghostscript/oneiric

« back to all changes in this revision

Viewing changes to psi/zarray.c

  • Committer: Bazaar Package Importer
  • Author(s): Till Kamppeter
  • Date: 2011-07-15 16:49:55 UTC
  • mfrom: (1.1.23 upstream)
  • Revision ID: james.westby@ubuntu.com-20110715164955-uga6qibao6kez05c
Tags: 9.04~dfsg~20110715-0ubuntu1
* New upstream release
   - GIT snapshot from Jult, 12 2011.
* debian/patches/020110406~a54df2d.patch,
  debian/patches/020110408~0791cc8.patch,
  debian/patches/020110408~507cbee.patch,
  debian/patches/020110411~4509a49.patch,
  debian/patches/020110412~78bb9a6.patch,
  debian/patches/020110418~a05ab8a.patch,
  debian/patches/020110420~20b6c78.patch,
  debian/patches/020110420~4ddefa2.patch: Removed upstream patches.
* debian/rules: Generate ABI version number (variable "abi") correctly,
  cutting off repackaging and pre-release parts.
* debian/rules: Added ./lcms2/ directory to DEB_UPSTREAM_REPACKAGE_EXCLUDES.
* debian/copyright: Added lcms2/* to the list of excluded files.
* debian/symbols.common: Updated for new upstream source. Applied patch
  which dpkg-gensymbols generated for debian/libgs9.symbols to this file.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
/* Copyright (C) 2001-2006 Artifex Software, Inc.
2
2
   All Rights Reserved.
3
 
  
 
3
 
4
4
   This software is provided AS-IS with no warranty, either express or
5
5
   implied.
6
6
 
11
11
   San Rafael, CA  94903, U.S.A., +1(415)492-9861, for further information.
12
12
*/
13
13
 
14
 
/* $Id: zarray.c 9043 2008-08-28 22:48:19Z giles $ */
 
14
/* $Id$ */
15
15
/* Array operators */
16
16
#include "memory_.h"
17
17
#include "ghost.h"
33
33
 
34
34
    check_type(*op, t_integer);
35
35
    if (op->value.intval < 0)
36
 
        return_error(e_rangecheck);
 
36
        return_error(e_rangecheck);
37
37
    if (op->value.intval > max_array_size)
38
 
        return_error(e_limitcheck);
 
38
        return_error(e_limitcheck);
39
39
    size = op->value.intval;
40
40
    code = ialloc_ref_array((ref *)op, a_all, size, "array");
41
41
    if (code < 0)
42
 
        return code;
 
42
        return code;
43
43
    refset_null(op->value.refs, size);
44
44
    return 0;
45
45
}
54
54
 
55
55
    ref_assign(&aref, op);
56
56
    if (!r_is_array(&aref))
57
 
        return_op_typecheck(op);
 
57
        return_op_typecheck(op);
58
58
    check_read(aref);
59
59
    asize = r_size(&aref);
60
60
    if (asize > ostop - op) {   /* Use the slow, general algorithm. */
61
 
        int code = ref_stack_push(&o_stack, asize);
62
 
        uint i;
63
 
        const ref_packed *packed = aref.value.packed;
 
61
        int code = ref_stack_push(&o_stack, asize);
 
62
        uint i;
 
63
        const ref_packed *packed = aref.value.packed;
64
64
 
65
 
        if (code < 0)
66
 
            return code;
67
 
        for (i = asize; i > 0; i--, packed = packed_next(packed))
68
 
            packed_get(imemory, packed, ref_stack_index(&o_stack, i));
69
 
        *osp = aref;
70
 
        return 0;
 
65
        if (code < 0)
 
66
            return code;
 
67
        for (i = asize; i > 0; i--, packed = packed_next(packed))
 
68
            packed_get(imemory, packed, ref_stack_index(&o_stack, i));
 
69
        *osp = aref;
 
70
        return 0;
71
71
    }
72
72
    if (r_has_type(&aref, t_array))
73
 
        memcpy(op, aref.value.refs, asize * sizeof(ref));
 
73
        memcpy(op, aref.value.refs, asize * sizeof(ref));
74
74
    else {
75
 
        uint i;
76
 
        const ref_packed *packed = aref.value.packed;
77
 
        os_ptr pdest = op;
 
75
        uint i;
 
76
        const ref_packed *packed = aref.value.packed;
 
77
        os_ptr pdest = op;
78
78
 
79
 
        for (i = 0; i < asize; i++, pdest++, packed = packed_next(packed))
80
 
            packed_get(imemory, packed, pdest);
 
79
        for (i = 0; i < asize; i++, pdest++, packed = packed_next(packed))
 
80
            packed_get(imemory, packed, pdest);
81
81
    }
82
82
    push(asize);
83
83
    ref_assign(op, &aref);
93
93
    int code;
94
94
 
95
95
    if (!r_is_array(op))
96
 
        return_op_typecheck(op);
 
96
        return_op_typecheck(op);
97
97
    size = r_size(op);
98
98
    /* Amazingly, the following is valid: 0 array noaccess astore */
99
99
    if (size == 0)
100
100
        return 0;
101
 
    if (!r_has_type_attrs(op, t_array, a_write)) 
 
101
    if (!r_has_type_attrs(op, t_array, a_write))
102
102
        return_error(e_invalidaccess);
103
103
    if (size > op - osbot) {
104
 
        /* The store operation might involve other stack segments. */
105
 
        ref arr;
 
104
        /* The store operation might involve other stack segments. */
 
105
        ref arr;
106
106
 
107
 
        if (size >= ref_stack_count(&o_stack))
108
 
            return_error(e_stackunderflow);
109
 
        arr = *op;
110
 
        code = ref_stack_store(&o_stack, &arr, size, 1, 0, true, idmemory,
111
 
                               "astore");
112
 
        if (code < 0)
113
 
            return code;
114
 
        ref_stack_pop(&o_stack, size);
115
 
        *ref_stack_index(&o_stack, 0) = arr;
 
107
        if (size >= ref_stack_count(&o_stack))
 
108
            return_error(e_stackunderflow);
 
109
        arr = *op;
 
110
        code = ref_stack_store(&o_stack, &arr, size, 1, 0, true, idmemory,
 
111
                               "astore");
 
112
        if (code < 0)
 
113
            return code;
 
114
        ref_stack_pop(&o_stack, size);
 
115
        *ref_stack_index(&o_stack, 0) = arr;
116
116
    } else {
117
 
        code = refcpy_to_old(op, 0, op - size, size, idmemory, "astore");
118
 
        if (code < 0)
119
 
            return code;
120
 
        op[-(int)size] = *op;
121
 
        pop(size);
 
117
        code = refcpy_to_old(op, 0, op - size, size, idmemory, "astore");
 
118
        if (code < 0)
 
119
            return code;
 
120
        op[-(int)size] = *op;
 
121
        pop(size);
122
122
    }
123
123
    return 0;
124
124
}