Mercurial > hg > xemacs-beta
comparison src/file-coding.c @ 4967:0d4c9d0f6a8d
rewrite dynarr code
-------------------- ChangeLog entries follow: --------------------
src/ChangeLog addition:
2010-02-03 Ben Wing <ben@xemacs.org>
* device-x.c (x_get_resource_prefix):
* device-x.c (Fx_get_resource):
* device-x.c (Fx_get_resource_prefix):
* device-x.c (Fx_put_resource):
* dialog-msw.c:
* dialog-msw.c (handle_question_dialog_box):
* dired-msw.c (mswindows_sort_files):
* dired-msw.c (mswindows_get_files):
* extents.c (extent_fragment_sort_by_priority):
* extents.c (Fset_extent_parent):
* file-coding.c (coding_reader):
* file-coding.c (coding_writer):
* file-coding.c (gzip_convert):
* frame.c (generate_title_string):
* gutter.c (calculate_gutter_size_from_display_lines):
* indent.c (vmotion_1):
* lread.c (read_bit_vector):
* mule-coding.c (iso2022_decode):
* rangetab.c:
* rangetab.c (Fcopy_range_table):
* rangetab.c (Fget_range_table):
* rangetab.c (unified_range_table_copy_data):
* redisplay-msw.c (mswindows_output_string):
* redisplay-output.c (output_display_line):
* redisplay-output.c (redisplay_move_cursor):
* redisplay-output.c (redisplay_clear_bottom_of_window):
* redisplay-tty.c (tty_output_ichar_dynarr):
* redisplay-tty.c (set_foreground_to):
* redisplay-tty.c (set_background_to):
* redisplay-xlike-inc.c (XLIKE_output_string):
* redisplay.c (redisplay_window_text_width_string):
* redisplay.c (redisplay_text_width_string):
* redisplay.c (create_text_block):
* redisplay.c (SET_CURRENT_MODE_CHARS_PIXSIZE):
* redisplay.c (generate_fstring_runes):
* redisplay.c (regenerate_modeline):
* redisplay.c (ensure_modeline_generated):
* redisplay.c (real_current_modeline_height):
* redisplay.c (create_string_text_block):
* redisplay.c (regenerate_window):
* redisplay.c (REGEN_INC_FIND_START_END):
* redisplay.c (point_visible):
* redisplay.c (redisplay_window):
* redisplay.c (mark_glyph_block_dynarr):
* redisplay.c (line_start_cache_start):
* redisplay.c (start_with_line_at_pixpos):
* redisplay.c (update_line_start_cache):
* redisplay.c (glyph_to_pixel_translation):
* redisplay.c (pixel_to_glyph_translation):
* sysdep.c (qxe_readdir):
* text.c (dfc_convert_to_external_format):
* text.c (dfc_convert_to_internal_format):
* toolbar-common.c (common_output_toolbar_button):
* window.c (window_modeline_height):
* window.c (Fwindow_last_line_visible_height):
* window.c (window_displayed_height):
* window.c (window_scroll):
* window.c (get_current_pixel_pos):
Use Dynarr_begin() in place of Dynarr_atp (foo, 0).
* dynarr.c (Dynarr_realloc):
* dynarr.c (Dynarr_lisp_realloc):
* dynarr.c (Dynarr_resize):
* dynarr.c (Dynarr_insert_many):
* dynarr.c (Dynarr_delete_many):
* dynarr.c (Dynarr_memory_usage):
* dynarr.c (stack_like_malloc):
* dynarr.c (stack_like_free):
* lisp.h:
* lisp.h (DECLARE_DYNARR_LISP_IMP):
* lisp.h (XD_DYNARR_DESC):
* lisp.h (Dynarr_pop):
* gutter.c (output_gutter):
* redisplay-output.c (sync_rune_structs):
* redisplay-output.c (redisplay_output_window):
Redo the dynarr code, add greater checks.
Rename the `len', `largest' and `max' members to `len_',
`largest_' and `max_' to try and catch existing places that might
directly modify these values. Make new accessors Dynarr_largest()
and Dynarr_max() and make them and existing Dynarr_length() be
non-lvalues by adding '+ 0' to them; fix a couple of places in the
redisplay code that tried to modify the length directly by setting
Dynarr_length(). Use the accessors whenever possible even in the
dynarr code itself. The accessors also verify that 0 <= len <=
largest <= max. Rename settor function Dynarr_set_size() to
Dynarr_set_length() and use it more consistently; also create
lower-level Dynarr_set_length_1(). This latter function should be
the only function that directly modifies the `len_' member of a
Dynarr, and in the process makes sure that the `largest' value is
kept correct.
Consistently use ERROR_CHECK_STRUCTURES instead of
ERROR_CHECK_TYPES for error-checking code. Reintroduce the
temporarily disabled verification code on the positions of
Dynarr_at(), Dynarr_atp() and Dynarr_atp_past_end().
Also create Dynarr_resize_if() in place of a repeated
code fragment. Clean up all the functions that modify Dynarrs to
use the new macros and functions and verify the correctness of the
Dynarr both before and after the change.
Note that there are two kinds of verification -- one for accessing
and one for modifying. The difference is that the modify
verification additionally checks to make sure that the Dynarr
isn't locked. (This is used in redisplay to check for problems
with reentrancy.)
* lrecord.h: Move XD_DYNARR_DESC to lisp.h, grouping with the dynarr code.
author | Ben Wing <ben@xemacs.org> |
---|---|
date | Wed, 03 Feb 2010 20:51:18 -0600 |
parents | 304aebb79cd3 |
children | 16112448d484 |
comparison
equal
deleted
inserted
replaced
4966:48b63cd88a21 | 4967:0d4c9d0f6a8d |
---|---|
1833 most SIZE bytes, and delete the data from convert_to. */ | 1833 most SIZE bytes, and delete the data from convert_to. */ |
1834 if (Dynarr_length (str->convert_to) > 0) | 1834 if (Dynarr_length (str->convert_to) > 0) |
1835 { | 1835 { |
1836 Bytecount chunk = | 1836 Bytecount chunk = |
1837 min (size, (Bytecount) Dynarr_length (str->convert_to)); | 1837 min (size, (Bytecount) Dynarr_length (str->convert_to)); |
1838 memcpy (data, Dynarr_atp (str->convert_to, 0), chunk); | 1838 memcpy (data, Dynarr_begin (str->convert_to), chunk); |
1839 Dynarr_delete_many (str->convert_to, 0, chunk); | 1839 Dynarr_delete_many (str->convert_to, 0, chunk); |
1840 data += chunk; | 1840 data += chunk; |
1841 size -= chunk; | 1841 size -= chunk; |
1842 } | 1842 } |
1843 | 1843 |
1862 Dynarr_add_many (str->convert_from, 0, readmore); | 1862 Dynarr_add_many (str->convert_from, 0, readmore); |
1863 read_size = Lstream_read (str->other_end, | 1863 read_size = Lstream_read (str->other_end, |
1864 Dynarr_atp (str->convert_from, rejected), | 1864 Dynarr_atp (str->convert_from, rejected), |
1865 readmore); | 1865 readmore); |
1866 /* Trim size down to how much we actually got */ | 1866 /* Trim size down to how much we actually got */ |
1867 Dynarr_set_size (str->convert_from, rejected + max (0, read_size)); | 1867 Dynarr_set_length (str->convert_from, rejected + max (0, read_size)); |
1868 } | 1868 } |
1869 | 1869 |
1870 if (read_size < 0) /* LSTREAM_ERROR */ | 1870 if (read_size < 0) /* LSTREAM_ERROR */ |
1871 { | 1871 { |
1872 error_occurred = 1; | 1872 error_occurred = 1; |
1884 Bytecount to_process = Dynarr_length (str->convert_from); | 1884 Bytecount to_process = Dynarr_length (str->convert_from); |
1885 | 1885 |
1886 /* Convert the data, and save any rejected data in convert_from */ | 1886 /* Convert the data, and save any rejected data in convert_from */ |
1887 processed = | 1887 processed = |
1888 XCODESYSMETH (str->codesys, convert, | 1888 XCODESYSMETH (str->codesys, convert, |
1889 (str, Dynarr_atp (str->convert_from, 0), | 1889 (str, Dynarr_begin (str->convert_from), |
1890 str->convert_to, to_process)); | 1890 str->convert_to, to_process)); |
1891 if (processed < 0) | 1891 if (processed < 0) |
1892 { | 1892 { |
1893 error_occurred = 1; | 1893 error_occurred = 1; |
1894 break; | 1894 break; |
1895 } | 1895 } |
1896 assert (processed <= to_process); | 1896 assert (processed <= to_process); |
1897 if (processed < to_process) | 1897 if (processed < to_process) |
1898 memmove (Dynarr_atp (str->convert_from, 0), | 1898 memmove (Dynarr_begin (str->convert_from), |
1899 Dynarr_atp (str->convert_from, processed), | 1899 Dynarr_atp (str->convert_from, processed), |
1900 to_process - processed); | 1900 to_process - processed); |
1901 Dynarr_set_size (str->convert_from, to_process - processed); | 1901 Dynarr_set_length (str->convert_from, to_process - processed); |
1902 } | 1902 } |
1903 } | 1903 } |
1904 | 1904 |
1905 if (data - orig_data == 0) | 1905 if (data - orig_data == 0) |
1906 return error_occurred ? -1 : 0; | 1906 return error_occurred ? -1 : 0; |
1916 /* Convert all our data into convert_to, and then attempt to write | 1916 /* Convert all our data into convert_to, and then attempt to write |
1917 it all out to the other end. */ | 1917 it all out to the other end. */ |
1918 Dynarr_reset (str->convert_to); | 1918 Dynarr_reset (str->convert_to); |
1919 size = XCODESYSMETH (str->codesys, convert, | 1919 size = XCODESYSMETH (str->codesys, convert, |
1920 (str, data, str->convert_to, size)); | 1920 (str, data, str->convert_to, size)); |
1921 if (Lstream_write (str->other_end, Dynarr_atp (str->convert_to, 0), | 1921 if (Lstream_write (str->other_end, Dynarr_begin (str->convert_to), |
1922 Dynarr_length (str->convert_to)) < 0) | 1922 Dynarr_length (str->convert_to)) < 0) |
1923 return -1; | 1923 return -1; |
1924 else | 1924 else |
1925 /* The return value indicates how much of the incoming data was | 1925 /* The return value indicates how much of the incoming data was |
1926 processed, not how many bytes were written. */ | 1926 processed, not how many bytes were written. */ |
4421 data->stream.next_out = | 4421 data->stream.next_out = |
4422 Dynarr_atp (dst, Dynarr_length (dst) - reserved); | 4422 Dynarr_atp (dst, Dynarr_length (dst) - reserved); |
4423 data->stream.avail_out = reserved; | 4423 data->stream.avail_out = reserved; |
4424 zerr = inflate (&data->stream, Z_NO_FLUSH); | 4424 zerr = inflate (&data->stream, Z_NO_FLUSH); |
4425 /* Lop off the unused portion */ | 4425 /* Lop off the unused portion */ |
4426 Dynarr_set_size (dst, Dynarr_length (dst) - data->stream.avail_out); | 4426 Dynarr_set_length (dst, Dynarr_length (dst) - data->stream.avail_out); |
4427 if (zerr != Z_OK) | 4427 if (zerr != Z_OK) |
4428 break; | 4428 break; |
4429 } | 4429 } |
4430 | 4430 |
4431 if (zerr == Z_STREAM_END) | 4431 if (zerr == Z_STREAM_END) |
4481 data->stream.avail_out = reserved; | 4481 data->stream.avail_out = reserved; |
4482 zerr = | 4482 zerr = |
4483 deflate (&data->stream, | 4483 deflate (&data->stream, |
4484 str->eof ? Z_FINISH : Z_NO_FLUSH); | 4484 str->eof ? Z_FINISH : Z_NO_FLUSH); |
4485 /* Lop off the unused portion */ | 4485 /* Lop off the unused portion */ |
4486 Dynarr_set_size (dst, Dynarr_length (dst) - data->stream.avail_out); | 4486 Dynarr_set_length (dst, Dynarr_length (dst) - data->stream.avail_out); |
4487 if (zerr != Z_OK) | 4487 if (zerr != Z_OK) |
4488 break; | 4488 break; |
4489 } | 4489 } |
4490 | 4490 |
4491 if ((Bytecount) data->stream.avail_in < n) | 4491 if ((Bytecount) data->stream.avail_in < n) |