Mercurial > hg > xemacs-beta
annotate src/dynarr.c @ 4953:304aebb79cd3
function renamings to track names of char typedefs
-------------------- ChangeLog entries follow: --------------------
man/ChangeLog addition:
2010-01-27 Ben Wing <ben@xemacs.org>
* internals/internals.texi (lrecords):
* internals/internals.texi (The DFC API):
* internals/internals.texi (Conversion to and from External Data):
* internals/internals.texi (Mule-izing Code):
* internals/internals.texi (Pervasive changes throughout XEmacs sources):
* internals/internals.texi (Ben's README):
* internals/internals.texi (Future Work -- Localized Text/Messages):
* emodules.texi (Defining Variables):
Rename:
write_c_string -> write_cistring
build_intstring -> build_istring
build_string -> build_cistring
build_ext_string -> build_extstring
make_ext_string -> make_extstring
buffer_insert_c_string -> buffer_insert_ascstring
intern_int -> intern_istring
See comment in src/ChangeLog about this.
modules/ChangeLog addition:
2010-01-27 Ben Wing <ben@xemacs.org>
* postgresql/postgresql.c (print_pgconn):
* postgresql/postgresql.c (print_pgresult):
* postgresql/postgresql.c (Fpq_conn_defaults):
* postgresql/postgresql.c (Fpq_pgconn):
* postgresql/postgresql.c (Fpq_res_status):
* postgresql/postgresql.c (Fpq_result_error_message):
* postgresql/postgresql.c (Fpq_fname):
* postgresql/postgresql.c (Fpq_get_value):
* postgresql/postgresql.c (Fpq_cmd_status):
* postgresql/postgresql.c (Fpq_cmd_tuples):
* postgresql/postgresql.c (Fpq_notifies):
* postgresql/postgresql.c (Fpq_get_line):
* postgresql/postgresql.c (Fpq_get_line_async):
* postgresql/postgresql.c (FROB):
* postgresql/postgresql.c (init_postgresql_from_environment):
* ldap/eldap.c:
* ldap/eldap.c (Fldap_open):
* ldap/eldap.c (Fldap_search_basic):
* canna/canna_api.c:
* canna/canna_api.c (make_euc_string):
Rename:
write_c_string -> write_cistring
build_intstring -> build_istring
build_string -> build_cistring
build_ext_string -> build_extstring
make_ext_string -> make_extstring
buffer_insert_c_string -> buffer_insert_ascstring
intern_int -> intern_istring
See comment in src/ChangeLog about this.
src/ChangeLog addition:
2010-01-27 Ben Wing <ben@xemacs.org>
* .gdbinit.in.in:
* README:
* abbrev.c (write_abbrev):
* abbrev.c (describe_abbrev):
* alloc.c (make_extstring):
* alloc.c (build_istring):
* alloc.c (build_cistring):
* alloc.c (build_ascstring):
* alloc.c (build_extstring):
* alloc.c (build_msg_istring):
* alloc.c (build_defer_istring):
* buffer.c (Fgenerate_new_buffer_name):
* buffer.c (init_buffer_2):
* console-tty.c (tty_init_console):
* console-x.c (get_display_arg_connection):
* console-x.c (x_perhaps_init_unseen_key_defaults):
* database.c (dbm_map):
* database.c (dbm_get):
* database.c (berkdb_get):
* database.c (berkdb_map):
* device-gtk.c (FROB_PIXMAP):
* device-gtk.c (Fgtk_style_info):
* device-msw.c (msprinter_default_printer):
* device-msw.c (sync_printer_with_devmode):
* device-x.c (coding_system_of_xrm_database):
* device-x.c (x_init_device):
* device-x.c (signal_if_x_error):
* device-x.c (Fx_get_resource):
* device-x.c (Fx_server_vendor):
* device-x.c (Fx_get_font_path):
* dialog-x.c (maybe_run_dbox_text_callback):
* doc.c (extract_object_file_name):
* doc.c (unparesseuxify_doc_string):
* doc.c (get_doc_string):
* doc.c (get_object_file_name):
* doc.c (Fdocumentation):
* doc.c (Fsnarf_documentation):
* doc.c (Fsubstitute_command_keys):
* editfns.c (init_editfns):
* editfns.c (Ftemp_directory):
* editfns.c (Fuser_login_name):
* editfns.c (Fuser_real_login_name):
* editfns.c (Fuser_home_directory):
* editfns.c (Fformat_time_string):
* editfns.c (Fcurrent_time_string):
* editfns.c (Fcurrent_time_zone):
* emacs.c:
* emacs.c (main_1):
* emodules.c (Flist_modules):
* emodules.c (emodules_load):
* emodules.c (emodules_doc_sym):
* emodules.c (vars_of_module):
* event-Xt.c (x_has_keysym):
* event-gtk.c (emacs_gtk_format_magic_event):
* event-gtk.c (dragndrop_data_received):
* event-gtk.c (gtk_reset_key_mapping):
* event-msw.c (mswindows_dde_callback):
* event-msw.c (mswindows_wnd_proc):
* faces.c (complex_vars_of_faces):
* file-coding.c (find_coding_system):
* file-coding.c (setup_eol_coding_systems):
* file-coding.c (make_coding_system_1):
* file-coding.c (snarf_coding_system):
* fileio.c:
* fileio.c (lisp_strerror):
* fileio.c (Ffile_name_directory):
* fileio.c (Ffile_name_as_directory):
* fileio.c (Fdirectory_file_name):
* fileio.c (if):
* fileio.c (Ffile_symlink_p):
* fileio.c (Fencrypt_string):
* fileio.c (Fdecrypt_string):
* filelock.c (lock_file):
* filelock.c (Ffile_locked_p):
* floatfns.c (matherr):
* font-mgr.c (build_fcapi_string):
* font-mgr.c (make_xlfd_font_regexp):
* frame-msw.c (mswindows_window_id):
* frame-msw.c (mswindows_frame_property):
* frame-x.c:
* frame-x.c (color_to_string):
* frame-x.c (maybe_set_frame_title_format):
* frame-x.c (x_cde_transfer_callback):
* frame-x.c (Fx_window_id):
* glade.c (connector):
* glade.c (Fglade_xml_textdomain):
* glade.c (syms_of_glade):
* glyphs-eimage.c (jpeg_instantiate):
* glyphs-eimage.c (png_instantiate):
* glyphs-eimage.c (tiff_instantiate):
* glyphs-gtk.c (font_instantiate):
* glyphs-gtk.c (BUILD_GLYPH_INST):
* glyphs-x.c (x_locate_pixmap_file):
* glyphs-x.c (font_instantiate):
* glyphs-x.c (x_widget_property):
* glyphs-x.c (BUILD_GLYPH_INST):
* glyphs.c (print_image_instance):
* glyphs.c (bitmap_to_lisp_data):
* glyphs.c (pixmap_to_lisp_data):
* gpmevent.c (turn_off_gpm):
* gpmevent.c (Fgpm_enabled_p):
* gpmevent.c (Fgpm_enable):
* gtk-glue.c (__make_string_mapper):
* gtk-glue.c (xemacs_gtklist_to_list):
* gtk-xemacs.c (FROB_FACE):
* gtk-xemacs.c (xemacs_gtk_convert_color):
* hpplay.c (player_error_internal):
* hpplay.c (myHandler):
* insdel.c (buffer_insert_ascstring_1):
* insdel.h:
* insdel.h (buffer_insert_ascstring):
* intl.c (Fcurrent_locale):
* intl.c (Fset_current_locale):
* keymap.c (make_key_description):
* keymap.c (Ftext_char_description):
* keymap.c (describe_command):
* keymap.c (describe_map):
* lisp.h:
* lread.c:
* lread.c (locate_file_in_directory_mapper):
* lread.c (locate_file_construct_suffixed_files_mapper):
* mule-charset.c (Fmake_charset):
* nt.c (Fmswindows_short_file_name):
* nt.c (Fmswindows_long_file_name):
* objects-gtk.c (__get_gtk_font_truename):
* objects-gtk.c (__gtk_font_list_internal):
* objects-msw.c (font_enum_callback_2):
* objects-msw.c (create_hfont_from_font_spec):
* objects-msw.c (mswindows_font_list):
* objects-msw.c (mswindows_font_spec_matches_charset_stage_2):
* objects-tty.c (tty_initialize_font_instance):
* objects-x.c (x_font_truename):
* objects-x.c (x_font_instance_truename):
* objects-x.c (x_font_instance_properties):
* objects-x.c (x_font_list):
* print.c (write_cistring):
* print.c (print_vector_internal):
* print.c (print_cons):
* process-nt.c (nt_canonicalize_host_name):
* process-unix.c (unix_create_process):
* process-unix.c (unix_canonicalize_host_name):
* process.c (status_message):
* process.c (status_notify):
* process.c (init_xemacs_process):
* process.c (syms_of_process):
* redisplay-tty.c (term_get_fkeys_1):
* redisplay-tty.c (CONDITIONAL_REASSIGN):
* search.c (compile_pattern_1):
* select-common.h (selection_data_to_lisp_data):
* select-gtk.c (atom_to_symbol):
* select-gtk.c (PROCESSING_GTK_CODE):
* select-msw.c (mswindows_get_foreign_selection):
* select-x.c (x_atom_to_symbol):
* select-x.c (Fx_get_cutbuffer_internal):
* symbols.c (intern_istring):
* symbols.c (intern):
* symbols.c (intern_converting_underscores_to_dashes):
* symbols.c (Fintern):
* sysdep.c (init_system_name):
* sysdll.c (dll_error):
* sysdll.c (dll_open):
* syswindows.h:
* syswindows.h (build_tstr_string):
* tests.c (DFC_CHECK_LENGTH):
* tests.c (DFC_CHECK_CONTENT):
* tests.c (DFC_RESULT_PASS):
* tests.c (Ftest_data_format_conversion):
* text.c:
* text.c (new_dfc_convert_now_damn_it):
* text.h:
* text.h (build_wext_string):
* tooltalk.c (tt_build_c_string):
* tooltalk.c (Ftooltalk_default_procid):
* tooltalk.c (Ftooltalk_default_session):
* tooltalk.c (init_tooltalk):
* ui-byhand.c (Fgtk_clist_get_text):
* ui-byhand.c (Fgtk_clist_get_pixtext):
* ui-byhand.c (Fgtk_label_get):
* ui-byhand.c (Fgtk_notebook_query_tab_label_packing):
* ui-gtk.c (emacs_gtk_object_printer):
* ui-gtk.c (emacs_gtk_boxed_printer):
* ui-gtk.c (gtk_type_to_lisp):
* ui-gtk.c (symbol_to_enum):
* ui-gtk.c (enum_to_symbol):
* unexaix.c (report_error):
* unexaix.c (ERROR0):
* unexec.c (report_error):
* unexec.c (ERROR0):
* unicode.c (unicode_to_ichar):
* win32.c (tstr_to_local_file_format):
* win32.c (Fmswindows_cygwin_to_win32_path):
* win32.c (struct read_link_hash):
* xemacs.def.in.in:
Rename:
write_c_string -> write_cistring
build_intstring -> build_istring
build_string -> build_cistring
build_ext_string -> build_extstring
make_ext_string -> make_extstring
buffer_insert_c_string -> buffer_insert_ascstring
intern_int -> intern_istring
These functions have been renamed so that the naming harmonizes
with the typedefs for strings: `cistring' along with CIbyte *,
`istring' along with Ibyte *, `extstring' along with Extbyte *,
`ascstring' along with Ascbyte *.
Also make buffer_insert_ascstring take Ascbyte * and assert
that its argument is ASCII.
author | Ben Wing <ben@xemacs.org> |
---|---|
date | Wed, 27 Jan 2010 00:35:36 -0600 |
parents | 19a72041c5ed |
children | 0d4c9d0f6a8d |
rev | line source |
---|---|
1318 | 1 /* Support for dynamic arrays. |
428 | 2 Copyright (C) 1993 Sun Microsystems, Inc. |
4952
19a72041c5ed
Mule-izing, various fixes related to char * arguments
Ben Wing <ben@xemacs.org>
parents:
4844
diff
changeset
|
3 Copyright (C) 2002, 2003, 2004, 2005, 2010 Ben Wing. |
428 | 4 |
5 This file is part of XEmacs. | |
6 | |
7 XEmacs is free software; you can redistribute it and/or modify it | |
8 under the terms of the GNU General Public License as published by the | |
9 Free Software Foundation; either version 2, or (at your option) any | |
10 later version. | |
11 | |
12 XEmacs is distributed in the hope that it will be useful, but WITHOUT | |
13 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or | |
14 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License | |
15 for more details. | |
16 | |
17 You should have received a copy of the GNU General Public License | |
18 along with XEmacs; see the file COPYING. If not, write to | |
19 the Free Software Foundation, Inc., 59 Temple Place - Suite 330, | |
20 Boston, MA 02111-1307, USA. */ | |
21 | |
22 /* Synched up with: Not in FSF. */ | |
23 | |
24 /* Written by Ben Wing, December 1993. */ | |
25 | |
26 /* | |
27 | |
28 A "dynamic array" is a contiguous array of fixed-size elements where there | |
29 is no upper limit (except available memory) on the number of elements in the | |
30 array. Because the elements are maintained contiguously, space is used | |
31 efficiently (no per-element pointers necessary) and random access to a | |
32 particular element is in constant time. At any one point, the block of memory | |
33 that holds the array has an upper limit; if this limit is exceeded, the | |
34 memory is realloc()ed into a new array that is twice as big. Assuming that | |
35 the time to grow the array is on the order of the new size of the array | |
36 block, this scheme has a provably constant amortized time (i.e. average | |
37 time over all additions). | |
38 | |
39 When you add elements or retrieve elements, pointers are used. Note that | |
40 the element itself (of whatever size it is), and not the pointer to it, | |
41 is stored in the array; thus you do not have to allocate any heap memory | |
42 on your own. Also, returned pointers are only guaranteed to be valid | |
43 until the next operation that changes the length of the array. | |
44 | |
45 This is a container object. Declare a dynamic array of a specific type | |
46 as follows: | |
47 | |
2367 | 48 typedef struct |
49 { | |
50 Dynarr_declare (mytype); | |
51 } mytype_dynarr; | |
428 | 52 |
53 Use the following functions/macros: | |
54 | |
55 void *Dynarr_new(type) | |
56 [MACRO] Create a new dynamic-array object, with each element of the | |
57 specified type. The return value is cast to (type##_dynarr). | |
58 This requires following the convention that types are declared in | |
59 such a way that this type concatenation works. In particular, TYPE | |
60 must be a symbol, not an arbitrary C type. | |
61 | |
62 Dynarr_add(d, el) | |
63 [MACRO] Add an element to the end of a dynamic array. EL is a pointer | |
64 to the element; the element itself is stored in the array, however. | |
65 No function call is performed unless the array needs to be resized. | |
66 | |
67 Dynarr_add_many(d, base, len) | |
68 [MACRO] Add LEN elements to the end of the dynamic array. The elements | |
771 | 69 should be contiguous in memory, starting at BASE. If BASE if NULL, |
70 just make space for the elements; don't actually add them. | |
428 | 71 |
72 Dynarr_insert_many_at_start(d, base, len) | |
73 [MACRO] Append LEN elements to the beginning of the dynamic array. | |
74 The elements should be contiguous in memory, starting at BASE. | |
771 | 75 If BASE if NULL, just make space for the elements; don't actually |
76 add them. | |
428 | 77 |
78 Dynarr_insert_many(d, base, len, start) | |
79 Insert LEN elements to the dynamic array starting at position | |
80 START. The elements should be contiguous in memory, starting at BASE. | |
771 | 81 If BASE if NULL, just make space for the elements; don't actually |
82 add them. | |
83 | |
84 Dynarr_delete(d, i) | |
85 [MACRO] Delete an element from the dynamic array at position I. | |
86 | |
87 Dynarr_delete_many(d, start, len) | |
88 Delete LEN elements from the dynamic array starting at position | |
89 START. | |
90 | |
91 Dynarr_delete_by_pointer(d, p) | |
92 [MACRO] Delete an element from the dynamic array at pointer P, | |
93 which must point within the block of memory that stores the data. | |
94 P should be obtained using Dynarr_atp(). | |
428 | 95 |
96 int Dynarr_length(d) | |
97 [MACRO] Return the number of elements currently in a dynamic array. | |
98 | |
99 int Dynarr_largest(d) | |
100 [MACRO] Return the maximum value that Dynarr_length(d) would | |
4844
91b3d00e717f
Various cleanups for Dynarr code, from Unicode-internal ws
Ben Wing <ben@xemacs.org>
parents:
4117
diff
changeset
|
101 ever have returned. This is used esp. in the redisplay code, |
91b3d00e717f
Various cleanups for Dynarr code, from Unicode-internal ws
Ben Wing <ben@xemacs.org>
parents:
4117
diff
changeset
|
102 which reuses dynarrs for performance reasons. |
428 | 103 |
104 type Dynarr_at(d, i) | |
105 [MACRO] Return the element at the specified index (no bounds checking | |
106 done on the index). The element itself is returned, not a pointer | |
107 to it. | |
108 | |
109 type *Dynarr_atp(d, i) | |
110 [MACRO] Return a pointer to the element at the specified index (no | |
111 bounds checking done on the index). The pointer may not be valid | |
112 after an element is added to or removed from the array. | |
113 | |
114 Dynarr_reset(d) | |
115 [MACRO] Reset the length of a dynamic array to 0. | |
116 | |
117 Dynarr_free(d) | |
118 Destroy a dynamic array and the memory allocated to it. | |
119 | |
120 Use the following global variable: | |
121 | |
122 Dynarr_min_size | |
440 | 123 Minimum allowable size for a dynamic array when it is resized. |
428 | 124 |
125 */ | |
126 | |
127 #include <config.h> | |
128 #include "lisp.h" | |
129 | |
4952
19a72041c5ed
Mule-izing, various fixes related to char * arguments
Ben Wing <ben@xemacs.org>
parents:
4844
diff
changeset
|
130 static const struct memory_description const_Ascbyte_ptr_description_1[] = { |
19a72041c5ed
Mule-izing, various fixes related to char * arguments
Ben Wing <ben@xemacs.org>
parents:
4844
diff
changeset
|
131 { XD_ASCII_STRING, 0 }, |
19a72041c5ed
Mule-izing, various fixes related to char * arguments
Ben Wing <ben@xemacs.org>
parents:
4844
diff
changeset
|
132 { XD_END } |
19a72041c5ed
Mule-izing, various fixes related to char * arguments
Ben Wing <ben@xemacs.org>
parents:
4844
diff
changeset
|
133 }; |
19a72041c5ed
Mule-izing, various fixes related to char * arguments
Ben Wing <ben@xemacs.org>
parents:
4844
diff
changeset
|
134 |
19a72041c5ed
Mule-izing, various fixes related to char * arguments
Ben Wing <ben@xemacs.org>
parents:
4844
diff
changeset
|
135 const struct sized_memory_description const_Ascbyte_ptr_description = { |
19a72041c5ed
Mule-izing, various fixes related to char * arguments
Ben Wing <ben@xemacs.org>
parents:
4844
diff
changeset
|
136 sizeof (const Ascbyte *), |
19a72041c5ed
Mule-izing, various fixes related to char * arguments
Ben Wing <ben@xemacs.org>
parents:
4844
diff
changeset
|
137 const_Ascbyte_ptr_description_1 |
19a72041c5ed
Mule-izing, various fixes related to char * arguments
Ben Wing <ben@xemacs.org>
parents:
4844
diff
changeset
|
138 }; |
19a72041c5ed
Mule-izing, various fixes related to char * arguments
Ben Wing <ben@xemacs.org>
parents:
4844
diff
changeset
|
139 |
19a72041c5ed
Mule-izing, various fixes related to char * arguments
Ben Wing <ben@xemacs.org>
parents:
4844
diff
changeset
|
140 static const struct memory_description const_Ascbyte_ptr_dynarr_description_1[] = { |
19a72041c5ed
Mule-izing, various fixes related to char * arguments
Ben Wing <ben@xemacs.org>
parents:
4844
diff
changeset
|
141 XD_DYNARR_DESC (const_Ascbyte_ptr_dynarr, &const_Ascbyte_ptr_description), |
19a72041c5ed
Mule-izing, various fixes related to char * arguments
Ben Wing <ben@xemacs.org>
parents:
4844
diff
changeset
|
142 { XD_END } |
19a72041c5ed
Mule-izing, various fixes related to char * arguments
Ben Wing <ben@xemacs.org>
parents:
4844
diff
changeset
|
143 }; |
19a72041c5ed
Mule-izing, various fixes related to char * arguments
Ben Wing <ben@xemacs.org>
parents:
4844
diff
changeset
|
144 |
19a72041c5ed
Mule-izing, various fixes related to char * arguments
Ben Wing <ben@xemacs.org>
parents:
4844
diff
changeset
|
145 const struct sized_memory_description const_Ascbyte_ptr_dynarr_description = { |
19a72041c5ed
Mule-izing, various fixes related to char * arguments
Ben Wing <ben@xemacs.org>
parents:
4844
diff
changeset
|
146 sizeof (const_Ascbyte_ptr_dynarr), |
19a72041c5ed
Mule-izing, various fixes related to char * arguments
Ben Wing <ben@xemacs.org>
parents:
4844
diff
changeset
|
147 const_Ascbyte_ptr_dynarr_description_1 |
19a72041c5ed
Mule-izing, various fixes related to char * arguments
Ben Wing <ben@xemacs.org>
parents:
4844
diff
changeset
|
148 }; |
19a72041c5ed
Mule-izing, various fixes related to char * arguments
Ben Wing <ben@xemacs.org>
parents:
4844
diff
changeset
|
149 |
19a72041c5ed
Mule-izing, various fixes related to char * arguments
Ben Wing <ben@xemacs.org>
parents:
4844
diff
changeset
|
150 |
440 | 151 static int Dynarr_min_size = 8; |
428 | 152 |
153 static void | |
3210 | 154 Dynarr_realloc (Dynarr *dy, int new_size) |
428 | 155 { |
156 if (DUMPEDP (dy->base)) | |
157 { | |
3293 | 158 void *new_base = malloc (new_size * dy->elsize); |
3210 | 159 memcpy (new_base, dy->base, |
160 (dy->max < new_size ? dy->max : new_size) * dy->elsize); | |
428 | 161 dy->base = new_base; |
162 } | |
163 else | |
3210 | 164 dy->base = xrealloc (dy->base, new_size * dy->elsize); |
428 | 165 } |
166 | |
167 void * | |
168 Dynarr_newf (int elsize) | |
169 { | |
170 Dynarr *d = xnew_and_zero (Dynarr); | |
171 d->elsize = elsize; | |
172 | |
173 return d; | |
174 } | |
175 | |
3092 | 176 #ifdef NEW_GC |
177 DEFINE_LRECORD_IMPLEMENTATION ("dynarr", dynarr, | |
178 1, /*dumpable-flag*/ | |
179 0, 0, 0, 0, 0, | |
180 0, | |
181 Dynarr); | |
182 | |
183 static void | |
3210 | 184 Dynarr_lisp_realloc (Dynarr *dy, int new_size) |
3092 | 185 { |
186 void *new_base = alloc_lrecord_array (dy->elsize, new_size, dy->lisp_imp); | |
187 if (dy->base) | |
188 memcpy (new_base, dy->base, | |
3210 | 189 (dy->max < new_size ? dy->max : new_size) * dy->elsize); |
3092 | 190 dy->base = new_base; |
191 } | |
192 | |
193 void * | |
194 Dynarr_lisp_newf (int elsize, | |
195 const struct lrecord_implementation *dynarr_imp, | |
196 const struct lrecord_implementation *imp) | |
197 { | |
198 Dynarr *d = (Dynarr *) alloc_lrecord (sizeof (Dynarr), dynarr_imp); | |
199 d->elsize = elsize; | |
200 d->lisp_imp = imp; | |
201 | |
202 return d; | |
203 } | |
204 #endif /* not NEW_GC */ | |
205 | |
428 | 206 void |
2367 | 207 Dynarr_resize (void *d, Elemcount size) |
428 | 208 { |
209 int newsize; | |
210 double multiplier; | |
1318 | 211 Dynarr *dy = (Dynarr *) Dynarr_verify (d); |
428 | 212 |
213 if (dy->max <= 8) | |
214 multiplier = 2; | |
215 else | |
216 multiplier = 1.5; | |
217 | |
218 for (newsize = dy->max; newsize < size;) | |
219 newsize = max (Dynarr_min_size, (int) (multiplier * newsize)); | |
220 | |
221 /* Don't do anything if the array is already big enough. */ | |
222 if (newsize > dy->max) | |
223 { | |
3092 | 224 #ifdef NEW_GC |
225 if (dy->lisp_imp) | |
226 Dynarr_lisp_realloc (dy, newsize); | |
227 else | |
3210 | 228 Dynarr_realloc (dy, newsize); |
3092 | 229 #else /* not NEW_GC */ |
3210 | 230 Dynarr_realloc (dy, newsize); |
3092 | 231 #endif /* not NEW_GC */ |
428 | 232 dy->max = newsize; |
233 } | |
234 } | |
235 | |
236 /* Add a number of contiguous elements to the array starting at START. */ | |
237 void | |
442 | 238 Dynarr_insert_many (void *d, const void *el, int len, int start) |
428 | 239 { |
793 | 240 Dynarr *dy = (Dynarr *) Dynarr_verify (d); |
241 | |
4844
91b3d00e717f
Various cleanups for Dynarr code, from Unicode-internal ws
Ben Wing <ben@xemacs.org>
parents:
4117
diff
changeset
|
242 if (dy->len + len > dy->max) |
91b3d00e717f
Various cleanups for Dynarr code, from Unicode-internal ws
Ben Wing <ben@xemacs.org>
parents:
4117
diff
changeset
|
243 Dynarr_resize (dy, dy->len + len); |
1318 | 244 #if 0 |
245 /* WTF? We should be catching these problems. */ | |
428 | 246 /* Silently adjust start to be valid. */ |
4844
91b3d00e717f
Various cleanups for Dynarr code, from Unicode-internal ws
Ben Wing <ben@xemacs.org>
parents:
4117
diff
changeset
|
247 if (start > dy->len) |
91b3d00e717f
Various cleanups for Dynarr code, from Unicode-internal ws
Ben Wing <ben@xemacs.org>
parents:
4117
diff
changeset
|
248 start = dy->len; |
428 | 249 else if (start < 0) |
250 start = 0; | |
1318 | 251 #else |
4844
91b3d00e717f
Various cleanups for Dynarr code, from Unicode-internal ws
Ben Wing <ben@xemacs.org>
parents:
4117
diff
changeset
|
252 /* #### This could conceivably be wrong, if code wants to access stuff |
91b3d00e717f
Various cleanups for Dynarr code, from Unicode-internal ws
Ben Wing <ben@xemacs.org>
parents:
4117
diff
changeset
|
253 between len and largest. */ |
91b3d00e717f
Various cleanups for Dynarr code, from Unicode-internal ws
Ben Wing <ben@xemacs.org>
parents:
4117
diff
changeset
|
254 type_checking_assert (start >= 0 && start <= dy->len); |
1318 | 255 #endif |
428 | 256 |
4844
91b3d00e717f
Various cleanups for Dynarr code, from Unicode-internal ws
Ben Wing <ben@xemacs.org>
parents:
4117
diff
changeset
|
257 if (start != dy->len) |
428 | 258 { |
259 memmove ((char *) dy->base + (start + len)*dy->elsize, | |
260 (char *) dy->base + start*dy->elsize, | |
4844
91b3d00e717f
Various cleanups for Dynarr code, from Unicode-internal ws
Ben Wing <ben@xemacs.org>
parents:
4117
diff
changeset
|
261 (dy->len - start)*dy->elsize); |
428 | 262 } |
771 | 263 if (el) |
264 memcpy ((char *) dy->base + start*dy->elsize, el, len*dy->elsize); | |
4844
91b3d00e717f
Various cleanups for Dynarr code, from Unicode-internal ws
Ben Wing <ben@xemacs.org>
parents:
4117
diff
changeset
|
265 dy->len += len; |
428 | 266 |
4844
91b3d00e717f
Various cleanups for Dynarr code, from Unicode-internal ws
Ben Wing <ben@xemacs.org>
parents:
4117
diff
changeset
|
267 if (dy->len > dy->largest) |
91b3d00e717f
Various cleanups for Dynarr code, from Unicode-internal ws
Ben Wing <ben@xemacs.org>
parents:
4117
diff
changeset
|
268 dy->largest = dy->len; |
428 | 269 } |
270 | |
271 void | |
272 Dynarr_delete_many (void *d, int start, int len) | |
273 { | |
1318 | 274 Dynarr *dy = (Dynarr *) Dynarr_verify (d); |
428 | 275 |
4844
91b3d00e717f
Various cleanups for Dynarr code, from Unicode-internal ws
Ben Wing <ben@xemacs.org>
parents:
4117
diff
changeset
|
276 type_checking_assert (start >= 0 && len >= 0 && start + len <= dy->len); |
428 | 277 memmove ((char *) dy->base + start*dy->elsize, |
278 (char *) dy->base + (start + len)*dy->elsize, | |
4844
91b3d00e717f
Various cleanups for Dynarr code, from Unicode-internal ws
Ben Wing <ben@xemacs.org>
parents:
4117
diff
changeset
|
279 (dy->len - start - len)*dy->elsize); |
91b3d00e717f
Various cleanups for Dynarr code, from Unicode-internal ws
Ben Wing <ben@xemacs.org>
parents:
4117
diff
changeset
|
280 dy->len -= len; |
428 | 281 } |
282 | |
283 void | |
284 Dynarr_free (void *d) | |
285 { | |
286 Dynarr *dy = (Dynarr *) d; | |
287 | |
3092 | 288 #ifdef NEW_GC |
289 if (dy->base && !DUMPEDP (dy->base)) | |
290 { | |
4117 | 291 if (!dy->lisp_imp) |
3092 | 292 xfree (dy->base, void *); |
293 } | |
294 if(!DUMPEDP (dy)) | |
295 { | |
4117 | 296 if (!dy->lisp_imp) |
3092 | 297 xfree (dy, Dynarr *); |
298 } | |
299 #else /* not NEW_GC */ | |
428 | 300 if (dy->base && !DUMPEDP (dy->base)) |
1726 | 301 xfree (dy->base, void *); |
428 | 302 if(!DUMPEDP (dy)) |
1726 | 303 xfree (dy, Dynarr *); |
3092 | 304 #endif /* not NEW_GC */ |
428 | 305 } |
306 | |
307 #ifdef MEMORY_USAGE_STATS | |
308 | |
309 /* Return memory usage for Dynarr D. The returned value is the total | |
310 amount of bytes actually being used for the Dynarr, including all | |
311 overhead. The extra amount of space in the Dynarr that is | |
312 allocated beyond what was requested is returned in DYNARR_OVERHEAD | |
313 in STATS. The extra amount of space that malloc() allocates beyond | |
314 what was requested of it is returned in MALLOC_OVERHEAD in STATS. | |
315 See the comment above the definition of this structure. */ | |
316 | |
665 | 317 Bytecount |
428 | 318 Dynarr_memory_usage (void *d, struct overhead_stats *stats) |
319 { | |
665 | 320 Bytecount total = 0; |
428 | 321 Dynarr *dy = (Dynarr *) d; |
322 | |
323 /* We have to be a bit tricky here because not all of the | |
324 memory that malloc() will claim as "requested" was actually | |
325 requested. */ | |
326 | |
327 if (dy->base) | |
328 { | |
665 | 329 Bytecount malloc_used = malloced_storage_size (dy->base, |
1318 | 330 dy->elsize * dy->max, 0); |
428 | 331 /* #### This may or may not be correct. Some Dynarrs would |
4844
91b3d00e717f
Various cleanups for Dynarr code, from Unicode-internal ws
Ben Wing <ben@xemacs.org>
parents:
4117
diff
changeset
|
332 prefer that we use dy->len instead of dy->largest here. */ |
1318 | 333 Bytecount was_requested = dy->elsize * dy->largest; |
334 Bytecount dynarr_overhead = dy->elsize * (dy->max - dy->largest); | |
428 | 335 |
336 total += malloc_used; | |
337 stats->was_requested += was_requested; | |
338 stats->dynarr_overhead += dynarr_overhead; | |
339 /* And the remainder must be malloc overhead. */ | |
340 stats->malloc_overhead += | |
341 malloc_used - was_requested - dynarr_overhead; | |
342 } | |
343 | |
344 total += malloced_storage_size (d, sizeof (*dy), stats); | |
345 | |
346 return total; | |
347 } | |
348 | |
349 #endif /* MEMORY_USAGE_STATS */ | |
2367 | 350 |
351 /* Version of malloc() that will be extremely efficient when allocation | |
352 nearly always occurs in LIFO (stack) order. | |
353 | |
354 #### Perhaps shouldn't be in this file, but where else? */ | |
355 | |
356 typedef struct | |
357 { | |
358 Dynarr_declare (char_dynarr *); | |
359 } char_dynarr_dynarr; | |
360 | |
361 char_dynarr_dynarr *stack_like_free_list; | |
362 char_dynarr_dynarr *stack_like_in_use_list; | |
363 | |
364 void * | |
365 stack_like_malloc (Bytecount size) | |
366 { | |
367 char_dynarr *this_one; | |
368 if (!stack_like_free_list) | |
369 { | |
370 stack_like_free_list = Dynarr_new2 (char_dynarr_dynarr, | |
371 char_dynarr *); | |
372 stack_like_in_use_list = Dynarr_new2 (char_dynarr_dynarr, | |
373 char_dynarr *); | |
374 } | |
375 | |
376 if (Dynarr_length (stack_like_free_list) > 0) | |
377 this_one = Dynarr_pop (stack_like_free_list); | |
378 else | |
379 this_one = Dynarr_new (char); | |
380 Dynarr_add (stack_like_in_use_list, this_one); | |
4844
91b3d00e717f
Various cleanups for Dynarr code, from Unicode-internal ws
Ben Wing <ben@xemacs.org>
parents:
4117
diff
changeset
|
381 Dynarr_reset (this_one); |
91b3d00e717f
Various cleanups for Dynarr code, from Unicode-internal ws
Ben Wing <ben@xemacs.org>
parents:
4117
diff
changeset
|
382 Dynarr_add_many (this_one, 0, size); |
2367 | 383 return Dynarr_atp (this_one, 0); |
384 } | |
385 | |
386 void | |
387 stack_like_free (void *val) | |
388 { | |
389 int len = Dynarr_length (stack_like_in_use_list); | |
390 assert (len > 0); | |
391 /* The vast majority of times, we will be called in a last-in first-out | |
392 order, and the item at the end of the list will be the one we're | |
393 looking for, so just check for this first and avoid any function | |
394 calls. */ | |
395 if (Dynarr_atp (Dynarr_at (stack_like_in_use_list, len - 1), 0) == val) | |
396 { | |
397 char_dynarr *this_one = Dynarr_pop (stack_like_in_use_list); | |
398 Dynarr_add (stack_like_free_list, this_one); | |
399 } | |
400 else | |
401 { | |
402 /* Find the item and delete it. */ | |
403 int i; | |
404 assert (len >= 2); | |
405 for (i = len - 2; i >= 0; i--) | |
406 if (Dynarr_atp (Dynarr_at (stack_like_in_use_list, i), 0) == | |
407 val) | |
408 { | |
409 char_dynarr *this_one = Dynarr_at (stack_like_in_use_list, i); | |
410 Dynarr_add (stack_like_free_list, this_one); | |
411 Dynarr_delete (stack_like_in_use_list, i); | |
412 return; | |
413 } | |
414 | |
2500 | 415 ABORT (); |
2367 | 416 } |
417 } |