comparison src/scrollbar-msw.c @ 617:af57a77cbc92

[xemacs-hg @ 2001-06-18 07:09:50 by ben] --------------------------------------------------------------- DOCUMENTATION FIXES: --------------------------------------------------------------- eval.c: Correct documentation. elhash.c: Doc correction. --------------------------------------------------------------- LISP OBJECT CLEANUP: --------------------------------------------------------------- bytecode.h, buffer.h, casetab.h, chartab.h, console-msw.h, console.h, database.c, device.h, eldap.h, elhash.h, events.h, extents.h, faces.h, file-coding.h, frame.h, glyphs.h, gui-x.h, gui.h, keymap.h, lisp-disunion.h, lisp-union.h, lisp.h, lrecord.h, lstream.h, mule-charset.h, objects.h, opaque.h, postgresql.h, process.h, rangetab.h, specifier.h, toolbar.h, tooltalk.h, ui-gtk.h: Add wrap_* to all objects (it was already there for a few of them) -- an expression to encapsulate a pointer into a Lisp object, rather than the inconvenient XSET*. "wrap" was chosen because "make" as in make_int(), make_char() is not appropriate. (It implies allocation. The issue does not exist for ints and chars because they are not allocated.) Full error checking has been added to these expressions. When used without error checking, non-union build, use of these expressions will incur no loss of efficiency. (In fact, XSET* is now defined in terms of wrap_* in a non-union build.) In a union build, you will also get no loss of efficiency provided that you have a decent optimizing compiler, and a compiler that either understands inlines or automatically inlines those particular functions. (And since people don't normally do their production builds on union, it doesn't matter.) Update the sample Lisp object definition in lrecord.h accordingly. dumper.c: Fix places in dumper that referenced wrap_object to reference its new name, wrap_pointer_1. buffer.c, bufslots.h, conslots.h, console.c, console.h, devslots.h, device.c, device.h, frame.c, frame.h, frameslots.h, window.c, window.h, winslots.h: -- Extract out the Lisp objects of `struct device' into devslots.h, just like for the other structures. -- Extract out the remaining (not copied into the window config) Lisp objects in `struct window' into winslots.h; use different macros (WINDOW_SLOT vs. WINDOW_SAVED_SLOT) to differentiate them. -- Eliminate the `dead' flag of `struct frame', since it duplicates information already available in `framemeths', and fix FRAME_LIVE_P accordingly. (Devices and consoles already work this way.) -- In *slots.h, switch to system where MARKED_SLOT is automatically undef'd at the end of the file. (Follows what winslots.h already does.) -- Update the comments at the beginning of *slots.h to be accurate. -- When making any of the above objects dead, zero it out entirely and reset all Lisp object slots to Qnil. (We were already doing this somewhat, but not consistently.) This (1) Eliminates the possibility of extra objects hanging around that ought to be GC'd, (2) Causes an immediate crash if anyone tries to access a structure in one of these objects, (3) Ensures consistent behavior wrt dead objects. dialog-msw.c: Use internal_object_printer, since this object should not escape. --------------------------------------------------------------- FIXING A CRASH THAT I HIT ONCE (AND A RELATED BAD BEHAVIOR): --------------------------------------------------------------- eval.c: Fix up some comments about the FSF implementation. Fix two nasty bugs: (1) condition_case_unwind frees the conses sitting in the catch->tag slot too quickly, resulting in a crash that I hit. (2) catches need to be unwound one at a time when calling unwind-protect code, rather than all at once at the end; otherwise, incorrect behavior can result. (A comment shows exactly how.) backtrace.h: Improve comment about FSF differences in the handler stack. --------------------------------------------------------------- FIXING A CRASH THAT I REPEATEDLY HIT WHEN USING THE MOUSE WHEEL UNDER MSWINDOWS: --------------------------------------------------------------- Basic idea: My crash is due either to a dead, non-marked, GC-collected frame inside of a window mirror, or a prematurely freed window mirror. We need to mark the Lisp objects inside of window mirrors. Tracking the lifespan of window mirrors and scrollbar instances is extremely hard, and there may well be lurking bugs where such objects are freed too soon. The only safe way to fix these problems (and it fixes both problems at once) is to make both of these structures Lisp objects. lrecord.h, emacs.c, inline.c, scrollbar-gtk.c, scrollbar-msw.c, scrollbar-x.c, scrollbar.c, scrollbar.h, symsinit.h: Make scrollbar instances actual Lisp objects. Mark the window mirrors in them. inline.c needs to know about scrollbar.h now. Record the new type in lrecord.h. Fix up scrollbar-*.c appropriately. Create a hash table in scrollbar-msw.c so that the scrollbar instances stored in scrollbar HWND's are properly GC-protected. Create complex_vars_of_scrollbar_mswindows() to create the hash table at startup, and call it from emacs.c. Don't store the scrollbar instance as a property of the GTK scrollbar, as it's not used and if we did this, we'd have to separately GC-protect it in a hash table, like in MS Windows. lrecord.h, frame.h, frame.c, frameslots.h, redisplay.c, window.c, window.h: Move mark_window_mirror from redisplay.c to window.c. Make window mirrors actual Lisp objects. Tell lrecord.h about them. Change the window mirror member of struct frame from a pointer to a Lisp object, and add XWINDOW_MIRROR in appropriate places. Mark the scrollbar instances in the window mirror. redisplay.c, redisplay.h, alloc.c: Delete mark_redisplay. Don't call mark_redisplay. We now mark frame-specific structures in mark_frame. NOTE: I also deleted an extremely questionable call to update_frame_window_mirrors(). It was extremely questionable before, and now totally impossible, since it will create Lisp objects during redisplay. frame.c: Mark the scrollbar instances, which are now Lisp objects. Call mark_gutter() here, not in mark_redisplay(). gutter.c: Update comments about correct marking. --------------------------------------------------------------- ISSUES BROUGHT UP BY MARTIN: --------------------------------------------------------------- buffer.h: Put back these macros the way Steve T and I think they ought to be. I already explained in a previous changelog entry why I think these macros should be the way I'd defined them. Once again: We fix these macros so they don't care about the type of their lvalues. The non-C-string equivalents of these already function in the same way, and it's correct because it should be OK to pass in a CBufbyte *, a BufByte *, a Char_Binary *, an UChar_Binary *, etc. The whole reason for these different types is to work around errors caused by signed-vs-unsigned non-matching types. Any possible error that might be caught in a DFC macro would also be caught wherever the argument is used elsewhere. So creating multiple macro versions would add no useful error-checking and just further complicate an already complicated area. As for Martin's "ANSI aliasing" bug, XEmacs is not ANSI-aliasing clean and probably never will be. Unless the board agrees to change XEmacs in this way (and we really don't want to go down that road), this is not a bug. sound.h: Undo Martin's type change. signal.c: Fix problem identified by Martin with Linux and g++ due to non-standard declaration of setitimer(). systime.h: Update the docs for "qxe_" to point out why making the encapsulation explicit is always the right way to go. (setitimer() itself serves as an example.) For 21.4: update-elc-2.el: Correct misplaced parentheses, making lisp/mule not get recompiled.
author ben
date Mon, 18 Jun 2001 07:10:32 +0000
parents 38db05db9cb5
children 6e99cc8c6ca5
comparison
equal deleted inserted replaced
616:4f1c7a4ac1e6 617:af57a77cbc92
25 25
26 #include <config.h> 26 #include <config.h>
27 #include "lisp.h" 27 #include "lisp.h"
28 28
29 #include "console-msw.h" 29 #include "console-msw.h"
30 #include "elhash.h"
30 #include "events.h" 31 #include "events.h"
31 #include "frame.h" 32 #include "frame.h"
33 #include "opaque.h"
32 #include "scrollbar-msw.h" 34 #include "scrollbar-msw.h"
33 #include "scrollbar.h" 35 #include "scrollbar.h"
34 #include "specifier.h" 36 #include "specifier.h"
35 #include "window.h" 37 #include "window.h"
36 38
40 * without the hack it is impossible to drag to the end of a buffer. */ 42 * without the hack it is impossible to drag to the end of a buffer. */
41 #define VERTICAL_SCROLLBAR_DRAG_HACK 43 #define VERTICAL_SCROLLBAR_DRAG_HACK
42 44
43 static int vertical_drag_in_progress = 0; 45 static int vertical_drag_in_progress = 0;
44 46
47 /* As long as the HWND is around, the scrollbar instance must be GC-protected.
48 We have gotten crashes, apparently from trying to access a dead, freed
49 frame inside of a window mirror pointed to by the scrollbar structure. */
50 static Lisp_Object Vmswindows_scrollbar_instance_table;
51
45 static void 52 static void
46 mswindows_create_scrollbar_instance (struct frame *f, int vertical, 53 mswindows_create_scrollbar_instance (struct frame *f, int vertical,
47 struct scrollbar_instance *sb) 54 struct scrollbar_instance *sb)
48 { 55 {
49 int orientation; 56 int orientation;
57 Lisp_Object ptr;
50 58
51 sb->scrollbar_data = xnew_and_zero (struct mswindows_scrollbar_data); 59 sb->scrollbar_data = xnew_and_zero (struct mswindows_scrollbar_data);
52 60
53 if (vertical) 61 if (vertical)
54 orientation = SBS_VERT; 62 orientation = SBS_VERT;
61 CW_USEDEFAULT, CW_USEDEFAULT, 69 CW_USEDEFAULT, CW_USEDEFAULT,
62 FRAME_MSWINDOWS_HANDLE (f), 70 FRAME_MSWINDOWS_HANDLE (f),
63 NULL, NULL, NULL); 71 NULL, NULL, NULL);
64 SCROLLBAR_MSW_INFO (sb).cbSize = sizeof (SCROLLINFO); 72 SCROLLBAR_MSW_INFO (sb).cbSize = sizeof (SCROLLINFO);
65 SCROLLBAR_MSW_INFO (sb).fMask = SIF_ALL; 73 SCROLLBAR_MSW_INFO (sb).fMask = SIF_ALL;
66 GetScrollInfo(SCROLLBAR_MSW_HANDLE (sb), SB_CTL, 74 GetScrollInfo (SCROLLBAR_MSW_HANDLE (sb), SB_CTL,
67 &SCROLLBAR_MSW_INFO (sb)); 75 &SCROLLBAR_MSW_INFO (sb));
68 SetWindowLong (SCROLLBAR_MSW_HANDLE (sb), GWL_USERDATA, (LONG) sb); 76 ptr = make_opaque_ptr (SCROLLBAR_MSW_HANDLE (sb));
69 77 Fputhash (ptr, wrap_scrollbar_instance (sb),
70 #if 0 78 Vmswindows_scrollbar_instance_table);
71 { 79 SetWindowLong (SCROLLBAR_MSW_HANDLE (sb), GWL_USERDATA,
72 HWND h = SCROLLBAR_MSW_HANDLE (sb); 80 (LONG) LISP_TO_VOID (ptr));
73 int x = SetWindowLong (SCROLLBAR_MSW_HANDLE(sb), GWL_USERDATA, (LONG)sb);
74 int y = GetLastError();
75 struct scrollbar_instance *z =
76 (struct scrollbar_instance *)GetWindowLong (SCROLLBAR_MSW_HANDLE(sb),
77 GWL_USERDATA);
78 *z = *z;
79 }
80 #endif
81 } 81 }
82 82
83 static void 83 static void
84 mswindows_free_scrollbar_instance (struct scrollbar_instance *sb) 84 mswindows_free_scrollbar_instance (struct scrollbar_instance *sb)
85 { 85 {
86 void *opaque =
87 (void *) GetWindowLong (SCROLLBAR_MSW_HANDLE (sb), GWL_USERDATA);
88 Lisp_Object ptr;
89
90 VOID_TO_LISP (ptr, opaque);
91 assert (OPAQUE_PTRP (ptr));
92 ptr = Fremhash (ptr, Vmswindows_scrollbar_instance_table);
93 assert (!NILP (ptr));
86 DestroyWindow (SCROLLBAR_MSW_HANDLE (sb)); 94 DestroyWindow (SCROLLBAR_MSW_HANDLE (sb));
87 if (sb->scrollbar_data) 95 if (sb->scrollbar_data)
88 xfree (sb->scrollbar_data); 96 xfree (sb->scrollbar_data);
89 } 97 }
90 98
159 UPDATE_POS_FIELD (scrollbar_width); 167 UPDATE_POS_FIELD (scrollbar_width);
160 UPDATE_POS_FIELD (scrollbar_height); 168 UPDATE_POS_FIELD (scrollbar_height);
161 169
162 if (pos_changed) 170 if (pos_changed)
163 { 171 {
164 MoveWindow(SCROLLBAR_MSW_HANDLE (sb), 172 MoveWindow (SCROLLBAR_MSW_HANDLE (sb),
165 new_scrollbar_x, new_scrollbar_y, 173 new_scrollbar_x, new_scrollbar_y,
166 new_scrollbar_width, new_scrollbar_height, 174 new_scrollbar_width, new_scrollbar_height,
167 TRUE); 175 TRUE);
168 } 176 }
169 } 177 }
170 178
171 static void 179 static void
172 mswindows_update_scrollbar_instance_status (struct window *w, 180 mswindows_update_scrollbar_instance_status (struct window *w,
186 void 194 void
187 mswindows_handle_scrollbar_event (HWND hwnd, int code, int pos) 195 mswindows_handle_scrollbar_event (HWND hwnd, int code, int pos)
188 { 196 {
189 struct frame *f; 197 struct frame *f;
190 Lisp_Object win, frame; 198 Lisp_Object win, frame;
191 struct scrollbar_instance *sb; 199 struct scrollbar_instance *sb = 0;
200 void *v;
192 SCROLLINFO scrollinfo; 201 SCROLLINFO scrollinfo;
193 int vert = GetWindowLong (hwnd, GWL_STYLE) & SBS_VERT; 202 int vert = GetWindowLong (hwnd, GWL_STYLE) & SBS_VERT;
194 int value; 203 int value;
195 204
196 sb = (struct scrollbar_instance *) GetWindowLong (hwnd, GWL_USERDATA); 205 v = (void *) GetWindowLong (hwnd, GWL_USERDATA);
197 if (!sb) 206 if (!v)
198 { 207 {
208 /* apparently this can happen, as it was definitely necessary
209 to put the check in for sb below (VERTICAL_SCROLLBAR_DRAG_HACK) */
199 frame = mswindows_find_frame (hwnd); 210 frame = mswindows_find_frame (hwnd);
200 f = XFRAME (frame); 211 f = XFRAME (frame);
201 win = FRAME_SELECTED_WINDOW (f); 212 win = FRAME_SELECTED_WINDOW (f);
202 } 213 }
203 else 214 else
204 { 215 {
216 Lisp_Object ptr;
217 VOID_TO_LISP (ptr, v);
218 assert (OPAQUE_PTRP (ptr));
219 ptr = Fgethash (ptr, Vmswindows_scrollbar_instance_table, Qnil);
220 sb = XSCROLLBAR_INSTANCE (ptr);
205 win = real_window (sb->mirror, 0); 221 win = real_window (sb->mirror, 0);
206 frame = XWINDOW (win)->frame; 222 frame = WINDOW_FRAME (XWINDOW (win));
207 f = XFRAME (frame); 223 f = XFRAME (frame);
208 } 224 }
209 225
210 /* SB_LINEDOWN == SB_CHARLEFT etc. This is the way they will 226 /* SB_LINEDOWN == SB_CHARLEFT etc. This is the way they will
211 always be - any Windows is binary compatible backward with 227 always be -- any Windows is binary compatible backward with
212 old programs */ 228 old programs. */
213 229
214 switch (code) 230 switch (code)
215 { 231 {
216 case SB_LINEDOWN: 232 case SB_LINEDOWN:
217 mswindows_enqueue_misc_user_event 233 mswindows_enqueue_misc_user_event
405 421
406 /************************************************************************/ 422 /************************************************************************/
407 /* Device-specific ghost specifiers initialization */ 423 /* Device-specific ghost specifiers initialization */
408 /************************************************************************/ 424 /************************************************************************/
409 425
410 DEFUN ("mswindows-init-scrollbar-metrics", Fmswindows_init_scrollbar_metrics, 1, 1, 0, /* 426 DEFUN ("mswindows-init-scrollbar-metrics", Fmswindows_init_scrollbar_metrics,
427 1, 1, 0, /*
411 */ 428 */
412 (locale)) 429 (locale))
413 { 430 {
414 if (DEVICEP (locale)) 431 if (DEVICEP (locale))
415 { 432 {
441 CONSOLE_HAS_METHOD (mswindows, compute_scrollbar_instance_usage); 458 CONSOLE_HAS_METHOD (mswindows, compute_scrollbar_instance_usage);
442 #endif 459 #endif
443 } 460 }
444 461
445 void 462 void
446 syms_of_scrollbar_mswindows(void) 463 syms_of_scrollbar_mswindows (void)
447 { 464 {
448 DEFSUBR (Fmswindows_init_scrollbar_metrics); 465 DEFSUBR (Fmswindows_init_scrollbar_metrics);
449 } 466 }
450 467
451 void 468 void
452 vars_of_scrollbar_mswindows(void) 469 vars_of_scrollbar_mswindows (void)
453 { 470 {
454 Fprovide (intern ("mswindows-scrollbars")); 471 Fprovide (intern ("mswindows-scrollbars"));
455 } 472 }
456 473
474 void
475 complex_vars_of_scrollbar_mswindows (void)
476 {
477 staticpro (&Vmswindows_scrollbar_instance_table);
478 Vmswindows_scrollbar_instance_table =
479 make_lisp_hash_table (100, HASH_TABLE_NON_WEAK, HASH_TABLE_EQ);
480 }