Mercurial > hg > xemacs-beta
annotate modules/sample/internal/sample.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 | dce479915b74 |
children | dd9541c73e70 |
rev | line source |
---|---|
996 | 1 /* |
2 * Very simple sample module. Illustrates most of the salient features | |
3 * of Emacs dynamic modules. | |
4 * (C) Copyright 1998, 1999 J. Kean Johnston. All rights reserved. | |
5 * (C) Copyright 2002 Jerry James. | |
4737
dce479915b74
Clarify the GPL status of several sample module files. J. Kean Johnston
Jerry James <james@xemacs.org>
parents:
996
diff
changeset
|
6 * |
dce479915b74
Clarify the GPL status of several sample module files. J. Kean Johnston
Jerry James <james@xemacs.org>
parents:
996
diff
changeset
|
7 * This sample module code is free software; you can redistribute it and/or |
dce479915b74
Clarify the GPL status of several sample module files. J. Kean Johnston
Jerry James <james@xemacs.org>
parents:
996
diff
changeset
|
8 * modify it under the terms of the GNU General Public License as published |
dce479915b74
Clarify the GPL status of several sample module files. J. Kean Johnston
Jerry James <james@xemacs.org>
parents:
996
diff
changeset
|
9 * by the Free Software Foundation; either version 2, or (at your option) |
dce479915b74
Clarify the GPL status of several sample module files. J. Kean Johnston
Jerry James <james@xemacs.org>
parents:
996
diff
changeset
|
10 * any later version. |
996 | 11 */ |
12 | |
13 #include <config.h> | |
14 #include "lisp.h" | |
15 | |
16 /* | |
17 * This sample introduces three new Lisp objects to the Lisp reader. | |
18 * The first, a simple boolean value, and the second a string. The | |
19 * Third is a sample function that simply prints a message. | |
20 */ | |
21 int sample_bool; | |
22 Lisp_Object Vsample_string; | |
23 | |
24 DEFUN ("sample-function", Fsample_function, 0, 0, "", /* | |
25 This is a sample function loaded dynamically. | |
26 | |
27 You will notice in the source code for this module that the | |
28 declaration is identical to internal Emacs functions. This | |
29 makes it possible to use the exact same code in a dumped | |
30 version of Emacs. | |
31 */ | |
32 ()) | |
33 { | |
34 message ("Eureka! It worked"); | |
35 return Qt; | |
36 } | |
37 | |
38 /* | |
39 * Each dynamically loaded Emacs module is given a name at compile | |
40 * time. This is a short name, and must be a valid part of a C | |
41 * identifier. This name is used to construct the name of several | |
42 * functions which must appear in the module source code. | |
43 * The first such function, modules_of_XXXX, should load in any dependent | |
44 * modules. This function is optional, and the module will still load if | |
45 * it is not present in the module. | |
46 * | |
47 * The second function, which is NOT optional, is syms_of_XXXX, in which | |
48 * all functions that the module will be provided are declared. This | |
49 * function will contain calls to DEFSUBR(). | |
50 * | |
51 * The third function, which is also NOT optional, is vars_of_XXXX, in | |
52 * which you declare all variables that the module provides. This | |
53 * function will contain calls to DEFVAR_LISP(), DEFVAR_BOOL() etc. | |
54 * | |
55 * When declaring functions and variables in the syms_of_XXXX and | |
56 * vars_of_XXXX functions, you use the exact same syntax that you | |
57 * would as if this module were being compiled into the pure Emacs. | |
58 * | |
59 * The fourth function, which is optional, is unload_XXXX, in which actions | |
60 * that must be taken to unload the module are listed. XEmacs will unbind | |
61 * functions and variables for you. Anything else that must be done should | |
62 * appear in this function. | |
63 * | |
64 * All four of these functions are declared as void functions, | |
65 * taking no parameters. Since this sample module is called 'sample', | |
66 * the functions will be named 'modules_of_sample', 'syms_of_sample', | |
67 * 'vars_of_sample', and 'unload_sample'. | |
68 */ | |
69 | |
70 void | |
71 modules_of_sample() | |
72 { | |
73 /* | |
74 * This function isn't actually required as we will not be loading | |
75 * in any dependent modules, but if we were, we would do something like: | |
76 * emodules_load ("dependent.ell", "sample2", "1.0.0"); | |
77 */ | |
78 } | |
79 | |
80 void | |
81 syms_of_sample() | |
82 { | |
83 DEFSUBR(Fsample_function); | |
84 } | |
85 | |
86 void | |
87 vars_of_sample() | |
88 { | |
89 DEFVAR_LISP ("sample-string", &Vsample_string /* | |
90 This is a sample string, declared in a dynamic module. | |
91 | |
92 The syntax and conventions used for all normal Emacs variables | |
93 apply equally to modules, using an identical syntax. | |
94 */ ); | |
95 | |
96 DEFVAR_BOOL ("sample-boolean", &sample_bool /* | |
97 *Sample boolean value, in a dynamic module. | |
98 | |
99 This is a user-settable variable, as indicated by the * | |
100 as the first character of the description. Declared in | |
101 a module exactly as it would be internally in Emacs. | |
102 */ ); | |
103 } | |
104 | |
105 #ifdef HAVE_SHLIB | |
106 void | |
107 unload_sample() | |
108 { | |
109 /* We don't need to do anything here in the sample case. However, if you | |
110 create any new types with INIT_LRECORD_IMPLEMENTATION (sample_type), then | |
111 UNDEF_LRECORD_IMPLEMENTATION (sample_type) must appear here. Also, any | |
112 symbols declared with DEFSYMBOL (Qsample_var), or one of its variants, | |
113 must have a corresponding unstaticpro_nodump (&Qsample_var) here. */ | |
114 } | |
115 #endif |