Mercurial > hg > xemacs-beta
annotate src/array.h @ 5934:e2fae7783046 cygwin
lots of use of EMACS_INT, a few others, to eliminate all pointer truncation warnings
author | Henry Thompson <ht@markup.co.uk> |
---|---|
date | Sat, 12 Dec 2015 19:08:46 +0000 |
parents | f7abcda06b1b |
children |
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 |
5934
e2fae7783046
lots of use of EMACS_INT, a few others, to eliminate all pointer truncation warnings
Henry Thompson <ht@markup.co.uk>
parents:
5729
diff
changeset
|
49 /* HST increased these for 64-bit */ |
5168
cf900a2f1fa3
extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents:
diff
changeset
|
50 #define Dynarr_declare(type) \ |
cf900a2f1fa3
extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents:
diff
changeset
|
51 struct lrecord_header header; \ |
cf900a2f1fa3
extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents:
diff
changeset
|
52 type *base; \ |
cf900a2f1fa3
extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents:
diff
changeset
|
53 DECLARE_DYNARR_LISP_IMP () \ |
cf900a2f1fa3
extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents:
diff
changeset
|
54 DECLARE_DYNARR_LOCKED () \ |
cf900a2f1fa3
extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents:
diff
changeset
|
55 int elsize_; \ |
5934
e2fae7783046
lots of use of EMACS_INT, a few others, to eliminate all pointer truncation warnings
Henry Thompson <ht@markup.co.uk>
parents:
5729
diff
changeset
|
56 EMACS_INT len_; \ |
e2fae7783046
lots of use of EMACS_INT, a few others, to eliminate all pointer truncation warnings
Henry Thompson <ht@markup.co.uk>
parents:
5729
diff
changeset
|
57 EMACS_INT largest_; \ |
e2fae7783046
lots of use of EMACS_INT, a few others, to eliminate all pointer truncation warnings
Henry Thompson <ht@markup.co.uk>
parents:
5729
diff
changeset
|
58 EMACS_INT max_ |
5168
cf900a2f1fa3
extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents:
diff
changeset
|
59 |
cf900a2f1fa3
extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents:
diff
changeset
|
60 typedef struct dynarr |
cf900a2f1fa3
extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents:
diff
changeset
|
61 { |
cf900a2f1fa3
extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents:
diff
changeset
|
62 Dynarr_declare (void); |
cf900a2f1fa3
extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents:
diff
changeset
|
63 } Dynarr; |
cf900a2f1fa3
extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents:
diff
changeset
|
64 |
cf900a2f1fa3
extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents:
diff
changeset
|
65 #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
|
66 { 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
|
67 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
|
68 { 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
|
69 { 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
|
70 { 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
|
71 |
cf900a2f1fa3
extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents:
diff
changeset
|
72 #ifdef NEW_GC |
cf900a2f1fa3
extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents:
diff
changeset
|
73 #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
|
74 { 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
|
75 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
|
76 { 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
|
77 { 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
|
78 { 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
|
79 #endif /* NEW_GC */ |
cf900a2f1fa3
extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents:
diff
changeset
|
80 |
cf900a2f1fa3
extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents:
diff
changeset
|
81 /************* Dynarr verification *************/ |
cf900a2f1fa3
extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents:
diff
changeset
|
82 |
cf900a2f1fa3
extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents:
diff
changeset
|
83 /* Dynarr locking and verification. |
cf900a2f1fa3
extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents:
diff
changeset
|
84 |
cf900a2f1fa3
extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents:
diff
changeset
|
85 [I] VERIFICATION |
cf900a2f1fa3
extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents:
diff
changeset
|
86 |
cf900a2f1fa3
extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents:
diff
changeset
|
87 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
|
88 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
|
89 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
|
90 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
|
91 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
|
92 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
|
93 |
cf900a2f1fa3
extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents:
diff
changeset
|
94 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
|
95 |
cf900a2f1fa3
extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents:
diff
changeset
|
96 (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
|
97 involving the length/size values: |
cf900a2f1fa3
extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents:
diff
changeset
|
98 |
cf900a2f1fa3
extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents:
diff
changeset
|
99 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
|
100 |
cf900a2f1fa3
extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents:
diff
changeset
|
101 (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
|
102 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
|
103 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
|
104 |
cf900a2f1fa3
extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents:
diff
changeset
|
105 (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
|
106 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
|
107 is being performed: |
cf900a2f1fa3
extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents:
diff
changeset
|
108 |
cf900a2f1fa3
extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents:
diff
changeset
|
109 (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
|
110 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
|
111 (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
|
112 POS == Dynarr_largest(). |
cf900a2f1fa3
extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents:
diff
changeset
|
113 (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
|
114 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
|
115 comment below. |
cf900a2f1fa3
extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents:
diff
changeset
|
116 (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
|
117 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
|
118 0 <= POS <= Dynarr_length(). |
cf900a2f1fa3
extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents:
diff
changeset
|
119 |
cf900a2f1fa3
extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents:
diff
changeset
|
120 #### 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
|
121 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
|
122 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
|
123 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
|
124 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
|
125 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
|
126 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
|
127 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
|
128 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
|
129 |
cf900a2f1fa3
extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents:
diff
changeset
|
130 [II] LOCKING |
cf900a2f1fa3
extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents:
diff
changeset
|
131 |
cf900a2f1fa3
extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents:
diff
changeset
|
132 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
|
133 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
|
134 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
|
135 |
cf900a2f1fa3
extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents:
diff
changeset
|
136 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
|
137 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
|
138 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
|
139 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
|
140 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
|
141 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
|
142 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
|
143 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
|
144 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
|
145 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
|
146 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
|
147 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
|
148 For more info:-- |
cf900a2f1fa3
extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents:
diff
changeset
|
149 |
cf900a2f1fa3
extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents:
diff
changeset
|
150 (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
|
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 |
cf900a2f1fa3
extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents:
diff
changeset
|
154 #ifdef ERROR_CHECK_DYNARR |
cf900a2f1fa3
extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents:
diff
changeset
|
155 DECLARE_INLINE_HEADER ( |
cf900a2f1fa3
extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents:
diff
changeset
|
156 int |
cf900a2f1fa3
extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents:
diff
changeset
|
157 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
|
158 ) |
cf900a2f1fa3
extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents:
diff
changeset
|
159 { |
cf900a2f1fa3
extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents:
diff
changeset
|
160 Dynarr *dy = (Dynarr *) d; |
cf900a2f1fa3
extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents:
diff
changeset
|
161 /* 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
|
162 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
|
163 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
|
164 return pos; |
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 |
cf900a2f1fa3
extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents:
diff
changeset
|
167 DECLARE_INLINE_HEADER ( |
cf900a2f1fa3
extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents:
diff
changeset
|
168 int |
cf900a2f1fa3
extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents:
diff
changeset
|
169 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
|
170 ) |
cf900a2f1fa3
extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents:
diff
changeset
|
171 { |
cf900a2f1fa3
extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents:
diff
changeset
|
172 Dynarr *dy = (Dynarr *) d; |
cf900a2f1fa3
extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents:
diff
changeset
|
173 /* 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
|
174 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
|
175 /* [[ 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
|
176 |
cf900a2f1fa3
extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents:
diff
changeset
|
177 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
|
178 Dynarr_length (dyn)); |
cf900a2f1fa3
extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents:
diff
changeset
|
179 |
cf900a2f1fa3
extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents:
diff
changeset
|
180 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
|
181 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
|
182 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
|
183 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
|
184 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
|
185 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
|
186 |
cf900a2f1fa3
extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents:
diff
changeset
|
187 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
|
188 `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
|
189 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
|
190 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
|
191 return pos; |
cf900a2f1fa3
extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents:
diff
changeset
|
192 /* #### 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
|
193 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
|
194 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
|
195 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
|
196 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
|
197 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
|
198 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
|
199 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
|
200 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
|
201 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
|
202 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
|
203 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
|
204 return pos; |
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 |
cf900a2f1fa3
extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents:
diff
changeset
|
207 DECLARE_INLINE_HEADER ( |
cf900a2f1fa3
extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents:
diff
changeset
|
208 int |
cf900a2f1fa3
extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents:
diff
changeset
|
209 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
|
210 int line) |
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 { |
cf900a2f1fa3
extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents:
diff
changeset
|
213 Dynarr *dy = (Dynarr *) d; |
cf900a2f1fa3
extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents:
diff
changeset
|
214 /* 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
|
215 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
|
216 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
|
217 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
|
218 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
|
219 return pos; |
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 |
cf900a2f1fa3
extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents:
diff
changeset
|
222 #else |
cf900a2f1fa3
extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents:
diff
changeset
|
223 #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
|
224 #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
|
225 #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
|
226 #endif /* ERROR_CHECK_DYNARR */ |
cf900a2f1fa3
extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents:
diff
changeset
|
227 |
cf900a2f1fa3
extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents:
diff
changeset
|
228 #ifdef ERROR_CHECK_DYNARR |
cf900a2f1fa3
extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents:
diff
changeset
|
229 DECLARE_INLINE_HEADER ( |
cf900a2f1fa3
extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents:
diff
changeset
|
230 Dynarr * |
cf900a2f1fa3
extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents:
diff
changeset
|
231 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
|
232 ) |
cf900a2f1fa3
extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents:
diff
changeset
|
233 { |
cf900a2f1fa3
extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents:
diff
changeset
|
234 Dynarr *dy = (Dynarr *) d; |
cf900a2f1fa3
extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents:
diff
changeset
|
235 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
|
236 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
|
237 return dy; |
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 |
cf900a2f1fa3
extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents:
diff
changeset
|
240 DECLARE_INLINE_HEADER ( |
cf900a2f1fa3
extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents:
diff
changeset
|
241 Dynarr * |
cf900a2f1fa3
extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents:
diff
changeset
|
242 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
|
243 ) |
cf900a2f1fa3
extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents:
diff
changeset
|
244 { |
cf900a2f1fa3
extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents:
diff
changeset
|
245 Dynarr *dy = (Dynarr *) d; |
cf900a2f1fa3
extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents:
diff
changeset
|
246 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
|
247 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
|
248 } |
cf900a2f1fa3
extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents:
diff
changeset
|
249 |
cf900a2f1fa3
extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents:
diff
changeset
|
250 #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
|
251 #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
|
252 |
cf900a2f1fa3
extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents:
diff
changeset
|
253 DECLARE_INLINE_HEADER ( |
cf900a2f1fa3
extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents:
diff
changeset
|
254 void |
cf900a2f1fa3
extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents:
diff
changeset
|
255 Dynarr_lock (void *d) |
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 { |
cf900a2f1fa3
extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents:
diff
changeset
|
258 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
|
259 dy->locked = 1; |
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 |
cf900a2f1fa3
extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents:
diff
changeset
|
262 DECLARE_INLINE_HEADER ( |
cf900a2f1fa3
extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents:
diff
changeset
|
263 void |
cf900a2f1fa3
extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents:
diff
changeset
|
264 Dynarr_unlock (void *d) |
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 { |
cf900a2f1fa3
extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents:
diff
changeset
|
267 Dynarr *dy = Dynarr_verify (d); |
cf900a2f1fa3
extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents:
diff
changeset
|
268 assert (dy->locked); |
cf900a2f1fa3
extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents:
diff
changeset
|
269 dy->locked = 0; |
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 |
cf900a2f1fa3
extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents:
diff
changeset
|
272 #else /* not ERROR_CHECK_DYNARR */ |
cf900a2f1fa3
extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents:
diff
changeset
|
273 |
cf900a2f1fa3
extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents:
diff
changeset
|
274 #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
|
275 #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
|
276 #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
|
277 #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
|
278 |
cf900a2f1fa3
extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents:
diff
changeset
|
279 #endif /* ERROR_CHECK_DYNARR */ |
cf900a2f1fa3
extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents:
diff
changeset
|
280 |
cf900a2f1fa3
extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents:
diff
changeset
|
281 /************* Dynarr creation *************/ |
cf900a2f1fa3
extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents:
diff
changeset
|
282 |
cf900a2f1fa3
extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents:
diff
changeset
|
283 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
|
284 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
|
285 |
cf900a2f1fa3
extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents:
diff
changeset
|
286 #ifdef NEW_GC |
cf900a2f1fa3
extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents:
diff
changeset
|
287 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
|
288 const struct lrecord_implementation |
cf900a2f1fa3
extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents:
diff
changeset
|
289 *dynarr_imp, |
cf900a2f1fa3
extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents:
diff
changeset
|
290 const struct lrecord_implementation *imp); |
cf900a2f1fa3
extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents:
diff
changeset
|
291 |
cf900a2f1fa3
extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents:
diff
changeset
|
292 #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
|
293 ((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
|
294 #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
|
295 ((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
|
296 #endif /* NEW_GC */ |
cf900a2f1fa3
extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents:
diff
changeset
|
297 #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
|
298 #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
|
299 ((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
|
300 |
cf900a2f1fa3
extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents:
diff
changeset
|
301 /************* Dynarr access *************/ |
cf900a2f1fa3
extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents:
diff
changeset
|
302 |
cf900a2f1fa3
extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents:
diff
changeset
|
303 #ifdef ERROR_CHECK_DYNARR |
cf900a2f1fa3
extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents:
diff
changeset
|
304 #define Dynarr_at(d, pos) \ |
cf900a2f1fa3
extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents:
diff
changeset
|
305 ((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
|
306 #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
|
307 (&((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
|
308 #define Dynarr_atp(d, pos) \ |
cf900a2f1fa3
extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents:
diff
changeset
|
309 (&((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
|
310 #else |
cf900a2f1fa3
extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents:
diff
changeset
|
311 #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
|
312 #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
|
313 #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
|
314 #endif |
cf900a2f1fa3
extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents:
diff
changeset
|
315 |
cf900a2f1fa3
extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents:
diff
changeset
|
316 /* 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
|
317 #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
|
318 #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
|
319 #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
|
320 |
cf900a2f1fa3
extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents:
diff
changeset
|
321 |
cf900a2f1fa3
extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents:
diff
changeset
|
322 /************* 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
|
323 |
cf900a2f1fa3
extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents:
diff
changeset
|
324 /* 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
|
325 be used as an lvalue. */ |
cf900a2f1fa3
extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents:
diff
changeset
|
326 #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
|
327 /* 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
|
328 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
|
329 #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
|
330 /* 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
|
331 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
|
332 #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
|
333 /* 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
|
334 #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
|
335 /* 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
|
336 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
|
337 #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
|
338 |
cf900a2f1fa3
extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents:
diff
changeset
|
339 /* 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
|
340 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
|
341 Dynarr_set_lengthr() instead. */ |
cf900a2f1fa3
extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents:
diff
changeset
|
342 DECLARE_INLINE_HEADER ( |
cf900a2f1fa3
extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents:
diff
changeset
|
343 void |
cf900a2f1fa3
extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents:
diff
changeset
|
344 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
|
345 ) |
cf900a2f1fa3
extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents:
diff
changeset
|
346 { |
cf900a2f1fa3
extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents:
diff
changeset
|
347 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
|
348 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
|
349 /* 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
|
350 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
|
351 dy->len_ = len; |
cf900a2f1fa3
extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents:
diff
changeset
|
352 if (dy->len_ > dy->largest_) |
cf900a2f1fa3
extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents:
diff
changeset
|
353 dy->largest_ = dy->len_; |
cf900a2f1fa3
extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents:
diff
changeset
|
354 (void) Dynarr_verify_mod (d); |
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 |
cf900a2f1fa3
extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents:
diff
changeset
|
357 /* "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
|
358 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
|
359 |
cf900a2f1fa3
extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents:
diff
changeset
|
360 DECLARE_INLINE_HEADER ( |
cf900a2f1fa3
extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents:
diff
changeset
|
361 void |
cf900a2f1fa3
extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents:
diff
changeset
|
362 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
|
363 ) |
cf900a2f1fa3
extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents:
diff
changeset
|
364 { |
cf900a2f1fa3
extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents:
diff
changeset
|
365 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
|
366 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
|
367 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
|
368 } |
cf900a2f1fa3
extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents:
diff
changeset
|
369 |
cf900a2f1fa3
extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents:
diff
changeset
|
370 /* "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
|
371 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
|
372 |
cf900a2f1fa3
extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents:
diff
changeset
|
373 #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
|
374 |
cf900a2f1fa3
extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents:
diff
changeset
|
375 |
cf900a2f1fa3
extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents:
diff
changeset
|
376 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
|
377 |
cf900a2f1fa3
extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents:
diff
changeset
|
378 DECLARE_INLINE_HEADER ( |
cf900a2f1fa3
extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents:
diff
changeset
|
379 void |
cf900a2f1fa3
extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents:
diff
changeset
|
380 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
|
381 ) |
cf900a2f1fa3
extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents:
diff
changeset
|
382 { |
cf900a2f1fa3
extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents:
diff
changeset
|
383 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
|
384 if (size > Dynarr_max (dy)) |
cf900a2f1fa3
extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents:
diff
changeset
|
385 Dynarr_resize (dy, size); |
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 |
cf900a2f1fa3
extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents:
diff
changeset
|
388 #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
|
389 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
|
390 |
cf900a2f1fa3
extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents:
diff
changeset
|
391 /* 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
|
392 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
|
393 |
cf900a2f1fa3
extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents:
diff
changeset
|
394 DECLARE_INLINE_HEADER ( |
cf900a2f1fa3
extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents:
diff
changeset
|
395 void |
cf900a2f1fa3
extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents:
diff
changeset
|
396 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
|
397 ) |
cf900a2f1fa3
extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents:
diff
changeset
|
398 { |
cf900a2f1fa3
extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents:
diff
changeset
|
399 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
|
400 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
|
401 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
|
402 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
|
403 } |
cf900a2f1fa3
extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents:
diff
changeset
|
404 |
cf900a2f1fa3
extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents:
diff
changeset
|
405 /* 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
|
406 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
|
407 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
|
408 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
|
409 otherwise be uninitialized.) */ |
cf900a2f1fa3
extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents:
diff
changeset
|
410 |
cf900a2f1fa3
extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents:
diff
changeset
|
411 DECLARE_INLINE_HEADER ( |
cf900a2f1fa3
extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents:
diff
changeset
|
412 void |
cf900a2f1fa3
extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents:
diff
changeset
|
413 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
|
414 ) |
cf900a2f1fa3
extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents:
diff
changeset
|
415 { |
cf900a2f1fa3
extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents:
diff
changeset
|
416 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
|
417 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
|
418 if (old_len >= len) |
cf900a2f1fa3
extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents:
diff
changeset
|
419 Dynarr_set_lengthr (dy, len); |
cf900a2f1fa3
extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents:
diff
changeset
|
420 else |
cf900a2f1fa3
extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents:
diff
changeset
|
421 Dynarr_increase_length (d, len); |
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 |
cf900a2f1fa3
extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents:
diff
changeset
|
424 #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
|
425 |
cf900a2f1fa3
extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents:
diff
changeset
|
426 /* 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
|
427 |
cf900a2f1fa3
extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents:
diff
changeset
|
428 DECLARE_INLINE_HEADER ( |
cf900a2f1fa3
extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents:
diff
changeset
|
429 void |
cf900a2f1fa3
extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents:
diff
changeset
|
430 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
|
431 ) |
cf900a2f1fa3
extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents:
diff
changeset
|
432 { |
cf900a2f1fa3
extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents:
diff
changeset
|
433 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
|
434 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
|
435 len*Dynarr_elsize (dy)); |
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 |
cf900a2f1fa3
extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents:
diff
changeset
|
438 /* 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
|
439 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
|
440 length. */ |
cf900a2f1fa3
extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents:
diff
changeset
|
441 |
cf900a2f1fa3
extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents:
diff
changeset
|
442 DECLARE_INLINE_HEADER ( |
cf900a2f1fa3
extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents:
diff
changeset
|
443 void |
cf900a2f1fa3
extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents:
diff
changeset
|
444 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
|
445 ) |
cf900a2f1fa3
extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents:
diff
changeset
|
446 { |
cf900a2f1fa3
extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents:
diff
changeset
|
447 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
|
448 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
|
449 Dynarr_increase_length (dy, len); |
cf900a2f1fa3
extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents:
diff
changeset
|
450 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
|
451 } |
cf900a2f1fa3
extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents:
diff
changeset
|
452 |
cf900a2f1fa3
extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents:
diff
changeset
|
453 /* 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
|
454 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
|
455 lengths. */ |
cf900a2f1fa3
extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents:
diff
changeset
|
456 |
cf900a2f1fa3
extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents:
diff
changeset
|
457 DECLARE_INLINE_HEADER ( |
cf900a2f1fa3
extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents:
diff
changeset
|
458 void |
cf900a2f1fa3
extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents:
diff
changeset
|
459 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
|
460 ) |
cf900a2f1fa3
extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents:
diff
changeset
|
461 { |
cf900a2f1fa3
extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents:
diff
changeset
|
462 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
|
463 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
|
464 if (old_len >= len) |
cf900a2f1fa3
extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents:
diff
changeset
|
465 Dynarr_set_lengthr (dy, len); |
cf900a2f1fa3
extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents:
diff
changeset
|
466 else |
cf900a2f1fa3
extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents:
diff
changeset
|
467 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
|
468 } |
cf900a2f1fa3
extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents:
diff
changeset
|
469 |
cf900a2f1fa3
extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents:
diff
changeset
|
470 /* 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
|
471 #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
|
472 |
cf900a2f1fa3
extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents:
diff
changeset
|
473 #ifdef MEMORY_USAGE_STATS |
cf900a2f1fa3
extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents:
diff
changeset
|
474 struct usage_stats; |
cf900a2f1fa3
extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents:
diff
changeset
|
475 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
|
476 #endif |
cf900a2f1fa3
extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents:
diff
changeset
|
477 |
cf900a2f1fa3
extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents:
diff
changeset
|
478 /************* 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
|
479 |
cf900a2f1fa3
extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents:
diff
changeset
|
480 /* 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
|
481 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
|
482 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
|
483 |
cf900a2f1fa3
extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents:
diff
changeset
|
484 #ifdef NEW_GC |
cf900a2f1fa3
extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents:
diff
changeset
|
485 #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
|
486 do { \ |
cf900a2f1fa3
extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents:
diff
changeset
|
487 if ((d)->lisp_imp) \ |
cf900a2f1fa3
extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents:
diff
changeset
|
488 set_lheader_implementation \ |
cf900a2f1fa3
extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents:
diff
changeset
|
489 ((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
|
490 } while (0) |
cf900a2f1fa3
extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents:
diff
changeset
|
491 #else |
cf900a2f1fa3
extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents:
diff
changeset
|
492 #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
|
493 #endif /* (not) NEW_GC */ |
cf900a2f1fa3
extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents:
diff
changeset
|
494 |
cf900a2f1fa3
extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents:
diff
changeset
|
495 /* 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
|
496 |
cf900a2f1fa3
extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents:
diff
changeset
|
497 #define Dynarr_add(d, el) \ |
cf900a2f1fa3
extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents:
diff
changeset
|
498 do { \ |
cf900a2f1fa3
extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents:
diff
changeset
|
499 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
|
500 (void) Dynarr_verify_mod (d); \ |
cf900a2f1fa3
extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents:
diff
changeset
|
501 Dynarr_increment (d); \ |
cf900a2f1fa3
extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents:
diff
changeset
|
502 ((d)->base)[_da_pos] = (el); \ |
cf900a2f1fa3
extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents:
diff
changeset
|
503 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
|
504 } while (0) |
cf900a2f1fa3
extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents:
diff
changeset
|
505 |
cf900a2f1fa3
extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents:
diff
changeset
|
506 /* 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
|
507 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
|
508 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
|
509 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
|
510 |
cf900a2f1fa3
extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents:
diff
changeset
|
511 #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
|
512 do { \ |
cf900a2f1fa3
extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents:
diff
changeset
|
513 Elemcount _ds_pos = (pos); \ |
cf900a2f1fa3
extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents:
diff
changeset
|
514 (void) Dynarr_verify_mod (d); \ |
cf900a2f1fa3
extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents:
diff
changeset
|
515 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
|
516 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
|
517 ((d)->base)[_ds_pos] = (el); \ |
cf900a2f1fa3
extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents:
diff
changeset
|
518 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
|
519 } while (0) |
cf900a2f1fa3
extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents:
diff
changeset
|
520 |
cf900a2f1fa3
extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents:
diff
changeset
|
521 /* 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
|
522 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
|
523 |
cf900a2f1fa3
extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents:
diff
changeset
|
524 DECLARE_INLINE_HEADER ( |
cf900a2f1fa3
extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents:
diff
changeset
|
525 void |
cf900a2f1fa3
extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents:
diff
changeset
|
526 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
|
527 ) |
cf900a2f1fa3
extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents:
diff
changeset
|
528 { |
cf900a2f1fa3
extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents:
diff
changeset
|
529 /* 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
|
530 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
|
531 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
|
532 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
|
533 Elemcount pos = Dynarr_length (dy); |
cf900a2f1fa3
extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents:
diff
changeset
|
534 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
|
535 if (base) |
cf900a2f1fa3
extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents:
diff
changeset
|
536 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
|
537 len*Dynarr_elsize (dy)); |
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 |
cf900a2f1fa3
extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents:
diff
changeset
|
540 /* 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
|
541 starting at position POS. */ |
cf900a2f1fa3
extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents:
diff
changeset
|
542 |
cf900a2f1fa3
extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents:
diff
changeset
|
543 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
|
544 Elemcount pos); |
cf900a2f1fa3
extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents:
diff
changeset
|
545 |
cf900a2f1fa3
extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents:
diff
changeset
|
546 /* 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
|
547 |
cf900a2f1fa3
extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents:
diff
changeset
|
548 #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
|
549 |
cf900a2f1fa3
extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents:
diff
changeset
|
550 /* 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
|
551 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
|
552 |
cf900a2f1fa3
extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents:
diff
changeset
|
553 #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
|
554 |
cf900a2f1fa3
extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents:
diff
changeset
|
555 /* 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
|
556 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
|
557 zero byte is appended. */ |
cf900a2f1fa3
extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents:
diff
changeset
|
558 |
cf900a2f1fa3
extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents:
diff
changeset
|
559 /* #### 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
|
560 isn't declared yet. */ |
cf900a2f1fa3
extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents:
diff
changeset
|
561 |
cf900a2f1fa3
extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents:
diff
changeset
|
562 #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
|
563 do { \ |
cf900a2f1fa3
extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents:
diff
changeset
|
564 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
|
565 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
|
566 Extbyte *dyna_ls_eb; \ |
cf900a2f1fa3
extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents:
diff
changeset
|
567 Bytecount dyna_ls_bc; \ |
cf900a2f1fa3
extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents:
diff
changeset
|
568 \ |
cf900a2f1fa3
extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents:
diff
changeset
|
569 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
|
570 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
|
571 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
|
572 } while (0) |
cf900a2f1fa3
extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents:
diff
changeset
|
573 |
cf900a2f1fa3
extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents:
diff
changeset
|
574 /* 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
|
575 |
cf900a2f1fa3
extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents:
diff
changeset
|
576 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
|
577 |
cf900a2f1fa3
extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents:
diff
changeset
|
578 /* 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
|
579 |
cf900a2f1fa3
extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents:
diff
changeset
|
580 #define Dynarr_pop(d) \ |
cf900a2f1fa3
extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents:
diff
changeset
|
581 (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
|
582 Dynarr_verify_mod (d)->len_--, \ |
cf900a2f1fa3
extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents:
diff
changeset
|
583 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
|
584 |
cf900a2f1fa3
extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents:
diff
changeset
|
585 /* Delete the item at POS */ |
cf900a2f1fa3
extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents:
diff
changeset
|
586 |
cf900a2f1fa3
extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents:
diff
changeset
|
587 #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
|
588 |
cf900a2f1fa3
extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents:
diff
changeset
|
589 /* 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
|
590 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
|
591 #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
|
592 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
|
593 |
cf900a2f1fa3
extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents:
diff
changeset
|
594 /* 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
|
595 |
cf900a2f1fa3
extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents:
diff
changeset
|
596 #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
|
597 do \ |
cf900a2f1fa3
extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents:
diff
changeset
|
598 { \ |
cf900a2f1fa3
extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents:
diff
changeset
|
599 REGISTER int i; \ |
cf900a2f1fa3
extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents:
diff
changeset
|
600 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
|
601 { \ |
cf900a2f1fa3
extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents:
diff
changeset
|
602 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
|
603 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
|
604 } \ |
cf900a2f1fa3
extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents:
diff
changeset
|
605 } while (0) |
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 /************************************************************************/ |
cf900a2f1fa3
extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents:
diff
changeset
|
609 /** Stack-like malloc/free **/ |
cf900a2f1fa3
extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents:
diff
changeset
|
610 /************************************************************************/ |
cf900a2f1fa3
extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents:
diff
changeset
|
611 |
5729
f7abcda06b1b
Since stack_like_{malloc,free}() are only used when WIN32_ANY,
Jerry James <james@xemacs.org>
parents:
5402
diff
changeset
|
612 #ifdef WIN32_ANY |
5168
cf900a2f1fa3
extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents:
diff
changeset
|
613 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
|
614 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
|
615 #endif |
5168
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 /************************************************************************/ |
cf900a2f1fa3
extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents:
diff
changeset
|
619 /** Gap array **/ |
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 |
cf900a2f1fa3
extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents:
diff
changeset
|
622 /* 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
|
623 deleted, similar to standard markers. */ |
cf900a2f1fa3
extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents:
diff
changeset
|
624 |
cf900a2f1fa3
extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents:
diff
changeset
|
625 typedef struct gap_array_marker |
cf900a2f1fa3
extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents:
diff
changeset
|
626 { |
cf900a2f1fa3
extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents:
diff
changeset
|
627 #ifdef NEW_GC |
cf900a2f1fa3
extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents:
diff
changeset
|
628 NORMAL_LISP_OBJECT_HEADER header; |
cf900a2f1fa3
extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents:
diff
changeset
|
629 #endif /* NEW_GC */ |
cf900a2f1fa3
extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents:
diff
changeset
|
630 int pos; |
cf900a2f1fa3
extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents:
diff
changeset
|
631 struct gap_array_marker *next; |
cf900a2f1fa3
extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents:
diff
changeset
|
632 } Gap_Array_Marker; |
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 |
cf900a2f1fa3
extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents:
diff
changeset
|
635 /* 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
|
636 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
|
637 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
|
638 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
|
639 the gap. */ |
cf900a2f1fa3
extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents:
diff
changeset
|
640 |
cf900a2f1fa3
extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents:
diff
changeset
|
641 /* Layout of gap array: |
cf900a2f1fa3
extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents:
diff
changeset
|
642 |
cf900a2f1fa3
extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents:
diff
changeset
|
643 <------ gap ------><---- gapsize ----><----- numels - gap ----> |
cf900a2f1fa3
extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents:
diff
changeset
|
644 <---------------------- numels + gapsize ---------------------> |
cf900a2f1fa3
extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents:
diff
changeset
|
645 |
cf900a2f1fa3
extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents:
diff
changeset
|
646 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
|
647 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
|
648 of elements in that data: |
cf900a2f1fa3
extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents:
diff
changeset
|
649 |
cf900a2f1fa3
extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents:
diff
changeset
|
650 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
|
651 els_past_gap = numels - gap |
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 |
cf900a2f1fa3
extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents:
diff
changeset
|
655 typedef struct gap_array |
cf900a2f1fa3
extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents:
diff
changeset
|
656 { |
cf900a2f1fa3
extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents:
diff
changeset
|
657 #ifdef NEW_GC |
cf900a2f1fa3
extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents:
diff
changeset
|
658 NORMAL_LISP_OBJECT_HEADER header; |
cf900a2f1fa3
extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents:
diff
changeset
|
659 int is_lisp; |
cf900a2f1fa3
extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents:
diff
changeset
|
660 #endif /* NEW_GC */ |
cf900a2f1fa3
extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents:
diff
changeset
|
661 Elemcount gap; |
cf900a2f1fa3
extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents:
diff
changeset
|
662 Elemcount gapsize; |
cf900a2f1fa3
extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents:
diff
changeset
|
663 Elemcount numels; |
cf900a2f1fa3
extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents:
diff
changeset
|
664 Bytecount elsize; |
cf900a2f1fa3
extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents:
diff
changeset
|
665 /* 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
|
666 Bytecount offset_past_gap; |
cf900a2f1fa3
extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents:
diff
changeset
|
667 Elemcount els_past_gap; |
cf900a2f1fa3
extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents:
diff
changeset
|
668 Gap_Array_Marker *markers; |
cf900a2f1fa3
extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents:
diff
changeset
|
669 /* this is a stretchy array */ |
cf900a2f1fa3
extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents:
diff
changeset
|
670 char array[1]; |
cf900a2f1fa3
extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents:
diff
changeset
|
671 } Gap_Array; |
cf900a2f1fa3
extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents:
diff
changeset
|
672 |
cf900a2f1fa3
extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents:
diff
changeset
|
673 #ifdef NEW_GC |
cf900a2f1fa3
extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents:
diff
changeset
|
674 struct gap_array_marker; |
cf900a2f1fa3
extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents:
diff
changeset
|
675 |
cf900a2f1fa3
extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents:
diff
changeset
|
676 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
|
677 #define XGAP_ARRAY_MARKER(x) \ |
cf900a2f1fa3
extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents:
diff
changeset
|
678 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
|
679 #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
|
680 #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
|
681 #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
|
682 #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
|
683 |
cf900a2f1fa3
extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents:
diff
changeset
|
684 struct gap_array; |
cf900a2f1fa3
extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents:
diff
changeset
|
685 |
cf900a2f1fa3
extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents:
diff
changeset
|
686 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
|
687 #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
|
688 #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
|
689 #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
|
690 #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
|
691 #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
|
692 #endif /* NEW_GC */ |
cf900a2f1fa3
extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents:
diff
changeset
|
693 |
cf900a2f1fa3
extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents:
diff
changeset
|
694 #ifdef NEW_GC |
cf900a2f1fa3
extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents:
diff
changeset
|
695 #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
|
696 { 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
|
697 #else /* not NEW_GC */ |
cf900a2f1fa3
extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents:
diff
changeset
|
698 #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
|
699 { 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
|
700 { &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
|
701 #endif /* not NEW_GC */ |
cf900a2f1fa3
extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents:
diff
changeset
|
702 |
cf900a2f1fa3
extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents:
diff
changeset
|
703 #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
|
704 { 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
|
705 { 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
|
706 { 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
|
707 XD_GAP_ARRAY_MARKER_DESC, \ |
cf900a2f1fa3
extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents:
diff
changeset
|
708 { 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
|
709 { sub_desc } }, \ |
cf900a2f1fa3
extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents:
diff
changeset
|
710 { 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
|
711 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
|
712 |
cf900a2f1fa3
extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents:
diff
changeset
|
713 /* 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
|
714 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
|
715 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
|
716 "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
|
717 #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
|
718 |
cf900a2f1fa3
extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents:
diff
changeset
|
719 /* 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
|
720 #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
|
721 |
cf900a2f1fa3
extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents:
diff
changeset
|
722 #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
|
723 #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
|
724 |
cf900a2f1fa3
extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents:
diff
changeset
|
725 #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
|
726 ((pos) < gappos ? (pos) : (pos) + gapsize) |
cf900a2f1fa3
extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents:
diff
changeset
|
727 |
cf900a2f1fa3
extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents:
diff
changeset
|
728 #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
|
729 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
|
730 |
cf900a2f1fa3
extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents:
diff
changeset
|
731 #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
|
732 ((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
|
733 |
cf900a2f1fa3
extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents:
diff
changeset
|
734 /* 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
|
735 #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
|
736 ((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
|
737 |
cf900a2f1fa3
extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents:
diff
changeset
|
738 /* 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
|
739 #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
|
740 |
cf900a2f1fa3
extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents:
diff
changeset
|
741 /* 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
|
742 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
|
743 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
|
744 #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
|
745 |
cf900a2f1fa3
extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents:
diff
changeset
|
746 #ifndef NEW_GC |
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 lispobj_gap_array_description; |
cf900a2f1fa3
extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents:
diff
changeset
|
748 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
|
749 #endif |
cf900a2f1fa3
extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents:
diff
changeset
|
750 |
cf900a2f1fa3
extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents:
diff
changeset
|
751 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
|
752 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
|
753 Elemcount numels); |
cf900a2f1fa3
extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents:
diff
changeset
|
754 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
|
755 #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
|
756 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
|
757 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
|
758 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
|
759 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
|
760 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
|
761 #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
|
762 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
|
763 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
|
764 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
|
765 void free_gap_array (Gap_Array *ga); |
5170
5ddbab03b0e6
various fixes to memory-usage stats
Ben Wing <ben@xemacs.org>
parents:
5169
diff
changeset
|
766 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
|
767 Bytecount *marker_ancillary); |
5168
cf900a2f1fa3
extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents:
diff
changeset
|
768 |
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
|
769 #endif /* INCLUDED_array_h_ */ |