annotate src/array.h @ 5729:f7abcda06b1b

Since stack_like_{malloc,free}() are only used when WIN32_ANY, define them only that case. See xemacs-patches message <CAHCOHQmW_HyWn=T8OJYVgp1CGPptFVHW0xPVgoaVJXpu4C0NkA@mail.gmail.com>.
author Jerry James <james@xemacs.org>
date Fri, 08 Mar 2013 13:43:06 -0700
parents 308d34e9f07d
children e2fae7783046
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
5168
cf900a2f1fa3 extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents:
diff changeset
1 /* Header for arrays (dynarrs, gap arrays, etc.).
cf900a2f1fa3 extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents:
diff changeset
2 Copyright (C) 1993, 1994, 1995 Free Software Foundation, Inc.
cf900a2f1fa3 extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents:
diff changeset
3 Copyright (C) 1996, 2001, 2002, 2004, 2005, 2009, 2010 Ben Wing.
cf900a2f1fa3 extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents:
diff changeset
4
cf900a2f1fa3 extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents:
diff changeset
5 This file is part of XEmacs.
cf900a2f1fa3 extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents:
diff changeset
6
5402
308d34e9f07d Changed bulk of GPLv2 or later files identified by script
Mats Lidell <matsl@xemacs.org>
parents: 5170
diff changeset
7 XEmacs is free software: you can redistribute it and/or modify it
5168
cf900a2f1fa3 extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents:
diff changeset
8 under the terms of the GNU General Public License as published by the
5402
308d34e9f07d Changed bulk of GPLv2 or later files identified by script
Mats Lidell <matsl@xemacs.org>
parents: 5170
diff changeset
9 Free Software Foundation, either version 3 of the License, or (at your
308d34e9f07d Changed bulk of GPLv2 or later files identified by script
Mats Lidell <matsl@xemacs.org>
parents: 5170
diff changeset
10 option) any later version.
5168
cf900a2f1fa3 extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents:
diff changeset
11
cf900a2f1fa3 extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents:
diff changeset
12 XEmacs is distributed in the hope that it will be useful, but WITHOUT
cf900a2f1fa3 extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents:
diff changeset
13 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
cf900a2f1fa3 extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents:
diff changeset
14 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
cf900a2f1fa3 extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents:
diff changeset
15 for more details.
cf900a2f1fa3 extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents:
diff changeset
16
cf900a2f1fa3 extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents:
diff changeset
17 You should have received a copy of the GNU General Public License
5402
308d34e9f07d Changed bulk of GPLv2 or later files identified by script
Mats Lidell <matsl@xemacs.org>
parents: 5170
diff changeset
18 along with XEmacs. If not, see <http://www.gnu.org/licenses/>. */
5168
cf900a2f1fa3 extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents:
diff changeset
19
cf900a2f1fa3 extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents:
diff changeset
20 /* Synched up with: Not in FSF. */
cf900a2f1fa3 extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents:
diff changeset
21
cf900a2f1fa3 extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents:
diff changeset
22 /* This file has been Mule-ized, Ben Wing, 10-13-04. */
cf900a2f1fa3 extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents:
diff changeset
23
cf900a2f1fa3 extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents:
diff changeset
24 #ifndef INCLUDED_array_h_
cf900a2f1fa3 extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents:
diff changeset
25 #define INCLUDED_array_h_
cf900a2f1fa3 extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents:
diff changeset
26
cf900a2f1fa3 extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents:
diff changeset
27 /************************************************************************/
cf900a2f1fa3 extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents:
diff changeset
28 /** Definition of dynamic arrays (dynarrs) **/
cf900a2f1fa3 extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents:
diff changeset
29 /************************************************************************/
cf900a2f1fa3 extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents:
diff changeset
30
cf900a2f1fa3 extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents:
diff changeset
31 BEGIN_C_DECLS
cf900a2f1fa3 extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents:
diff changeset
32
cf900a2f1fa3 extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents:
diff changeset
33 /************* Dynarr declaration *************/
cf900a2f1fa3 extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents:
diff changeset
34
cf900a2f1fa3 extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents:
diff changeset
35 #ifdef NEW_GC
cf900a2f1fa3 extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents:
diff changeset
36 #define DECLARE_DYNARR_LISP_IMP() \
cf900a2f1fa3 extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents:
diff changeset
37 const struct lrecord_implementation *lisp_imp;
cf900a2f1fa3 extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents:
diff changeset
38 #else
cf900a2f1fa3 extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents:
diff changeset
39 #define DECLARE_DYNARR_LISP_IMP()
cf900a2f1fa3 extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents:
diff changeset
40 #endif
cf900a2f1fa3 extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents:
diff changeset
41
cf900a2f1fa3 extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents:
diff changeset
42 #ifdef ERROR_CHECK_DYNARR
cf900a2f1fa3 extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents:
diff changeset
43 #define DECLARE_DYNARR_LOCKED() \
cf900a2f1fa3 extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents:
diff changeset
44 int locked;
cf900a2f1fa3 extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents:
diff changeset
45 #else
cf900a2f1fa3 extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents:
diff changeset
46 #define DECLARE_DYNARR_LOCKED()
cf900a2f1fa3 extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents:
diff changeset
47 #endif
cf900a2f1fa3 extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents:
diff changeset
48
cf900a2f1fa3 extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents:
diff changeset
49 #define Dynarr_declare(type) \
cf900a2f1fa3 extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents:
diff changeset
50 struct lrecord_header header; \
cf900a2f1fa3 extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents:
diff changeset
51 type *base; \
cf900a2f1fa3 extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents:
diff changeset
52 DECLARE_DYNARR_LISP_IMP () \
cf900a2f1fa3 extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents:
diff changeset
53 DECLARE_DYNARR_LOCKED () \
cf900a2f1fa3 extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents:
diff changeset
54 int elsize_; \
cf900a2f1fa3 extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents:
diff changeset
55 int len_; \
cf900a2f1fa3 extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents:
diff changeset
56 int largest_; \
cf900a2f1fa3 extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents:
diff changeset
57 int max_
cf900a2f1fa3 extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents:
diff changeset
58
cf900a2f1fa3 extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents:
diff changeset
59 typedef struct dynarr
cf900a2f1fa3 extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents:
diff changeset
60 {
cf900a2f1fa3 extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents:
diff changeset
61 Dynarr_declare (void);
cf900a2f1fa3 extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents:
diff changeset
62 } Dynarr;
cf900a2f1fa3 extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents:
diff changeset
63
cf900a2f1fa3 extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents:
diff changeset
64 #define XD_DYNARR_DESC(base_type, sub_desc) \
cf900a2f1fa3 extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents:
diff changeset
65 { XD_BLOCK_PTR, offsetof (base_type, base), \
cf900a2f1fa3 extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents:
diff changeset
66 XD_INDIRECT(1, 0), {sub_desc} }, \
cf900a2f1fa3 extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents:
diff changeset
67 { XD_INT, offsetof (base_type, len_) }, \
cf900a2f1fa3 extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents:
diff changeset
68 { XD_INT_RESET, offsetof (base_type, largest_), XD_INDIRECT(1, 0) }, \
cf900a2f1fa3 extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents:
diff changeset
69 { XD_INT_RESET, offsetof (base_type, max_), XD_INDIRECT(1, 0) }
cf900a2f1fa3 extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents:
diff changeset
70
cf900a2f1fa3 extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents:
diff changeset
71 #ifdef NEW_GC
cf900a2f1fa3 extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents:
diff changeset
72 #define XD_LISP_DYNARR_DESC(base_type, sub_desc) \
5169
6c6d78781d59 cleanup of code related to xfree(), better KKCC backtrace capabilities, document XD_INLINE_LISP_OBJECT_BLOCK_PTR, fix some memory leaks, other code cleanup
Ben Wing <ben@xemacs.org>
parents: 5168
diff changeset
73 { XD_INLINE_LISP_OBJECT_BLOCK_PTR, offsetof (base_type, base), \
5168
cf900a2f1fa3 extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents:
diff changeset
74 XD_INDIRECT(1, 0), {sub_desc} }, \
cf900a2f1fa3 extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents:
diff changeset
75 { XD_INT, offsetof (base_type, len_) }, \
cf900a2f1fa3 extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents:
diff changeset
76 { XD_INT_RESET, offsetof (base_type, largest_), XD_INDIRECT(1, 0) }, \
cf900a2f1fa3 extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents:
diff changeset
77 { XD_INT_RESET, offsetof (base_type, max_), XD_INDIRECT(1, 0) }
cf900a2f1fa3 extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents:
diff changeset
78 #endif /* NEW_GC */
cf900a2f1fa3 extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents:
diff changeset
79
cf900a2f1fa3 extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents:
diff changeset
80 /************* Dynarr verification *************/
cf900a2f1fa3 extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents:
diff changeset
81
cf900a2f1fa3 extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents:
diff changeset
82 /* Dynarr locking and verification.
cf900a2f1fa3 extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents:
diff changeset
83
cf900a2f1fa3 extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents:
diff changeset
84 [I] VERIFICATION
cf900a2f1fa3 extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents:
diff changeset
85
cf900a2f1fa3 extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents:
diff changeset
86 Verification routines simply return their basic argument, possibly
cf900a2f1fa3 extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents:
diff changeset
87 casted, but in the process perform some verification on it, aborting if
cf900a2f1fa3 extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents:
diff changeset
88 the verification fails. The verification routines take FILE and LINE
cf900a2f1fa3 extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents:
diff changeset
89 parameters, and use them to output the file and line of the caller
cf900a2f1fa3 extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents:
diff changeset
90 when an abort occurs, rather than the file and line of the inline
cf900a2f1fa3 extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents:
diff changeset
91 function, which is less than useful.
cf900a2f1fa3 extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents:
diff changeset
92
cf900a2f1fa3 extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents:
diff changeset
93 There are three basic types of verification routines:
cf900a2f1fa3 extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents:
diff changeset
94
cf900a2f1fa3 extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents:
diff changeset
95 (1) Verify the dynarr itself. This verifies the basic invariant
cf900a2f1fa3 extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents:
diff changeset
96 involving the length/size values:
cf900a2f1fa3 extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents:
diff changeset
97
cf900a2f1fa3 extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents:
diff changeset
98 0 <= Dynarr_length(d) <= Dynarr_largest(d) <= Dynarr_max(d)
cf900a2f1fa3 extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents:
diff changeset
99
cf900a2f1fa3 extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents:
diff changeset
100 (2) Verify the dynarr itself prior to modifying it. This performs
cf900a2f1fa3 extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents:
diff changeset
101 the same verification as previously, but also checks that the
cf900a2f1fa3 extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents:
diff changeset
102 dynarr is not locked (see below).
cf900a2f1fa3 extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents:
diff changeset
103
cf900a2f1fa3 extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents:
diff changeset
104 (3) Verify a dynarr position. Unfortunately we have to have
cf900a2f1fa3 extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents:
diff changeset
105 different verification routines depending on which kind of operation
cf900a2f1fa3 extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents:
diff changeset
106 is being performed:
cf900a2f1fa3 extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents:
diff changeset
107
cf900a2f1fa3 extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents:
diff changeset
108 (a) For Dynarr_at(), we check that the POS is bounded by Dynarr_largest(),
cf900a2f1fa3 extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents:
diff changeset
109 i.e. 0 <= POS < Dynarr_largest().
cf900a2f1fa3 extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents:
diff changeset
110 (b) For Dynarr_atp_allow_end(), we also have to allow
cf900a2f1fa3 extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents:
diff changeset
111 POS == Dynarr_largest().
cf900a2f1fa3 extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents:
diff changeset
112 (c) For Dynarr_atp(), we behave largely like Dynarr_at() but make a
cf900a2f1fa3 extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents:
diff changeset
113 special exception when POS == 0 and Dynarr_largest() == 0 -- see
cf900a2f1fa3 extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents:
diff changeset
114 comment below.
cf900a2f1fa3 extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents:
diff changeset
115 (d) Some other routines contain the POS verification within their code,
cf900a2f1fa3 extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents:
diff changeset
116 and make the check 0 <= POS < Dynarr_length() or
cf900a2f1fa3 extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents:
diff changeset
117 0 <= POS <= Dynarr_length().
cf900a2f1fa3 extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents:
diff changeset
118
cf900a2f1fa3 extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents:
diff changeset
119 #### It is not well worked-out whether and in what circumstances it's
cf900a2f1fa3 extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents:
diff changeset
120 allowed to use a position that is between Dynarr_length() and
cf900a2f1fa3 extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents:
diff changeset
121 Dynarr_largest(). The ideal solution is to never allow this, and require
cf900a2f1fa3 extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents:
diff changeset
122 instead that code first change the length before accessing higher
cf900a2f1fa3 extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents:
diff changeset
123 positions. That would require looking through all the code that accesses
cf900a2f1fa3 extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents:
diff changeset
124 dynarrs and fixing it appropriately (especially redisplay code, and
cf900a2f1fa3 extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents:
diff changeset
125 especially redisplay code in the vicinity of a reference to
cf900a2f1fa3 extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents:
diff changeset
126 Dynarr_largest(), since such code usually checks explicitly to see whether
cf900a2f1fa3 extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents:
diff changeset
127 there is extra stuff between Dynarr_length() and Dynarr_largest().)
cf900a2f1fa3 extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents:
diff changeset
128
cf900a2f1fa3 extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents:
diff changeset
129 [II] LOCKING
cf900a2f1fa3 extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents:
diff changeset
130
cf900a2f1fa3 extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents:
diff changeset
131 The idea behind dynarr locking is simple: Locking a dynarr prevents
cf900a2f1fa3 extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents:
diff changeset
132 any modification from occurring, or rather, leads to an abort upon
cf900a2f1fa3 extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents:
diff changeset
133 any attempt to modify a dynarr.
cf900a2f1fa3 extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents:
diff changeset
134
cf900a2f1fa3 extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents:
diff changeset
135 Dynarr locking was originally added to catch some sporadic and hard-to-
cf900a2f1fa3 extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents:
diff changeset
136 debug crashes in the redisplay code where dynarrs appeared to be getting
cf900a2f1fa3 extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents:
diff changeset
137 corrupted in an unexpected fashion. The solution was to lock the
cf900a2f1fa3 extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents:
diff changeset
138 dynarrs that were getting corrupted (in this case, the display-line
cf900a2f1fa3 extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents:
diff changeset
139 dynarrs) around calls to routines that weren't supposed to be changing
cf900a2f1fa3 extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents:
diff changeset
140 these dynarrs but might somehow be calling code that modified them.
cf900a2f1fa3 extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents:
diff changeset
141 This eventually revealed that there was a reentrancy problem with
cf900a2f1fa3 extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents:
diff changeset
142 redisplay that involved the QUIT mechanism and the processing done in
cf900a2f1fa3 extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents:
diff changeset
143 order to determine whether C-g had been pressed -- this processing
cf900a2f1fa3 extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents:
diff changeset
144 involves retrieving, processing and queueing pending events to see
cf900a2f1fa3 extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents:
diff changeset
145 whether any of them result in a C-g keypress. However, at least under
cf900a2f1fa3 extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents:
diff changeset
146 MS Windows this can result in redisplay being called reentrantly.
cf900a2f1fa3 extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents:
diff changeset
147 For more info:--
cf900a2f1fa3 extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents:
diff changeset
148
cf900a2f1fa3 extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents:
diff changeset
149 (Info-goto-node "(internals)Critical Redisplay Sections")
cf900a2f1fa3 extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents:
diff changeset
150
cf900a2f1fa3 extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents:
diff changeset
151 */
cf900a2f1fa3 extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents:
diff changeset
152
cf900a2f1fa3 extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents:
diff changeset
153 #ifdef ERROR_CHECK_DYNARR
cf900a2f1fa3 extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents:
diff changeset
154 DECLARE_INLINE_HEADER (
cf900a2f1fa3 extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents:
diff changeset
155 int
cf900a2f1fa3 extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents:
diff changeset
156 Dynarr_verify_pos_at (void *d, Elemcount pos, const Ascbyte *file, int line)
cf900a2f1fa3 extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents:
diff changeset
157 )
cf900a2f1fa3 extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents:
diff changeset
158 {
cf900a2f1fa3 extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents:
diff changeset
159 Dynarr *dy = (Dynarr *) d;
cf900a2f1fa3 extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents:
diff changeset
160 /* We use `largest', not `len', because the redisplay code often
cf900a2f1fa3 extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents:
diff changeset
161 accesses stuff between len and largest. */
cf900a2f1fa3 extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents:
diff changeset
162 assert_at_line (pos >= 0 && pos < dy->largest_, file, line);
cf900a2f1fa3 extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents:
diff changeset
163 return pos;
cf900a2f1fa3 extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents:
diff changeset
164 }
cf900a2f1fa3 extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents:
diff changeset
165
cf900a2f1fa3 extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents:
diff changeset
166 DECLARE_INLINE_HEADER (
cf900a2f1fa3 extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents:
diff changeset
167 int
cf900a2f1fa3 extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents:
diff changeset
168 Dynarr_verify_pos_atp (void *d, Elemcount pos, const Ascbyte *file, int line)
cf900a2f1fa3 extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents:
diff changeset
169 )
cf900a2f1fa3 extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents:
diff changeset
170 {
cf900a2f1fa3 extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents:
diff changeset
171 Dynarr *dy = (Dynarr *) d;
cf900a2f1fa3 extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents:
diff changeset
172 /* We use `largest', not `len', because the redisplay code often
cf900a2f1fa3 extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents:
diff changeset
173 accesses stuff between len and largest. */
cf900a2f1fa3 extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents:
diff changeset
174 /* [[ Code will often do something like ...
cf900a2f1fa3 extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents:
diff changeset
175
cf900a2f1fa3 extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents:
diff changeset
176 val = make_bit_vector_from_byte_vector (Dynarr_atp (dyn, 0),
cf900a2f1fa3 extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents:
diff changeset
177 Dynarr_length (dyn));
cf900a2f1fa3 extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents:
diff changeset
178
cf900a2f1fa3 extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents:
diff changeset
179 which works fine when the Dynarr_length is non-zero, but when zero,
cf900a2f1fa3 extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents:
diff changeset
180 the result of Dynarr_atp() not only points past the end of the
cf900a2f1fa3 extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents:
diff changeset
181 allocated array, but the array may not have ever been allocated and
cf900a2f1fa3 extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents:
diff changeset
182 hence the return value is NULL. But the length of 0 causes the
cf900a2f1fa3 extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents:
diff changeset
183 pointer to never get checked. These can occur throughout the code
cf900a2f1fa3 extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents:
diff changeset
184 so we put in a special check. --ben ]]
cf900a2f1fa3 extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents:
diff changeset
185
cf900a2f1fa3 extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents:
diff changeset
186 Update: The common idiom `Dynarr_atp (dyn, 0)' has been changed to
cf900a2f1fa3 extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents:
diff changeset
187 `Dynarr_begin (dyn)'. Possibly this special check at POS 0 can be
cf900a2f1fa3 extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents:
diff changeset
188 done only for Dynarr_begin() not for general Dynarr_atp(). --ben */
cf900a2f1fa3 extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents:
diff changeset
189 if (pos == 0 && dy->len_ == 0)
cf900a2f1fa3 extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents:
diff changeset
190 return pos;
cf900a2f1fa3 extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents:
diff changeset
191 /* #### It's vaguely possible that some code could legitimately want to
cf900a2f1fa3 extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents:
diff changeset
192 retrieve a pointer to the position just past the end of dynarr memory.
cf900a2f1fa3 extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents:
diff changeset
193 This could happen with Dynarr_atp() but not Dynarr_at(). If so, it
cf900a2f1fa3 extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents:
diff changeset
194 will trigger this assert(). In such cases, it should be obvious that
cf900a2f1fa3 extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents:
diff changeset
195 the code wants to do this; rather than relaxing the assert, we should
cf900a2f1fa3 extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents:
diff changeset
196 probably create a new macro Dynarr_atp_allow_end() which is like
cf900a2f1fa3 extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents:
diff changeset
197 Dynarr_atp() but which allows for pointing at invalid addresses -- we
cf900a2f1fa3 extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents:
diff changeset
198 really want to check for cases of accessing just past the end of
cf900a2f1fa3 extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents:
diff changeset
199 memory, which is a likely off-by-one problem to occur and will usually
cf900a2f1fa3 extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents:
diff changeset
200 not trigger a protection fault (instead, you'll just get random
cf900a2f1fa3 extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents:
diff changeset
201 behavior, possibly overwriting other memory, which is bad). --ben */
cf900a2f1fa3 extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents:
diff changeset
202 assert_at_line (pos >= 0 && pos < dy->largest_, file, line);
cf900a2f1fa3 extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents:
diff changeset
203 return pos;
cf900a2f1fa3 extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents:
diff changeset
204 }
cf900a2f1fa3 extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents:
diff changeset
205
cf900a2f1fa3 extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents:
diff changeset
206 DECLARE_INLINE_HEADER (
cf900a2f1fa3 extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents:
diff changeset
207 int
cf900a2f1fa3 extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents:
diff changeset
208 Dynarr_verify_pos_atp_allow_end (void *d, Elemcount pos, const Ascbyte *file,
cf900a2f1fa3 extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents:
diff changeset
209 int line)
cf900a2f1fa3 extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents:
diff changeset
210 )
cf900a2f1fa3 extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents:
diff changeset
211 {
cf900a2f1fa3 extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents:
diff changeset
212 Dynarr *dy = (Dynarr *) d;
cf900a2f1fa3 extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents:
diff changeset
213 /* We use `largest', not `len', because the redisplay code often
cf900a2f1fa3 extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents:
diff changeset
214 accesses stuff between len and largest.
cf900a2f1fa3 extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents:
diff changeset
215 We also allow referencing the very end, past the end of allocated
cf900a2f1fa3 extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents:
diff changeset
216 legitimately space. See comments in Dynarr_verify_pos_atp.()*/
cf900a2f1fa3 extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents:
diff changeset
217 assert_at_line (pos >= 0 && pos <= dy->largest_, file, line);
cf900a2f1fa3 extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents:
diff changeset
218 return pos;
cf900a2f1fa3 extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents:
diff changeset
219 }
cf900a2f1fa3 extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents:
diff changeset
220
cf900a2f1fa3 extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents:
diff changeset
221 #else
cf900a2f1fa3 extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents:
diff changeset
222 #define Dynarr_verify_pos_at(d, pos, file, line) (pos)
cf900a2f1fa3 extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents:
diff changeset
223 #define Dynarr_verify_pos_atp(d, pos, file, line) (pos)
cf900a2f1fa3 extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents:
diff changeset
224 #define Dynarr_verify_pos_atp_allow_end(d, pos, file, line) (pos)
cf900a2f1fa3 extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents:
diff changeset
225 #endif /* ERROR_CHECK_DYNARR */
cf900a2f1fa3 extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents:
diff changeset
226
cf900a2f1fa3 extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents:
diff changeset
227 #ifdef ERROR_CHECK_DYNARR
cf900a2f1fa3 extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents:
diff changeset
228 DECLARE_INLINE_HEADER (
cf900a2f1fa3 extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents:
diff changeset
229 Dynarr *
cf900a2f1fa3 extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents:
diff changeset
230 Dynarr_verify_1 (void *d, const Ascbyte *file, int line)
cf900a2f1fa3 extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents:
diff changeset
231 )
cf900a2f1fa3 extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents:
diff changeset
232 {
cf900a2f1fa3 extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents:
diff changeset
233 Dynarr *dy = (Dynarr *) d;
cf900a2f1fa3 extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents:
diff changeset
234 assert_at_line (dy->len_ >= 0 && dy->len_ <= dy->largest_ &&
cf900a2f1fa3 extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents:
diff changeset
235 dy->largest_ <= dy->max_, file, line);
cf900a2f1fa3 extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents:
diff changeset
236 return dy;
cf900a2f1fa3 extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents:
diff changeset
237 }
cf900a2f1fa3 extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents:
diff changeset
238
cf900a2f1fa3 extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents:
diff changeset
239 DECLARE_INLINE_HEADER (
cf900a2f1fa3 extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents:
diff changeset
240 Dynarr *
cf900a2f1fa3 extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents:
diff changeset
241 Dynarr_verify_mod_1 (void *d, const Ascbyte *file, int line)
cf900a2f1fa3 extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents:
diff changeset
242 )
cf900a2f1fa3 extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents:
diff changeset
243 {
cf900a2f1fa3 extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents:
diff changeset
244 Dynarr *dy = (Dynarr *) d;
cf900a2f1fa3 extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents:
diff changeset
245 assert_at_line (!dy->locked, file, line);
cf900a2f1fa3 extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents:
diff changeset
246 return Dynarr_verify_1 (d, file, line);
cf900a2f1fa3 extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents:
diff changeset
247 }
cf900a2f1fa3 extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents:
diff changeset
248
cf900a2f1fa3 extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents:
diff changeset
249 #define Dynarr_verify(d) Dynarr_verify_1 (d, __FILE__, __LINE__)
cf900a2f1fa3 extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents:
diff changeset
250 #define Dynarr_verify_mod(d) Dynarr_verify_mod_1 (d, __FILE__, __LINE__)
cf900a2f1fa3 extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents:
diff changeset
251
cf900a2f1fa3 extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents:
diff changeset
252 DECLARE_INLINE_HEADER (
cf900a2f1fa3 extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents:
diff changeset
253 void
cf900a2f1fa3 extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents:
diff changeset
254 Dynarr_lock (void *d)
cf900a2f1fa3 extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents:
diff changeset
255 )
cf900a2f1fa3 extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents:
diff changeset
256 {
cf900a2f1fa3 extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents:
diff changeset
257 Dynarr *dy = Dynarr_verify_mod (d);
cf900a2f1fa3 extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents:
diff changeset
258 dy->locked = 1;
cf900a2f1fa3 extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents:
diff changeset
259 }
cf900a2f1fa3 extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents:
diff changeset
260
cf900a2f1fa3 extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents:
diff changeset
261 DECLARE_INLINE_HEADER (
cf900a2f1fa3 extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents:
diff changeset
262 void
cf900a2f1fa3 extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents:
diff changeset
263 Dynarr_unlock (void *d)
cf900a2f1fa3 extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents:
diff changeset
264 )
cf900a2f1fa3 extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents:
diff changeset
265 {
cf900a2f1fa3 extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents:
diff changeset
266 Dynarr *dy = Dynarr_verify (d);
cf900a2f1fa3 extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents:
diff changeset
267 assert (dy->locked);
cf900a2f1fa3 extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents:
diff changeset
268 dy->locked = 0;
cf900a2f1fa3 extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents:
diff changeset
269 }
cf900a2f1fa3 extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents:
diff changeset
270
cf900a2f1fa3 extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents:
diff changeset
271 #else /* not ERROR_CHECK_DYNARR */
cf900a2f1fa3 extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents:
diff changeset
272
cf900a2f1fa3 extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents:
diff changeset
273 #define Dynarr_verify(d) ((Dynarr *) d)
cf900a2f1fa3 extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents:
diff changeset
274 #define Dynarr_verify_mod(d) ((Dynarr *) d)
cf900a2f1fa3 extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents:
diff changeset
275 #define Dynarr_lock(d) DO_NOTHING
cf900a2f1fa3 extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents:
diff changeset
276 #define Dynarr_unlock(d) DO_NOTHING
cf900a2f1fa3 extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents:
diff changeset
277
cf900a2f1fa3 extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents:
diff changeset
278 #endif /* ERROR_CHECK_DYNARR */
cf900a2f1fa3 extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents:
diff changeset
279
cf900a2f1fa3 extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents:
diff changeset
280 /************* Dynarr creation *************/
cf900a2f1fa3 extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents:
diff changeset
281
cf900a2f1fa3 extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents:
diff changeset
282 MODULE_API void *Dynarr_newf (Bytecount elsize);
cf900a2f1fa3 extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents:
diff changeset
283 MODULE_API void Dynarr_free (void *d);
cf900a2f1fa3 extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents:
diff changeset
284
cf900a2f1fa3 extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents:
diff changeset
285 #ifdef NEW_GC
cf900a2f1fa3 extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents:
diff changeset
286 MODULE_API void *Dynarr_lisp_newf (Bytecount elsize,
cf900a2f1fa3 extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents:
diff changeset
287 const struct lrecord_implementation
cf900a2f1fa3 extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents:
diff changeset
288 *dynarr_imp,
cf900a2f1fa3 extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents:
diff changeset
289 const struct lrecord_implementation *imp);
cf900a2f1fa3 extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents:
diff changeset
290
cf900a2f1fa3 extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents:
diff changeset
291 #define Dynarr_lisp_new(type, dynarr_imp, imp) \
cf900a2f1fa3 extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents:
diff changeset
292 ((type##_dynarr *) Dynarr_lisp_newf (sizeof (type), dynarr_imp, imp))
cf900a2f1fa3 extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents:
diff changeset
293 #define Dynarr_lisp_new2(dynarr_type, type, dynarr_imp, imp) \
cf900a2f1fa3 extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents:
diff changeset
294 ((dynarr_type *) Dynarr_lisp_newf (sizeof (type)), dynarr_imp, imp)
cf900a2f1fa3 extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents:
diff changeset
295 #endif /* NEW_GC */
cf900a2f1fa3 extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents:
diff changeset
296 #define Dynarr_new(type) ((type##_dynarr *) Dynarr_newf (sizeof (type)))
cf900a2f1fa3 extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents:
diff changeset
297 #define Dynarr_new2(dynarr_type, type) \
cf900a2f1fa3 extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents:
diff changeset
298 ((dynarr_type *) Dynarr_newf (sizeof (type)))
cf900a2f1fa3 extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents:
diff changeset
299
cf900a2f1fa3 extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents:
diff changeset
300 /************* Dynarr access *************/
cf900a2f1fa3 extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents:
diff changeset
301
cf900a2f1fa3 extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents:
diff changeset
302 #ifdef ERROR_CHECK_DYNARR
cf900a2f1fa3 extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents:
diff changeset
303 #define Dynarr_at(d, pos) \
cf900a2f1fa3 extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents:
diff changeset
304 ((d)->base[Dynarr_verify_pos_at (d, pos, __FILE__, __LINE__)])
cf900a2f1fa3 extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents:
diff changeset
305 #define Dynarr_atp_allow_end(d, pos) \
cf900a2f1fa3 extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents:
diff changeset
306 (&((d)->base[Dynarr_verify_pos_atp_allow_end (d, pos, __FILE__, __LINE__)]))
cf900a2f1fa3 extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents:
diff changeset
307 #define Dynarr_atp(d, pos) \
cf900a2f1fa3 extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents:
diff changeset
308 (&((d)->base[Dynarr_verify_pos_atp (d, pos, __FILE__, __LINE__)]))
cf900a2f1fa3 extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents:
diff changeset
309 #else
cf900a2f1fa3 extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents:
diff changeset
310 #define Dynarr_at(d, pos) ((d)->base[pos])
cf900a2f1fa3 extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents:
diff changeset
311 #define Dynarr_atp(d, pos) (&Dynarr_at (d, pos))
cf900a2f1fa3 extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents:
diff changeset
312 #define Dynarr_atp_allow_end(d, pos) Dynarr_atp (d, pos)
cf900a2f1fa3 extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents:
diff changeset
313 #endif
cf900a2f1fa3 extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents:
diff changeset
314
cf900a2f1fa3 extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents:
diff changeset
315 /* Old #define Dynarr_atp(d, pos) (&Dynarr_at (d, pos)) */
cf900a2f1fa3 extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents:
diff changeset
316 #define Dynarr_begin(d) Dynarr_atp (d, 0)
cf900a2f1fa3 extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents:
diff changeset
317 #define Dynarr_lastp(d) Dynarr_atp (d, Dynarr_length (d) - 1)
cf900a2f1fa3 extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents:
diff changeset
318 #define Dynarr_past_lastp(d) Dynarr_atp_allow_end (d, Dynarr_length (d))
cf900a2f1fa3 extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents:
diff changeset
319
cf900a2f1fa3 extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents:
diff changeset
320
cf900a2f1fa3 extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents:
diff changeset
321 /************* Dynarr length/size retrieval and setting *************/
cf900a2f1fa3 extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents:
diff changeset
322
cf900a2f1fa3 extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents:
diff changeset
323 /* Retrieve the length of a dynarr. The `+ 0' is to ensure that this cannot
cf900a2f1fa3 extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents:
diff changeset
324 be used as an lvalue. */
cf900a2f1fa3 extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents:
diff changeset
325 #define Dynarr_length(d) (Dynarr_verify (d)->len_ + 0)
cf900a2f1fa3 extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents:
diff changeset
326 /* Retrieve the largest ever length seen of a dynarr. The `+ 0' is to
cf900a2f1fa3 extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents:
diff changeset
327 ensure that this cannot be used as an lvalue. */
cf900a2f1fa3 extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents:
diff changeset
328 #define Dynarr_largest(d) (Dynarr_verify (d)->largest_ + 0)
cf900a2f1fa3 extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents:
diff changeset
329 /* Retrieve the number of elements that fit in the currently allocated
cf900a2f1fa3 extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents:
diff changeset
330 space. The `+ 0' is to ensure that this cannot be used as an lvalue. */
cf900a2f1fa3 extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents:
diff changeset
331 #define Dynarr_max(d) (Dynarr_verify (d)->max_ + 0)
cf900a2f1fa3 extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents:
diff changeset
332 /* Return the size in bytes of an element in a dynarr. */
cf900a2f1fa3 extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents:
diff changeset
333 #define Dynarr_elsize(d) (Dynarr_verify (d)->elsize_ + 0)
cf900a2f1fa3 extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents:
diff changeset
334 /* Retrieve the advertised memory usage of a dynarr, i.e. the number of
cf900a2f1fa3 extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents:
diff changeset
335 bytes occupied by the elements in the dynarr, not counting any overhead. */
cf900a2f1fa3 extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents:
diff changeset
336 #define Dynarr_sizeof(d) (Dynarr_length (d) * Dynarr_elsize (d))
cf900a2f1fa3 extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents:
diff changeset
337
cf900a2f1fa3 extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents:
diff changeset
338 /* Actually set the length of a dynarr. This is a low-level routine that
cf900a2f1fa3 extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents:
diff changeset
339 should not be directly used; use Dynarr_set_length() or
cf900a2f1fa3 extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents:
diff changeset
340 Dynarr_set_lengthr() instead. */
cf900a2f1fa3 extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents:
diff changeset
341 DECLARE_INLINE_HEADER (
cf900a2f1fa3 extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents:
diff changeset
342 void
cf900a2f1fa3 extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents:
diff changeset
343 Dynarr_set_length_1 (void *d, Elemcount len)
cf900a2f1fa3 extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents:
diff changeset
344 )
cf900a2f1fa3 extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents:
diff changeset
345 {
cf900a2f1fa3 extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents:
diff changeset
346 Dynarr *dy = Dynarr_verify_mod (d);
cf900a2f1fa3 extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents:
diff changeset
347 dynarr_checking_assert (len >= 0 && len <= Dynarr_max (dy));
cf900a2f1fa3 extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents:
diff changeset
348 /* Use the raw field references here otherwise we get a crash because
cf900a2f1fa3 extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents:
diff changeset
349 we've set the length but not yet fixed up the largest value. */
cf900a2f1fa3 extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents:
diff changeset
350 dy->len_ = len;
cf900a2f1fa3 extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents:
diff changeset
351 if (dy->len_ > dy->largest_)
cf900a2f1fa3 extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents:
diff changeset
352 dy->largest_ = dy->len_;
cf900a2f1fa3 extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents:
diff changeset
353 (void) Dynarr_verify_mod (d);
cf900a2f1fa3 extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents:
diff changeset
354 }
cf900a2f1fa3 extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents:
diff changeset
355
cf900a2f1fa3 extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents:
diff changeset
356 /* "Restricted set-length": Set the length of dynarr D to LEN,
cf900a2f1fa3 extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents:
diff changeset
357 which must be in the range [0, Dynarr_largest(d)]. */
cf900a2f1fa3 extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents:
diff changeset
358
cf900a2f1fa3 extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents:
diff changeset
359 DECLARE_INLINE_HEADER (
cf900a2f1fa3 extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents:
diff changeset
360 void
cf900a2f1fa3 extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents:
diff changeset
361 Dynarr_set_lengthr (void *d, Elemcount len)
cf900a2f1fa3 extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents:
diff changeset
362 )
cf900a2f1fa3 extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents:
diff changeset
363 {
cf900a2f1fa3 extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents:
diff changeset
364 Dynarr *dy = Dynarr_verify_mod (d);
cf900a2f1fa3 extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents:
diff changeset
365 dynarr_checking_assert (len >= 0 && len <= Dynarr_largest (dy));
cf900a2f1fa3 extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents:
diff changeset
366 Dynarr_set_length_1 (dy, len);
cf900a2f1fa3 extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents:
diff changeset
367 }
cf900a2f1fa3 extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents:
diff changeset
368
cf900a2f1fa3 extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents:
diff changeset
369 /* "Restricted increment": Increment the length of dynarr D by 1; the resulting
cf900a2f1fa3 extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents:
diff changeset
370 length must be in the range [0, Dynarr_largest(d)]. */
cf900a2f1fa3 extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents:
diff changeset
371
cf900a2f1fa3 extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents:
diff changeset
372 #define Dynarr_incrementr(d) Dynarr_set_lengthr (d, Dynarr_length (d) + 1)
cf900a2f1fa3 extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents:
diff changeset
373
cf900a2f1fa3 extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents:
diff changeset
374
cf900a2f1fa3 extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents:
diff changeset
375 MODULE_API void Dynarr_resize (void *d, Elemcount size);
cf900a2f1fa3 extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents:
diff changeset
376
cf900a2f1fa3 extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents:
diff changeset
377 DECLARE_INLINE_HEADER (
cf900a2f1fa3 extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents:
diff changeset
378 void
cf900a2f1fa3 extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents:
diff changeset
379 Dynarr_resize_to_fit (void *d, Elemcount size)
cf900a2f1fa3 extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents:
diff changeset
380 )
cf900a2f1fa3 extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents:
diff changeset
381 {
cf900a2f1fa3 extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents:
diff changeset
382 Dynarr *dy = Dynarr_verify_mod (d);
cf900a2f1fa3 extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents:
diff changeset
383 if (size > Dynarr_max (dy))
cf900a2f1fa3 extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents:
diff changeset
384 Dynarr_resize (dy, size);
cf900a2f1fa3 extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents:
diff changeset
385 }
cf900a2f1fa3 extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents:
diff changeset
386
cf900a2f1fa3 extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents:
diff changeset
387 #define Dynarr_resize_to_add(d, numels) \
cf900a2f1fa3 extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents:
diff changeset
388 Dynarr_resize_to_fit (d, Dynarr_length (d) + numels)
cf900a2f1fa3 extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents:
diff changeset
389
cf900a2f1fa3 extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents:
diff changeset
390 /* This is an optimization. This is like Dynarr_set_length() but the length
cf900a2f1fa3 extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents:
diff changeset
391 is guaranteed to be at least as big as the existing length. */
cf900a2f1fa3 extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents:
diff changeset
392
cf900a2f1fa3 extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents:
diff changeset
393 DECLARE_INLINE_HEADER (
cf900a2f1fa3 extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents:
diff changeset
394 void
cf900a2f1fa3 extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents:
diff changeset
395 Dynarr_increase_length (void *d, Elemcount len)
cf900a2f1fa3 extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents:
diff changeset
396 )
cf900a2f1fa3 extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents:
diff changeset
397 {
cf900a2f1fa3 extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents:
diff changeset
398 Dynarr *dy = Dynarr_verify_mod (d);
cf900a2f1fa3 extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents:
diff changeset
399 dynarr_checking_assert (len >= Dynarr_length (dy));
cf900a2f1fa3 extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents:
diff changeset
400 Dynarr_resize_to_fit (dy, len);
cf900a2f1fa3 extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents:
diff changeset
401 Dynarr_set_length_1 (dy, len);
cf900a2f1fa3 extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents:
diff changeset
402 }
cf900a2f1fa3 extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents:
diff changeset
403
cf900a2f1fa3 extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents:
diff changeset
404 /* Set the length of dynarr D to LEN. If the length increases, resize as
cf900a2f1fa3 extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents:
diff changeset
405 necessary to fit. (NOTE: This will leave uninitialized memory. If you
cf900a2f1fa3 extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents:
diff changeset
406 aren't planning on immediately overwriting the memory, use
cf900a2f1fa3 extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents:
diff changeset
407 Dynarr_set_length_and_zero() to zero out all the memory that would
cf900a2f1fa3 extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents:
diff changeset
408 otherwise be uninitialized.) */
cf900a2f1fa3 extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents:
diff changeset
409
cf900a2f1fa3 extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents:
diff changeset
410 DECLARE_INLINE_HEADER (
cf900a2f1fa3 extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents:
diff changeset
411 void
cf900a2f1fa3 extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents:
diff changeset
412 Dynarr_set_length (void *d, Elemcount len)
cf900a2f1fa3 extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents:
diff changeset
413 )
cf900a2f1fa3 extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents:
diff changeset
414 {
cf900a2f1fa3 extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents:
diff changeset
415 Dynarr *dy = Dynarr_verify_mod (d);
cf900a2f1fa3 extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents:
diff changeset
416 Elemcount old_len = Dynarr_length (dy);
cf900a2f1fa3 extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents:
diff changeset
417 if (old_len >= len)
cf900a2f1fa3 extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents:
diff changeset
418 Dynarr_set_lengthr (dy, len);
cf900a2f1fa3 extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents:
diff changeset
419 else
cf900a2f1fa3 extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents:
diff changeset
420 Dynarr_increase_length (d, len);
cf900a2f1fa3 extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents:
diff changeset
421 }
cf900a2f1fa3 extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents:
diff changeset
422
cf900a2f1fa3 extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents:
diff changeset
423 #define Dynarr_increment(d) Dynarr_increase_length (d, Dynarr_length (d) + 1)
cf900a2f1fa3 extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents:
diff changeset
424
cf900a2f1fa3 extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents:
diff changeset
425 /* Zero LEN contiguous elements starting at POS. */
cf900a2f1fa3 extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents:
diff changeset
426
cf900a2f1fa3 extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents:
diff changeset
427 DECLARE_INLINE_HEADER (
cf900a2f1fa3 extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents:
diff changeset
428 void
cf900a2f1fa3 extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents:
diff changeset
429 Dynarr_zero_many (void *d, Elemcount pos, Elemcount len)
cf900a2f1fa3 extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents:
diff changeset
430 )
cf900a2f1fa3 extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents:
diff changeset
431 {
cf900a2f1fa3 extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents:
diff changeset
432 Dynarr *dy = Dynarr_verify_mod (d);
cf900a2f1fa3 extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents:
diff changeset
433 memset ((Rawbyte *) dy->base + pos*Dynarr_elsize (dy), 0,
cf900a2f1fa3 extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents:
diff changeset
434 len*Dynarr_elsize (dy));
cf900a2f1fa3 extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents:
diff changeset
435 }
cf900a2f1fa3 extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents:
diff changeset
436
cf900a2f1fa3 extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents:
diff changeset
437 /* This is an optimization. This is like Dynarr_set_length_and_zero() but
cf900a2f1fa3 extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents:
diff changeset
438 the length is guaranteed to be at least as big as the existing
cf900a2f1fa3 extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents:
diff changeset
439 length. */
cf900a2f1fa3 extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents:
diff changeset
440
cf900a2f1fa3 extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents:
diff changeset
441 DECLARE_INLINE_HEADER (
cf900a2f1fa3 extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents:
diff changeset
442 void
cf900a2f1fa3 extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents:
diff changeset
443 Dynarr_increase_length_and_zero (void *d, Elemcount len)
cf900a2f1fa3 extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents:
diff changeset
444 )
cf900a2f1fa3 extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents:
diff changeset
445 {
cf900a2f1fa3 extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents:
diff changeset
446 Dynarr *dy = Dynarr_verify_mod (d);
cf900a2f1fa3 extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents:
diff changeset
447 Elemcount old_len = Dynarr_length (dy);
cf900a2f1fa3 extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents:
diff changeset
448 Dynarr_increase_length (dy, len);
cf900a2f1fa3 extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents:
diff changeset
449 Dynarr_zero_many (dy, old_len, len - old_len);
cf900a2f1fa3 extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents:
diff changeset
450 }
cf900a2f1fa3 extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents:
diff changeset
451
cf900a2f1fa3 extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents:
diff changeset
452 /* Set the length of dynarr D to LEN. If the length increases, resize as
cf900a2f1fa3 extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents:
diff changeset
453 necessary to fit and zero out all the elements between the old and new
cf900a2f1fa3 extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents:
diff changeset
454 lengths. */
cf900a2f1fa3 extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents:
diff changeset
455
cf900a2f1fa3 extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents:
diff changeset
456 DECLARE_INLINE_HEADER (
cf900a2f1fa3 extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents:
diff changeset
457 void
cf900a2f1fa3 extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents:
diff changeset
458 Dynarr_set_length_and_zero (void *d, Elemcount len)
cf900a2f1fa3 extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents:
diff changeset
459 )
cf900a2f1fa3 extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents:
diff changeset
460 {
cf900a2f1fa3 extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents:
diff changeset
461 Dynarr *dy = Dynarr_verify_mod (d);
cf900a2f1fa3 extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents:
diff changeset
462 Elemcount old_len = Dynarr_length (dy);
cf900a2f1fa3 extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents:
diff changeset
463 if (old_len >= len)
cf900a2f1fa3 extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents:
diff changeset
464 Dynarr_set_lengthr (dy, len);
cf900a2f1fa3 extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents:
diff changeset
465 else
cf900a2f1fa3 extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents:
diff changeset
466 Dynarr_increase_length_and_zero (d, len);
cf900a2f1fa3 extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents:
diff changeset
467 }
cf900a2f1fa3 extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents:
diff changeset
468
cf900a2f1fa3 extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents:
diff changeset
469 /* Reset the dynarr's length to 0. */
cf900a2f1fa3 extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents:
diff changeset
470 #define Dynarr_reset(d) Dynarr_set_lengthr (d, 0)
cf900a2f1fa3 extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents:
diff changeset
471
cf900a2f1fa3 extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents:
diff changeset
472 #ifdef MEMORY_USAGE_STATS
cf900a2f1fa3 extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents:
diff changeset
473 struct usage_stats;
cf900a2f1fa3 extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents:
diff changeset
474 Bytecount Dynarr_memory_usage (void *d, struct usage_stats *stats);
cf900a2f1fa3 extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents:
diff changeset
475 #endif
cf900a2f1fa3 extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents:
diff changeset
476
cf900a2f1fa3 extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents:
diff changeset
477 /************* Adding/deleting elements to/from a dynarr *************/
cf900a2f1fa3 extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents:
diff changeset
478
cf900a2f1fa3 extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents:
diff changeset
479 /* Set the Lisp implementation of the element at POS in dynarr D. Only
cf900a2f1fa3 extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents:
diff changeset
480 does this if the dynarr holds Lisp objects of a particular type (the
cf900a2f1fa3 extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents:
diff changeset
481 objects themselves, not pointers to them), and only under NEW_GC. */
cf900a2f1fa3 extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents:
diff changeset
482
cf900a2f1fa3 extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents:
diff changeset
483 #ifdef NEW_GC
cf900a2f1fa3 extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents:
diff changeset
484 #define DYNARR_SET_LISP_IMP(d, pos) \
cf900a2f1fa3 extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents:
diff changeset
485 do { \
cf900a2f1fa3 extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents:
diff changeset
486 if ((d)->lisp_imp) \
cf900a2f1fa3 extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents:
diff changeset
487 set_lheader_implementation \
cf900a2f1fa3 extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents:
diff changeset
488 ((struct lrecord_header *)&(((d)->base)[pos]), (d)->lisp_imp); \
cf900a2f1fa3 extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents:
diff changeset
489 } while (0)
cf900a2f1fa3 extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents:
diff changeset
490 #else
cf900a2f1fa3 extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents:
diff changeset
491 #define DYNARR_SET_LISP_IMP(d, pos) DO_NOTHING
cf900a2f1fa3 extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents:
diff changeset
492 #endif /* (not) NEW_GC */
cf900a2f1fa3 extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents:
diff changeset
493
cf900a2f1fa3 extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents:
diff changeset
494 /* Add Element EL to the end of dynarr D. */
cf900a2f1fa3 extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents:
diff changeset
495
cf900a2f1fa3 extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents:
diff changeset
496 #define Dynarr_add(d, el) \
cf900a2f1fa3 extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents:
diff changeset
497 do { \
cf900a2f1fa3 extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents:
diff changeset
498 Elemcount _da_pos = Dynarr_length (d); \
cf900a2f1fa3 extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents:
diff changeset
499 (void) Dynarr_verify_mod (d); \
cf900a2f1fa3 extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents:
diff changeset
500 Dynarr_increment (d); \
cf900a2f1fa3 extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents:
diff changeset
501 ((d)->base)[_da_pos] = (el); \
cf900a2f1fa3 extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents:
diff changeset
502 DYNARR_SET_LISP_IMP (d, _da_pos); \
cf900a2f1fa3 extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents:
diff changeset
503 } while (0)
cf900a2f1fa3 extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents:
diff changeset
504
cf900a2f1fa3 extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents:
diff changeset
505 /* Set EL as the element at position POS in dynarr D.
cf900a2f1fa3 extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents:
diff changeset
506 Expand the dynarr as necessary so that its length is enough to include
cf900a2f1fa3 extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents:
diff changeset
507 position POS within it, and zero out any new elements created as a
cf900a2f1fa3 extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents:
diff changeset
508 result of expansion, other than the one at POS. */
cf900a2f1fa3 extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents:
diff changeset
509
cf900a2f1fa3 extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents:
diff changeset
510 #define Dynarr_set(d, pos, el) \
cf900a2f1fa3 extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents:
diff changeset
511 do { \
cf900a2f1fa3 extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents:
diff changeset
512 Elemcount _ds_pos = (pos); \
cf900a2f1fa3 extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents:
diff changeset
513 (void) Dynarr_verify_mod (d); \
cf900a2f1fa3 extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents:
diff changeset
514 if (Dynarr_length (d) < _ds_pos + 1) \
cf900a2f1fa3 extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents:
diff changeset
515 Dynarr_increase_length_and_zero (d, _ds_pos + 1); \
cf900a2f1fa3 extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents:
diff changeset
516 ((d)->base)[_ds_pos] = (el); \
cf900a2f1fa3 extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents:
diff changeset
517 DYNARR_SET_LISP_IMP (d, _ds_pos); \
cf900a2f1fa3 extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents:
diff changeset
518 } while (0)
cf900a2f1fa3 extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents:
diff changeset
519
cf900a2f1fa3 extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents:
diff changeset
520 /* Add LEN contiguous elements, stored at BASE, to dynarr D. If BASE is
cf900a2f1fa3 extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents:
diff changeset
521 NULL, reserve space but don't store anything. */
cf900a2f1fa3 extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents:
diff changeset
522
cf900a2f1fa3 extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents:
diff changeset
523 DECLARE_INLINE_HEADER (
cf900a2f1fa3 extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents:
diff changeset
524 void
cf900a2f1fa3 extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents:
diff changeset
525 Dynarr_add_many (void *d, const void *base, Elemcount len)
cf900a2f1fa3 extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents:
diff changeset
526 )
cf900a2f1fa3 extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents:
diff changeset
527 {
cf900a2f1fa3 extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents:
diff changeset
528 /* This duplicates Dynarr_insert_many to some extent; but since it is
cf900a2f1fa3 extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents:
diff changeset
529 called so often, it seemed useful to remove the unnecessary stuff
cf900a2f1fa3 extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents:
diff changeset
530 from that function and to make it inline */
cf900a2f1fa3 extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents:
diff changeset
531 Dynarr *dy = Dynarr_verify_mod (d);
cf900a2f1fa3 extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents:
diff changeset
532 Elemcount pos = Dynarr_length (dy);
cf900a2f1fa3 extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents:
diff changeset
533 Dynarr_increase_length (dy, Dynarr_length (dy) + len);
cf900a2f1fa3 extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents:
diff changeset
534 if (base)
cf900a2f1fa3 extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents:
diff changeset
535 memcpy ((Rawbyte *) dy->base + pos*Dynarr_elsize (dy), base,
cf900a2f1fa3 extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents:
diff changeset
536 len*Dynarr_elsize (dy));
cf900a2f1fa3 extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents:
diff changeset
537 }
cf900a2f1fa3 extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents:
diff changeset
538
cf900a2f1fa3 extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents:
diff changeset
539 /* Insert LEN elements, currently pointed to by BASE, into dynarr D
cf900a2f1fa3 extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents:
diff changeset
540 starting at position POS. */
cf900a2f1fa3 extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents:
diff changeset
541
cf900a2f1fa3 extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents:
diff changeset
542 MODULE_API void Dynarr_insert_many (void *d, const void *base, Elemcount len,
cf900a2f1fa3 extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents:
diff changeset
543 Elemcount pos);
cf900a2f1fa3 extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents:
diff changeset
544
cf900a2f1fa3 extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents:
diff changeset
545 /* Prepend LEN elements, currently pointed to by BASE, to the beginning. */
cf900a2f1fa3 extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents:
diff changeset
546
cf900a2f1fa3 extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents:
diff changeset
547 #define Dynarr_prepend_many(d, base, len) Dynarr_insert_many (d, base, len, 0)
cf900a2f1fa3 extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents:
diff changeset
548
cf900a2f1fa3 extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents:
diff changeset
549 /* Add literal string S to dynarr D, which should hold chars or unsigned
cf900a2f1fa3 extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents:
diff changeset
550 chars. The final zero byte is not stored. */
cf900a2f1fa3 extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents:
diff changeset
551
cf900a2f1fa3 extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents:
diff changeset
552 #define Dynarr_add_literal_string(d, s) Dynarr_add_many (d, s, sizeof (s) - 1)
cf900a2f1fa3 extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents:
diff changeset
553
cf900a2f1fa3 extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents:
diff changeset
554 /* Convert Lisp string S to an external encoding according to CODESYS and
cf900a2f1fa3 extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents:
diff changeset
555 add to dynarr D, which should hold chars or unsigned chars. No final
cf900a2f1fa3 extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents:
diff changeset
556 zero byte is appended. */
cf900a2f1fa3 extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents:
diff changeset
557
cf900a2f1fa3 extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents:
diff changeset
558 /* #### This should be an inline function but LISP_STRING_TO_SIZED_EXTERNAL
cf900a2f1fa3 extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents:
diff changeset
559 isn't declared yet. */
cf900a2f1fa3 extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents:
diff changeset
560
cf900a2f1fa3 extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents:
diff changeset
561 #define Dynarr_add_ext_lisp_string(d, s, codesys) \
cf900a2f1fa3 extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents:
diff changeset
562 do { \
cf900a2f1fa3 extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents:
diff changeset
563 Lisp_Object dyna_ls_s = (s); \
cf900a2f1fa3 extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents:
diff changeset
564 Lisp_Object dyna_ls_cs = (codesys); \
cf900a2f1fa3 extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents:
diff changeset
565 Extbyte *dyna_ls_eb; \
cf900a2f1fa3 extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents:
diff changeset
566 Bytecount dyna_ls_bc; \
cf900a2f1fa3 extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents:
diff changeset
567 \
cf900a2f1fa3 extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents:
diff changeset
568 LISP_STRING_TO_SIZED_EXTERNAL (dyna_ls_s, dyna_ls_eb, \
cf900a2f1fa3 extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents:
diff changeset
569 dyna_ls_bc, dyna_ls_cs); \
cf900a2f1fa3 extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents:
diff changeset
570 Dynarr_add_many (d, dyna_ls_eb, dyna_ls_bc); \
cf900a2f1fa3 extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents:
diff changeset
571 } while (0)
cf900a2f1fa3 extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents:
diff changeset
572
cf900a2f1fa3 extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents:
diff changeset
573 /* Delete LEN elements starting at position POS. */
cf900a2f1fa3 extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents:
diff changeset
574
cf900a2f1fa3 extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents:
diff changeset
575 MODULE_API void Dynarr_delete_many (void *d, Elemcount pos, Elemcount len);
cf900a2f1fa3 extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents:
diff changeset
576
cf900a2f1fa3 extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents:
diff changeset
577 /* Pop off (i.e. delete) the last element from the dynarr and return it */
cf900a2f1fa3 extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents:
diff changeset
578
cf900a2f1fa3 extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents:
diff changeset
579 #define Dynarr_pop(d) \
cf900a2f1fa3 extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents:
diff changeset
580 (dynarr_checking_assert (Dynarr_length (d) > 0), \
cf900a2f1fa3 extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents:
diff changeset
581 Dynarr_verify_mod (d)->len_--, \
cf900a2f1fa3 extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents:
diff changeset
582 Dynarr_at (d, Dynarr_length (d)))
cf900a2f1fa3 extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents:
diff changeset
583
cf900a2f1fa3 extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents:
diff changeset
584 /* Delete the item at POS */
cf900a2f1fa3 extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents:
diff changeset
585
cf900a2f1fa3 extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents:
diff changeset
586 #define Dynarr_delete(d, pos) Dynarr_delete_many (d, pos, 1)
cf900a2f1fa3 extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents:
diff changeset
587
cf900a2f1fa3 extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents:
diff changeset
588 /* Delete the item located at memory address P, which must be a `type *'
cf900a2f1fa3 extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents:
diff changeset
589 pointer, where `type' is the type of the elements of the dynarr. */
cf900a2f1fa3 extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents:
diff changeset
590 #define Dynarr_delete_by_pointer(d, p) \
cf900a2f1fa3 extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents:
diff changeset
591 Dynarr_delete_many (d, (p) - ((d)->base), 1)
cf900a2f1fa3 extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents:
diff changeset
592
cf900a2f1fa3 extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents:
diff changeset
593 /* Delete all elements that are numerically equal to EL. */
cf900a2f1fa3 extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents:
diff changeset
594
cf900a2f1fa3 extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents:
diff changeset
595 #define Dynarr_delete_object(d, el) \
cf900a2f1fa3 extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents:
diff changeset
596 do \
cf900a2f1fa3 extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents:
diff changeset
597 { \
cf900a2f1fa3 extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents:
diff changeset
598 REGISTER int i; \
cf900a2f1fa3 extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents:
diff changeset
599 for (i = Dynarr_length (d) - 1; i >= 0; i--) \
cf900a2f1fa3 extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents:
diff changeset
600 { \
cf900a2f1fa3 extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents:
diff changeset
601 if (el == Dynarr_at (d, i)) \
cf900a2f1fa3 extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents:
diff changeset
602 Dynarr_delete_many (d, i, 1); \
cf900a2f1fa3 extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents:
diff changeset
603 } \
cf900a2f1fa3 extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents:
diff changeset
604 } while (0)
cf900a2f1fa3 extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents:
diff changeset
605
cf900a2f1fa3 extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents:
diff changeset
606
cf900a2f1fa3 extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents:
diff changeset
607 /************************************************************************/
cf900a2f1fa3 extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents:
diff changeset
608 /** Stack-like malloc/free **/
cf900a2f1fa3 extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents:
diff changeset
609 /************************************************************************/
cf900a2f1fa3 extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents:
diff changeset
610
5729
f7abcda06b1b Since stack_like_{malloc,free}() are only used when WIN32_ANY,
Jerry James <james@xemacs.org>
parents: 5402
diff changeset
611 #ifdef WIN32_ANY
5168
cf900a2f1fa3 extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents:
diff changeset
612 void *stack_like_malloc (Bytecount size);
cf900a2f1fa3 extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents:
diff changeset
613 void stack_like_free (void *val);
5729
f7abcda06b1b Since stack_like_{malloc,free}() are only used when WIN32_ANY,
Jerry James <james@xemacs.org>
parents: 5402
diff changeset
614 #endif
5168
cf900a2f1fa3 extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents:
diff changeset
615
cf900a2f1fa3 extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents:
diff changeset
616
cf900a2f1fa3 extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents:
diff changeset
617 /************************************************************************/
cf900a2f1fa3 extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents:
diff changeset
618 /** Gap array **/
cf900a2f1fa3 extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents:
diff changeset
619 /************************************************************************/
cf900a2f1fa3 extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents:
diff changeset
620
cf900a2f1fa3 extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents:
diff changeset
621 /* Holds a marker that moves as elements in the array are inserted and
cf900a2f1fa3 extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents:
diff changeset
622 deleted, similar to standard markers. */
cf900a2f1fa3 extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents:
diff changeset
623
cf900a2f1fa3 extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents:
diff changeset
624 typedef struct gap_array_marker
cf900a2f1fa3 extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents:
diff changeset
625 {
cf900a2f1fa3 extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents:
diff changeset
626 #ifdef NEW_GC
cf900a2f1fa3 extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents:
diff changeset
627 NORMAL_LISP_OBJECT_HEADER header;
cf900a2f1fa3 extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents:
diff changeset
628 #endif /* NEW_GC */
cf900a2f1fa3 extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents:
diff changeset
629 int pos;
cf900a2f1fa3 extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents:
diff changeset
630 struct gap_array_marker *next;
cf900a2f1fa3 extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents:
diff changeset
631 } Gap_Array_Marker;
cf900a2f1fa3 extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents:
diff changeset
632
cf900a2f1fa3 extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents:
diff changeset
633
cf900a2f1fa3 extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents:
diff changeset
634 /* Holds a "gap array", which is an array of elements with a gap located
cf900a2f1fa3 extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents:
diff changeset
635 in it. Insertions and deletions with a high degree of locality
cf900a2f1fa3 extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents:
diff changeset
636 are very fast, essentially in constant time. Array positions as
cf900a2f1fa3 extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents:
diff changeset
637 used and returned in the gap array functions are independent of
cf900a2f1fa3 extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents:
diff changeset
638 the gap. */
cf900a2f1fa3 extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents:
diff changeset
639
cf900a2f1fa3 extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents:
diff changeset
640 /* Layout of gap array:
cf900a2f1fa3 extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents:
diff changeset
641
cf900a2f1fa3 extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents:
diff changeset
642 <------ gap ------><---- gapsize ----><----- numels - gap ---->
cf900a2f1fa3 extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents:
diff changeset
643 <---------------------- numels + gapsize --------------------->
cf900a2f1fa3 extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents:
diff changeset
644
cf900a2f1fa3 extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents:
diff changeset
645 For marking purposes, we use two extra variables computed from
cf900a2f1fa3 extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents:
diff changeset
646 the others -- the offset to the data past the gap, plus the number
cf900a2f1fa3 extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents:
diff changeset
647 of elements in that data:
cf900a2f1fa3 extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents:
diff changeset
648
cf900a2f1fa3 extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents:
diff changeset
649 offset_past_gap = elsize * (gap + gapsize)
cf900a2f1fa3 extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents:
diff changeset
650 els_past_gap = numels - gap
cf900a2f1fa3 extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents:
diff changeset
651 */
cf900a2f1fa3 extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents:
diff changeset
652
cf900a2f1fa3 extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents:
diff changeset
653
cf900a2f1fa3 extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents:
diff changeset
654 typedef struct gap_array
cf900a2f1fa3 extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents:
diff changeset
655 {
cf900a2f1fa3 extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents:
diff changeset
656 #ifdef NEW_GC
cf900a2f1fa3 extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents:
diff changeset
657 NORMAL_LISP_OBJECT_HEADER header;
cf900a2f1fa3 extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents:
diff changeset
658 int is_lisp;
cf900a2f1fa3 extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents:
diff changeset
659 #endif /* NEW_GC */
cf900a2f1fa3 extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents:
diff changeset
660 Elemcount gap;
cf900a2f1fa3 extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents:
diff changeset
661 Elemcount gapsize;
cf900a2f1fa3 extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents:
diff changeset
662 Elemcount numels;
cf900a2f1fa3 extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents:
diff changeset
663 Bytecount elsize;
cf900a2f1fa3 extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents:
diff changeset
664 /* Redundant numbers computed from the others, for marking purposes */
cf900a2f1fa3 extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents:
diff changeset
665 Bytecount offset_past_gap;
cf900a2f1fa3 extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents:
diff changeset
666 Elemcount els_past_gap;
cf900a2f1fa3 extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents:
diff changeset
667 Gap_Array_Marker *markers;
cf900a2f1fa3 extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents:
diff changeset
668 /* this is a stretchy array */
cf900a2f1fa3 extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents:
diff changeset
669 char array[1];
cf900a2f1fa3 extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents:
diff changeset
670 } Gap_Array;
cf900a2f1fa3 extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents:
diff changeset
671
cf900a2f1fa3 extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents:
diff changeset
672 #ifdef NEW_GC
cf900a2f1fa3 extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents:
diff changeset
673 struct gap_array_marker;
cf900a2f1fa3 extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents:
diff changeset
674
cf900a2f1fa3 extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents:
diff changeset
675 DECLARE_LISP_OBJECT (gap_array_marker, struct gap_array_marker);
cf900a2f1fa3 extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents:
diff changeset
676 #define XGAP_ARRAY_MARKER(x) \
cf900a2f1fa3 extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents:
diff changeset
677 XRECORD (x, gap_array_marker, struct gap_array_marker)
cf900a2f1fa3 extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents:
diff changeset
678 #define wrap_gap_array_marker(p) wrap_record (p, gap_array_marker)
cf900a2f1fa3 extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents:
diff changeset
679 #define GAP_ARRAY_MARKERP(x) RECORDP (x, gap_array_marker)
cf900a2f1fa3 extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents:
diff changeset
680 #define CHECK_GAP_ARRAY_MARKER(x) CHECK_RECORD (x, gap_array_marker)
cf900a2f1fa3 extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents:
diff changeset
681 #define CONCHECK_GAP_ARRAY_MARKER(x) CONCHECK_RECORD (x, gap_array_marker)
cf900a2f1fa3 extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents:
diff changeset
682
cf900a2f1fa3 extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents:
diff changeset
683 struct gap_array;
cf900a2f1fa3 extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents:
diff changeset
684
cf900a2f1fa3 extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents:
diff changeset
685 DECLARE_LISP_OBJECT (gap_array, struct gap_array);
cf900a2f1fa3 extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents:
diff changeset
686 #define XGAP_ARRAY(x) XRECORD (x, gap_array, struct gap_array)
cf900a2f1fa3 extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents:
diff changeset
687 #define wrap_gap_array(p) wrap_record (p, gap_array)
cf900a2f1fa3 extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents:
diff changeset
688 #define GAP_ARRAYP(x) RECORDP (x, gap_array)
cf900a2f1fa3 extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents:
diff changeset
689 #define CHECK_GAP_ARRAY(x) CHECK_RECORD (x, gap_array)
cf900a2f1fa3 extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents:
diff changeset
690 #define CONCHECK_GAP_ARRAY(x) CONCHECK_RECORD (x, gap_array)
cf900a2f1fa3 extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents:
diff changeset
691 #endif /* NEW_GC */
cf900a2f1fa3 extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents:
diff changeset
692
cf900a2f1fa3 extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents:
diff changeset
693 #ifdef NEW_GC
cf900a2f1fa3 extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents:
diff changeset
694 #define XD_GAP_ARRAY_MARKER_DESC \
cf900a2f1fa3 extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents:
diff changeset
695 { XD_LISP_OBJECT, offsetof (Gap_Array, markers) }
cf900a2f1fa3 extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents:
diff changeset
696 #else /* not NEW_GC */
cf900a2f1fa3 extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents:
diff changeset
697 #define XD_GAP_ARRAY_MARKER_DESC \
cf900a2f1fa3 extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents:
diff changeset
698 { XD_BLOCK_PTR, offsetof (Gap_Array, markers), 1, \
cf900a2f1fa3 extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents:
diff changeset
699 { &gap_array_marker_description }, XD_FLAG_NO_KKCC }
cf900a2f1fa3 extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents:
diff changeset
700 #endif /* not NEW_GC */
cf900a2f1fa3 extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents:
diff changeset
701
cf900a2f1fa3 extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents:
diff changeset
702 #define XD_GAP_ARRAY_DESC(sub_desc) \
cf900a2f1fa3 extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents:
diff changeset
703 { XD_ELEMCOUNT, offsetof (Gap_Array, gap) }, \
cf900a2f1fa3 extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents:
diff changeset
704 { XD_BYTECOUNT, offsetof (Gap_Array, offset_past_gap) }, \
cf900a2f1fa3 extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents:
diff changeset
705 { XD_ELEMCOUNT, offsetof (Gap_Array, els_past_gap) }, \
cf900a2f1fa3 extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents:
diff changeset
706 XD_GAP_ARRAY_MARKER_DESC, \
cf900a2f1fa3 extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents:
diff changeset
707 { XD_BLOCK_ARRAY, offsetof (Gap_Array, array), XD_INDIRECT (0, 0), \
cf900a2f1fa3 extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents:
diff changeset
708 { sub_desc } }, \
cf900a2f1fa3 extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents:
diff changeset
709 { XD_BLOCK_ARRAY, XD_INDIRECT (1, offsetof (Gap_Array, array)), \
cf900a2f1fa3 extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents:
diff changeset
710 XD_INDIRECT (2, 0), { sub_desc } }
cf900a2f1fa3 extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents:
diff changeset
711
cf900a2f1fa3 extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents:
diff changeset
712 /* Convert a "memory position" (i.e. taking the gap into account) into
cf900a2f1fa3 extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents:
diff changeset
713 the address of the element at (i.e. after) that position. "Memory
cf900a2f1fa3 extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents:
diff changeset
714 positions" are only used internally and are of type Memxpos.
cf900a2f1fa3 extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents:
diff changeset
715 "Array positions" are used externally and are of type Elemcount. */
cf900a2f1fa3 extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents:
diff changeset
716 #define GAP_ARRAY_MEMEL_ADDR(ga, memel) ((ga)->array + (ga)->elsize*(memel))
cf900a2f1fa3 extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents:
diff changeset
717
cf900a2f1fa3 extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents:
diff changeset
718 /* Number of elements currently in a gap array */
cf900a2f1fa3 extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents:
diff changeset
719 #define gap_array_length(ga) ((ga)->numels)
cf900a2f1fa3 extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents:
diff changeset
720
cf900a2f1fa3 extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents:
diff changeset
721 #define gap_array_gappos(ga) ((ga)->gap)
cf900a2f1fa3 extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents:
diff changeset
722 #define gap_array_gapsize(ga) ((ga)->gapsize)
cf900a2f1fa3 extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents:
diff changeset
723
cf900a2f1fa3 extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents:
diff changeset
724 #define GAP_ARRAY_ARRAY_TO_MEMORY_POS_1(pos, gappos, gapsize) \
cf900a2f1fa3 extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents:
diff changeset
725 ((pos) < gappos ? (pos) : (pos) + gapsize)
cf900a2f1fa3 extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents:
diff changeset
726
cf900a2f1fa3 extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents:
diff changeset
727 #define GAP_ARRAY_ARRAY_TO_MEMORY_POS(ga, pos) \
cf900a2f1fa3 extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents:
diff changeset
728 GAP_ARRAY_ARRAY_TO_MEMORY_POS_1 (pos, (ga)->gap, (ga)->gapsize)
cf900a2f1fa3 extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents:
diff changeset
729
cf900a2f1fa3 extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents:
diff changeset
730 #define GAP_ARRAY_MEMORY_TO_ARRAY_POS(ga, pos) \
cf900a2f1fa3 extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents:
diff changeset
731 ((pos) <= (ga)->gap ? (pos) : (pos) - (ga)->gapsize)
cf900a2f1fa3 extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents:
diff changeset
732
cf900a2f1fa3 extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents:
diff changeset
733 /* Return a pointer to the element at a given position. */
cf900a2f1fa3 extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents:
diff changeset
734 #define gap_array_atp(ga, pos, type) \
cf900a2f1fa3 extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents:
diff changeset
735 ((type *) GAP_ARRAY_MEMEL_ADDR (ga, GAP_ARRAY_ARRAY_TO_MEMORY_POS (ga, pos)))
cf900a2f1fa3 extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents:
diff changeset
736
cf900a2f1fa3 extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents:
diff changeset
737 /* Return the element at a given position. */
cf900a2f1fa3 extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents:
diff changeset
738 #define gap_array_at(ga, pos, type) (*gap_array_atp (ga, pos, type))
cf900a2f1fa3 extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents:
diff changeset
739
cf900a2f1fa3 extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents:
diff changeset
740 /* Return a pointer to the beginning of memory storage for the gap array.
cf900a2f1fa3 extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents:
diff changeset
741 Note this is NOT the same as gap_array_atp(ga, 0, type) because that
cf900a2f1fa3 extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents:
diff changeset
742 will skip forward past the gap if the gap is at position 0. */
cf900a2f1fa3 extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents:
diff changeset
743 #define gap_array_begin(ga, type) ((type *) ((ga)->array))
cf900a2f1fa3 extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents:
diff changeset
744
cf900a2f1fa3 extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents:
diff changeset
745 #ifndef NEW_GC
cf900a2f1fa3 extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents:
diff changeset
746 extern const struct sized_memory_description lispobj_gap_array_description;
cf900a2f1fa3 extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents:
diff changeset
747 extern const struct sized_memory_description gap_array_marker_description;
cf900a2f1fa3 extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents:
diff changeset
748 #endif
cf900a2f1fa3 extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents:
diff changeset
749
cf900a2f1fa3 extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents:
diff changeset
750 Bytecount gap_array_byte_size (Gap_Array *ga);
cf900a2f1fa3 extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents:
diff changeset
751 Gap_Array *gap_array_insert_els (Gap_Array *ga, Elemcount pos, void *elptr,
cf900a2f1fa3 extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents:
diff changeset
752 Elemcount numels);
cf900a2f1fa3 extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents:
diff changeset
753 void gap_array_delete_els (Gap_Array *ga, Elemcount from, Elemcount numdel);
cf900a2f1fa3 extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents:
diff changeset
754 #define gap_array_delete_all_els(ga) \
cf900a2f1fa3 extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents:
diff changeset
755 gap_array_delete_els (ga, 0, gap_array_length (ga))
cf900a2f1fa3 extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents:
diff changeset
756 Gap_Array_Marker *gap_array_make_marker (Gap_Array *ga, Elemcount pos);
cf900a2f1fa3 extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents:
diff changeset
757 void gap_array_delete_marker (Gap_Array *ga, Gap_Array_Marker *m);
cf900a2f1fa3 extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents:
diff changeset
758 void gap_array_delete_all_markers (Gap_Array *ga);
cf900a2f1fa3 extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents:
diff changeset
759 void gap_array_move_marker (Gap_Array *ga, Gap_Array_Marker *m, Elemcount pos);
cf900a2f1fa3 extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents:
diff changeset
760 #define gap_array_marker_pos(ga, m) \
cf900a2f1fa3 extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents:
diff changeset
761 GAP_ARRAY_MEMORY_TO_ARRAY_POS (ga, (m)->pos)
cf900a2f1fa3 extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents:
diff changeset
762 Gap_Array *make_gap_array (Elemcount elsize, int USED_IF_NEW_GC (do_lisp));
cf900a2f1fa3 extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents:
diff changeset
763 Gap_Array *gap_array_clone (Gap_Array *ga);
cf900a2f1fa3 extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents:
diff changeset
764 void free_gap_array (Gap_Array *ga);
5170
5ddbab03b0e6 various fixes to memory-usage stats
Ben Wing <ben@xemacs.org>
parents: 5169
diff changeset
765 Bytecount gap_array_memory_usage (Gap_Array *ga, struct usage_stats *stats,
5ddbab03b0e6 various fixes to memory-usage stats
Ben Wing <ben@xemacs.org>
parents: 5169
diff changeset
766 Bytecount *marker_ancillary);
5168
cf900a2f1fa3 extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents:
diff changeset
767
5169
6c6d78781d59 cleanup of code related to xfree(), better KKCC backtrace capabilities, document XD_INLINE_LISP_OBJECT_BLOCK_PTR, fix some memory leaks, other code cleanup
Ben Wing <ben@xemacs.org>
parents: 5168
diff changeset
768 #endif /* INCLUDED_array_h_ */