comparison src/event-msw.c @ 853:2b6fa2618f76

[xemacs-hg @ 2002-05-28 08:44:22 by ben] merge my stderr-proc ws make-docfile.c: Fix places where we forget to check for EOF. code-init.el: Don't use CRLF conversion by default on process output. CMD.EXE and friends work both ways but Cygwin programs don't like the CRs. code-process.el, multicast.el, process.el: Removed. Improvements to call-process-internal: -- allows a buffer to be specified for input and stderr output -- use it on all systems -- implement C-g as documented -- clean up and comment call-process-region uses new call-process facilities; no temp file. remove duplicate funs in process.el. comment exactly how coding systems work and fix various problems. open-multicast-group now does similar coding-system frobbing to open-network-stream. dumped-lisp.el, faces.el, msw-faces.el: Fix some hidden errors due to code not being defined at the right time. xemacs.mak: Add -DSTRICT. ================================================================ ALLOW SEPARATION OF STDOUT AND STDERR IN PROCESSES ================================================================ Standard output and standard error can be processed separately in a process. Each can have its own buffer, its own mark in that buffer, and its filter function. You can specify a separate buffer for stderr in `start-process' to get things started, or use the new primitives: set-process-stderr-buffer process-stderr-buffer process-stderr-mark set-process-stderr-filter process-stderr-filter Also, process-send-region takes a 4th optional arg, a buffer. Currently always uses a pipe() under Unix to read the error output. (#### Would a PTY be better?) sysdep.h, sysproc.h, unexfreebsd.c, unexsunos4.c, nt.c, emacs.c, callproc.c, symsinit.h, sysdep.c, Makefile.in.in, process-unix.c: Delete callproc.c. Move child_setup() to process-unix.c. wait_for_termination() now only needed on a few really old systems. console-msw.h, event-Xt.c, event-msw.c, event-stream.c, event-tty.c, event-unixoid.c, events.h, process-nt.c, process-unix.c, process.c, process.h, procimpl.h: Rewrite the process methods to handle a separate channel for error input. Create Lstreams for reading in the error channel. Many process methods need change. In general the changes are fairly clear as they involve duplicating what's used for reading the normal stdout and changing for stderr -- although tedious, as such changes are required throughout the entire process code. Rewrote the code that reads process output to do two loops, one for stdout and one for stderr. gpmevent.c, tooltalk.c: set_process_filter takes an argument for stderr. ================================================================ NEW ERROR-TRAPPING MECHANISM ================================================================ Totally rewrite error trapping code to be unified and support more features. Basic function is call_trapping_problems(), which lets you specify, by means of flags, what sorts of problems you want trapped. these can include -- quit -- errors -- throws past the function -- creation of "display objects" (e.g. buffers) -- deletion of already-existing "display objects" (e.g. buffers) -- modification of already-existing buffers -- entering the debugger -- gc -- errors->warnings (ala suspended errors) etc. All other error funs rewritten in terms of this one. Various older mechanisms removed or rewritten. window.c, insdel.c, console.c, buffer.c, device.c, frame.c: When creating a display object, added call to note_object_created(), for use with trapping_problems mechanism. When deleting, call check_allowed_operation() and note_object deleted(). The trapping-problems code records the objects created since the call-trapping-problems began. Those objects can be deleted, but none others (i.e. previously existing ones). bytecode.c, cmdloop.c: internal_catch takes another arg. eval.c: Add long comments describing the "five lists" used to maintain state (backtrace, gcpro, specbind, etc.) in the Lisp engine. backtrace.h, eval.c: Implement trapping-problems mechanism, eliminate old mechanisms or redo in terms of new one. frame.c, gutter.c: Flush out the concept of "critical display section", defined by the in_display() var. Use an internal_bind() to get it reset, rather than just doing it at end, because there may be a non-local exit. event-msw.c, event-stream.c, console-msw.h, device.c, dialog-msw.c, frame.c, frame.h, intl.c, toolbar.c, menubar-msw.c, redisplay.c, alloc.c, menubar-x.c: Make use of new trapping-errors stuff and rewrite code based on old mechanisms. glyphs-widget.c, redisplay.h: Protect calling Lisp in redisplay. insdel.c: Protect hooks against deleting existing buffers. frame-msw.c: Use EQ, not EQUAL in hash tables whose keys are just numbers. Otherwise we run into stickiness in redisplay because internal_equal() can QUIT. ================================================================ SIGNAL, C-G CHANGES ================================================================ Here we change the way that C-g interacts with event reading. The idea is that a C-g occurring while we're reading a user event should be read as C-g, but elsewhere should be a QUIT. The former code did all sorts of bizarreness -- requiring that no QUIT occurs anywhere in event-reading code (impossible to enforce given the stuff called or Lisp code invoked), and having some weird system involving enqueue/dequeue of a C-g and interaction with Vquit_flag -- and it didn't work. Now, we simply enclose all code where we want C-g read as an event with {begin/end}_dont_check_for_quit(). This completely turns off the mechanism that checks (and may remove or alter) C-g in the read-ahead queues, so we just get the C-g normal. Signal.c documents this very carefully. cmdloop.c: Correct use of dont_check_for_quit to new scheme, remove old out-of-date comments. event-stream.c: Fix C-g handling to actually work. device-x.c: Disable quit checking when err out. signal.c: Cleanup. Add large descriptive comment. process-unix.c, process-nt.c, sysdep.c: Use QUIT instead of REALLY_QUIT. It's not necessary to use REALLY_QUIT and just confuses the issue. lisp.h: Comment quit handlers. ================================================================ CONS CHANGES ================================================================ free_cons() now takes a Lisp_Object not the result of XCONS(). car and cdr have been renamed so that they don't get used directly; go through XCAR(), XCDR() instead. alloc.c, dired.c, editfns.c, emodules.c, fns.c, glyphs-msw.c, glyphs-x.c, glyphs.c, keymap.c, minibuf.c, search.c, eval.c, lread.c, lisp.h: Correct free_cons calling convention: now takes Lisp_Object, not Lisp_Cons chartab.c: Eliminate direct use of ->car, ->cdr, should be black box. callint.c: Rewrote using EXTERNAL_LIST_LOOP to avoid use of Lisp_Cons. ================================================================ USE INTERNAL-BIND-* ================================================================ eval.c: Cleanups of these funs. alloc.c, fileio.c, undo.c, specifier.c, text.c, profile.c, lread.c, redisplay.c, menubar-x.c, macros.c: Rewrote to use internal_bind_int() and internal_bind_lisp_object() in place of whatever varied and cumbersome mechanisms were formerly there. ================================================================ SPECBIND SANITY ================================================================ backtrace.h: - Improved comments backtrace.h, bytecode.c, eval.c: Add new mechanism check_specbind_stack_sanity() for sanity checking code each time the catchlist or specbind stack change. Removed older prototype of same mechanism. ================================================================ MISC ================================================================ lisp.h, insdel.c, window.c, device.c, console.c, buffer.c: Fleshed out authorship. device-msw.c: Correct bad Unicode-ization. print.c: Be more careful when not initialized or in fatal error handling. search.c: Eliminate running_asynch_code, an FSF holdover. alloc.c: Added comments about gc-cons-threshold. dialog-x.c: Use begin_gc_forbidden() around code to build up a widget value tree, like in menubar-x.c. gui.c: Use Qunbound not Qnil as the default for gethash. lisp-disunion.h, lisp-union.h: Added warnings on use of VOID_TO_LISP(). lisp.h: Use ERROR_CHECK_STRUCTURES to turn on ERROR_CHECK_TRAPPING_PROBLEMS and ERROR_CHECK_TYPECHECK lisp.h: Add assert_with_message. lisp.h: Add macros for gcproing entire arrays. (You could do this before but it required manual twiddling the gcpro structure.) lisp.h: Add prototypes for new functions defined elsewhere.
author ben
date Tue, 28 May 2002 08:45:36 +0000
parents e7ee5f8bde58
children b27b70c1252a
comparison
equal deleted inserted replaced
852:d83885ef293b 853:2b6fa2618f76
36 36
37 #define NEED_MSWINDOWS_SHLOBJ /* for IShellLink */ 37 #define NEED_MSWINDOWS_SHLOBJ /* for IShellLink */
38 38
39 #include <config.h> 39 #include <config.h>
40 #include "lisp.h" 40 #include "lisp.h"
41
42 #if defined (CYGWIN) && !defined (HAVE_MSG_SELECT)
43 #error We do not support non-select() versions (i.e. very old) of Cygwin.
44 #endif
45
46 /* Acceptable are:
47
48 WIN32_NATIVE and HAVE_WIN32_PROCESSES and nothing else
49
50 CYGWIN and HAVE_MSG_SELECT and HAVE_UNIX_PROCESSES and nothing else
51 */
52 #ifdef WIN32_NATIVE
53 # if !(defined (HAVE_WIN32_PROCESSES && !defined (HAVE_UNIX_PROCESSES) && !defined (HAVE_MSG_SELECT) && !defined (CYGWIN)))
54 # error Something is wrong with your process definitions for Windows native.
55 # endif
56 #elif defined (CYGWIN)
57 # if !(defined (HAVE_UNIX_PROCESSES) && defined (HAVE_MSG_SELECT) && !defined (HAVE_WIN32_PROCESSES) && !defined (WIN32_NATIVE))
58 # error Something is wrong with your process definitions for Cygwin.
59 # endif
60 #else
61 # error Something is wrong -- you are neither Windows native (possibly MinGW) nor Cygwin.
62 #endif
41 63
42 #include "buffer.h" 64 #include "buffer.h"
43 #include "device.h" 65 #include "device.h"
44 #include "events.h" 66 #include "events.h"
45 #include "faces.h" 67 #include "faces.h"
70 #include "sysfile.h" 92 #include "sysfile.h"
71 #include "sysproc.h" 93 #include "sysproc.h"
72 #include "systime.h" 94 #include "systime.h"
73 #include "syswait.h" 95 #include "syswait.h"
74 96
75 #ifdef HAVE_MSG_SELECT 97 #ifdef CYGWIN
76 #include "console-tty.h" 98 #include "console-tty.h"
77 #elif defined (CYGWIN)
78 typedef unsigned int SOCKET;
79 #endif 99 #endif
80 100
81 #ifdef HAVE_MENUBARS 101 #ifdef HAVE_MENUBARS
82 #define ADJR_MENUFLAG TRUE 102 #define ADJR_MENUFLAG TRUE
83 #else 103 #else
103 static int mswindows_handle_sticky_modifiers (WPARAM wParam, LPARAM lParam, 123 static int mswindows_handle_sticky_modifiers (WPARAM wParam, LPARAM lParam,
104 int downp, int keyp); 124 int downp, int keyp);
105 125
106 static struct event_stream *mswindows_event_stream; 126 static struct event_stream *mswindows_event_stream;
107 127
108 #ifdef HAVE_MSG_SELECT 128 #ifdef CYGWIN
129
109 extern SELECT_TYPE input_wait_mask, non_fake_input_wait_mask; 130 extern SELECT_TYPE input_wait_mask, non_fake_input_wait_mask;
110 extern SELECT_TYPE process_only_mask, tty_only_mask; 131 extern SELECT_TYPE process_only_mask, tty_only_mask;
111 SELECT_TYPE zero_mask; 132 SELECT_TYPE zero_mask;
112 extern int signal_event_pipe_initialized; 133 extern int signal_event_pipe_initialized;
113 int windows_fd; 134 int windows_fd;
135
136 #else
137
138 /* List of mswindows waitable handles. */
139 static HANDLE mswindows_waitable_handles[MAX_WAITABLE];
140
141 /* Number of wait handles */
142 static int mswindows_waitable_count = 0;
143
114 #endif 144 #endif
115 145
116 /* 146 /*
117 * Two separate queues, for efficiency, one (_u_) for user events, and 147 * Two separate queues, for efficiency, one (_u_) for user events, and
118 * another (_s_) for non-user ones. We always return events out of the 148 * another (_s_) for non-user ones. We always return events out of the
123 static Lisp_Object mswindows_s_dispatch_event_queue, mswindows_s_dispatch_event_queue_tail; 153 static Lisp_Object mswindows_s_dispatch_event_queue, mswindows_s_dispatch_event_queue_tail;
124 154
125 /* The number of things we can wait on */ 155 /* The number of things we can wait on */
126 #define MAX_WAITABLE (MAXIMUM_WAIT_OBJECTS - 1) 156 #define MAX_WAITABLE (MAXIMUM_WAIT_OBJECTS - 1)
127 157
128 #ifndef HAVE_MSG_SELECT
129 /* List of mswindows waitable handles. */
130 static HANDLE mswindows_waitable_handles[MAX_WAITABLE];
131
132 /* Number of wait handles */
133 static int mswindows_waitable_count=0;
134 #endif /* HAVE_MSG_SELECT */
135
136 /* Brush for painting widgets */ 158 /* Brush for painting widgets */
137 static HBRUSH widget_brush = 0; 159 static HBRUSH widget_brush = 0;
138 static LONG last_widget_brushed = 0; 160 static LONG last_widget_brushed = 0;
139 161
140 /* Count of quit chars currently in the queue */ 162 /* Count of quit chars currently in the queue */
157 WPARAM wParam, LPARAM lParam); 179 WPARAM wParam, LPARAM lParam);
158 #endif 180 #endif
159 181
160 /* This is the event signaled by the event pump. 182 /* This is the event signaled by the event pump.
161 See mswindows_pump_outstanding_events for comments */ 183 See mswindows_pump_outstanding_events for comments */
162 static Lisp_Object mswindows_error_caught_in_modal_loop; 184 static int mswindows_error_caught_in_modal_loop;
163 static int mswindows_in_modal_loop; 185 static int mswindows_in_modal_loop;
164 186
165 /* Count of wound timers */ 187 /* Count of wound timers */
166 static int mswindows_pending_timers_count; 188 static int mswindows_pending_timers_count;
167 189
168 static DWORD mswindows_last_mouse_button_state; 190 static DWORD mswindows_last_mouse_button_state;
191
169 192
193 #ifndef CYGWIN /* Skips past slurp, shove, or winsock streams */
194
170 /************************************************************************/ 195 /************************************************************************/
171 /* Pipe instream - reads process output */ 196 /* Pipe instream - reads process output */
172 /************************************************************************/ 197 /************************************************************************/
173 198
174 #define PIPE_READ_DELAY 20 199 #define PIPE_READ_DELAY 20
190 deallocated in this case, ntpipe_slurp_stream_shared_data are not. */ 215 deallocated in this case, ntpipe_slurp_stream_shared_data are not. */
191 216
192 struct ntpipe_slurp_stream_shared_data 217 struct ntpipe_slurp_stream_shared_data
193 { 218 {
194 HANDLE hev_thread; /* Our thread blocks on this, signaled by caller */ 219 HANDLE hev_thread; /* Our thread blocks on this, signaled by caller */
195 /* This is a manual-reset object. */ 220 /* This is a manual-reset object. */
196 HANDLE hev_caller; /* Caller blocks on this, and we signal it */ 221 HANDLE hev_caller; /* Caller blocks on this, and we signal it */
197 /* This is a manual-reset object. */ 222 /* This is a manual-reset object. */
198 HANDLE hev_unsleep; /* Pipe read delay is canceled if this is set */ 223 HANDLE hev_unsleep; /* Pipe read delay is canceled if this is set */
199 /* This is a manual-reset object. */ 224 /* This is a manual-reset object. */
200 HANDLE hpipe; /* Pipe read end handle. */ 225 HANDLE hpipe; /* Pipe read end handle. */
201 LONG die_p; /* Thread must exit ASAP if non-zero */ 226 LONG die_p; /* Thread must exit ASAP if non-zero */
202 BOOL eof_p : 1; /* Set when thread saw EOF */ 227 BOOL eof_p : 1; /* Set when thread saw EOF */
203 BOOL error_p : 1; /* Read error other than EOF/broken pipe */ 228 BOOL error_p : 1; /* Read error other than EOF/broken pipe */
204 BOOL inuse_p : 1; /* this structure is in use */ 229 BOOL inuse_p : 1; /* this structure is in use */
465 init_slurp_stream (void) 490 init_slurp_stream (void)
466 { 491 {
467 LSTREAM_HAS_METHOD (ntpipe_slurp, reader); 492 LSTREAM_HAS_METHOD (ntpipe_slurp, reader);
468 LSTREAM_HAS_METHOD (ntpipe_slurp, closer); 493 LSTREAM_HAS_METHOD (ntpipe_slurp, closer);
469 } 494 }
495
470 496
471 /************************************************************************/ 497 /************************************************************************/
472 /* Pipe outstream - writes process input */ 498 /* Pipe outstream - writes process input */
473 /************************************************************************/ 499 /************************************************************************/
474 500
479 505
480 struct ntpipe_shove_stream 506 struct ntpipe_shove_stream
481 { 507 {
482 LPARAM user_data; /* Any user data stored in the stream object */ 508 LPARAM user_data; /* Any user data stored in the stream object */
483 HANDLE hev_thread; /* Our thread blocks on this, signaled by caller */ 509 HANDLE hev_thread; /* Our thread blocks on this, signaled by caller */
484 /* This is an auto-reset object. */ 510 /* This is an auto-reset object. */
485 HANDLE hpipe; /* Pipe write end handle. */ 511 HANDLE hpipe; /* Pipe write end handle. */
486 HANDLE hthread; /* Reader thread handle. */ 512 HANDLE hthread; /* Reader thread handle. */
487 char buffer[MAX_SHOVE_BUFFER_SIZE]; /* Buffer being written */ 513 char buffer[MAX_SHOVE_BUFFER_SIZE]; /* Buffer being written */
488 DWORD size; /* Number of bytes to write */ 514 DWORD size; /* Number of bytes to write */
489 LONG die_p; /* Thread must exit ASAP if non-zero */ 515 LONG die_p; /* Thread must exit ASAP if non-zero */
492 BOOL blocking_p : 1;/* Last write attempt would cause blocking */ 518 BOOL blocking_p : 1;/* Last write attempt would cause blocking */
493 }; 519 };
494 520
495 DEFINE_LSTREAM_IMPLEMENTATION ("ntpipe-output", ntpipe_shove); 521 DEFINE_LSTREAM_IMPLEMENTATION ("ntpipe-output", ntpipe_shove);
496 522
497 #ifndef HAVE_MSG_SELECT
498 static DWORD WINAPI 523 static DWORD WINAPI
499 shove_thread (LPVOID vparam) 524 shove_thread (LPVOID vparam)
500 { 525 {
501 struct ntpipe_shove_stream *s = (struct ntpipe_shove_stream *) vparam; 526 struct ntpipe_shove_stream *s = (struct ntpipe_shove_stream *) vparam;
502 527
577 get_ntpipe_output_stream_param (Lstream *stream) 602 get_ntpipe_output_stream_param (Lstream *stream)
578 { 603 {
579 struct ntpipe_shove_stream *s = NTPIPE_SHOVE_STREAM_DATA(stream); 604 struct ntpipe_shove_stream *s = NTPIPE_SHOVE_STREAM_DATA(stream);
580 return s->user_data; 605 return s->user_data;
581 } 606 }
582 #endif
583 607
584 static Bytecount 608 static Bytecount
585 ntpipe_shove_writer (Lstream *stream, const unsigned char *data, 609 ntpipe_shove_writer (Lstream *stream, const unsigned char *data,
586 Bytecount size) 610 Bytecount size)
587 { 611 {
654 } 678 }
655 679
656 /************************************************************************/ 680 /************************************************************************/
657 /* Winsock I/O stream */ 681 /* Winsock I/O stream */
658 /************************************************************************/ 682 /************************************************************************/
659 #if defined (HAVE_SOCKETS) && !defined(HAVE_MSG_SELECT)
660 683
661 #define WINSOCK_READ_BUFFER_SIZE 1024 684 #define WINSOCK_READ_BUFFER_SIZE 1024
662 685
663 struct winsock_stream 686 struct winsock_stream
664 { 687 {
881 LSTREAM_HAS_METHOD (winsock, reader); 904 LSTREAM_HAS_METHOD (winsock, reader);
882 LSTREAM_HAS_METHOD (winsock, writer); 905 LSTREAM_HAS_METHOD (winsock, writer);
883 LSTREAM_HAS_METHOD (winsock, closer); 906 LSTREAM_HAS_METHOD (winsock, closer);
884 LSTREAM_HAS_METHOD (winsock, was_blocked_p); 907 LSTREAM_HAS_METHOD (winsock, was_blocked_p);
885 } 908 }
886 #endif /* defined (HAVE_SOCKETS) */ 909 #endif /* ! CYGWIN */
887 910
888 /************************************************************************/ 911 /************************************************************************/
889 /* Dispatch queue management */ 912 /* Dispatch queue management */
890 /************************************************************************/ 913 /************************************************************************/
891 914
1102 previous_event = event; 1125 previous_event = event;
1103 } 1126 }
1104 return Qnil; 1127 return Qnil;
1105 } 1128 }
1106 1129
1107 #ifndef HAVE_MSG_SELECT 1130 #ifndef CYGWIN
1108 /************************************************************************/ 1131 /************************************************************************/
1109 /* Waitable handles manipulation */ 1132 /* Waitable handles manipulation */
1110 /************************************************************************/ 1133 /************************************************************************/
1111 static int 1134 static int
1112 find_waitable_handle (HANDLE h) 1135 find_waitable_handle (HANDLE h)
1138 return; 1161 return;
1139 1162
1140 mswindows_waitable_handles [ix] = 1163 mswindows_waitable_handles [ix] =
1141 mswindows_waitable_handles [--mswindows_waitable_count]; 1164 mswindows_waitable_handles [--mswindows_waitable_count];
1142 } 1165 }
1143 #endif /* HAVE_MSG_SELECT */ 1166
1167 #endif /* CYGWIN */
1144 1168
1145 /* 1169 /*
1146 * Given a lisp process pointer remove the corresponding process handle 1170 * Given a lisp process pointer remove the corresponding process handle
1147 * from mswindows_waitable_handles if it is in it. Normally the handle is 1171 * from mswindows_waitable_handles if it is in it. Normally the handle is
1148 * removed when the process terminates, but if the lisp process structure 1172 * removed when the process terminates, but if the lisp process structure
1150 * handle since it will be invalid and will cause the wait to fail 1174 * handle since it will be invalid and will cause the wait to fail
1151 */ 1175 */
1152 void 1176 void
1153 mswindows_unwait_process (Lisp_Process *p) 1177 mswindows_unwait_process (Lisp_Process *p)
1154 { 1178 {
1155 #ifndef HAVE_MSG_SELECT 1179 #ifndef CYGWIN
1156 remove_waitable_handle (get_nt_process_handle (p)); 1180 remove_waitable_handle (get_nt_process_handle (p));
1157 #endif /* HAVE_MSG_SELECT */ 1181 #endif /* CYGWIN */
1158 } 1182 }
1159 1183
1160 1184
1161 /************************************************************************/ 1185 /************************************************************************/
1162 /* Event pump */ 1186 /* Event pump */
1175 return 0; 1199 return 0;
1176 1200
1177 return !ascii_strcasecmp (class_name_buf, XEMACS_CLASS); 1201 return !ascii_strcasecmp (class_name_buf, XEMACS_CLASS);
1178 } 1202 }
1179 1203
1204 struct mswindows_protect_modal_loop
1205 {
1206 Lisp_Object (*bfun) (Lisp_Object barg);
1207 Lisp_Object barg;
1208 };
1209
1180 static Lisp_Object 1210 static Lisp_Object
1181 mswindows_modal_loop_error_handler (Lisp_Object cons_sig_data, 1211 mswindows_protect_modal_loop_1 (void *gack)
1182 Lisp_Object u_n_u_s_e_d) 1212 {
1183 { 1213 struct mswindows_protect_modal_loop *gata =
1184 mswindows_error_caught_in_modal_loop = cons_sig_data; 1214 (struct mswindows_protect_modal_loop *) gack;
1185 return Qunbound; 1215
1216 return (gata->bfun) (gata->barg);
1186 } 1217 }
1187 1218
1188 Lisp_Object 1219 Lisp_Object
1189 mswindows_protect_modal_loop (Lisp_Object (*bfun) (Lisp_Object barg), 1220 mswindows_protect_modal_loop (const char *error_string,
1190 Lisp_Object barg) 1221 Lisp_Object (*bfun) (Lisp_Object barg),
1222 Lisp_Object barg, int flags)
1191 { 1223 {
1192 Lisp_Object tmp; 1224 Lisp_Object tmp;
1225 struct mswindows_protect_modal_loop bluh;
1226
1227 bluh.bfun = bfun;
1228 bluh.barg = barg;
1193 1229
1194 ++mswindows_in_modal_loop; 1230 ++mswindows_in_modal_loop;
1195 tmp = condition_case_1 (Qt, 1231 tmp = call_trapping_problems (Qevent, error_string,
1196 bfun, barg, 1232 flags, 0,
1197 mswindows_modal_loop_error_handler, Qnil); 1233 mswindows_protect_modal_loop_1, &bluh);
1234 if (UNBOUNDP (tmp))
1235 mswindows_error_caught_in_modal_loop = 1;
1198 --mswindows_in_modal_loop; 1236 --mswindows_in_modal_loop;
1199 1237
1200 return tmp; 1238 return tmp;
1201 } 1239 }
1202 1240
1203 void 1241 void
1204 mswindows_unmodalize_signal_maybe (void) 1242 mswindows_unmodalize_signal_maybe (void)
1205 { 1243 {
1206 if (!NILP (mswindows_error_caught_in_modal_loop)) 1244 mswindows_error_caught_in_modal_loop = 0;
1207 {
1208 /* Got an error while messages were pumped while
1209 in window procedure - have to resignal */
1210 Lisp_Object sym = XCAR (mswindows_error_caught_in_modal_loop);
1211 Lisp_Object data = XCDR (mswindows_error_caught_in_modal_loop);
1212 mswindows_error_caught_in_modal_loop = Qnil;
1213 Fsignal (sym, data);
1214 }
1215 } 1245 }
1216 1246
1217 /* 1247 /*
1218 * This is an unsafe part of event pump, guarded by 1248 * This is an unsafe part of event pump, guarded by
1219 * condition_case. See mswindows_pump_outstanding_events 1249 * condition_case. See mswindows_pump_outstanding_events
1257 * module local variable mswindows_in_modal_loop to nonzero. 1287 * module local variable mswindows_in_modal_loop to nonzero.
1258 * 1288 *
1259 * Return value is Qt if no errors was trapped, or Qunbound if 1289 * Return value is Qt if no errors was trapped, or Qunbound if
1260 * there was an error. 1290 * there was an error.
1261 * 1291 *
1262 * In case of error, a cons representing the error, in the 1292 * In case of error, a warning is issued and the module local variable
1263 * form (SIGNAL . DATA), is stored in the module local variable 1293 * mswindows_error_caught_in_modal_loop is set to non-zero. Thus,
1264 * mswindows_error_caught_in_modal_loop. This error is signaled 1294 * Windows internal modal loops are protected against throws, which
1265 * again when DispatchMessage returns. Thus, Windows internal 1295 * are proven to corrupt internal Windows structures.
1266 * modal loops are protected against throws, which are proven
1267 * to corrupt internal Windows structures.
1268 * 1296 *
1269 * In case of success, mswindows_error_caught_in_modal_loop is 1297 * In case of success, mswindows_error_caught_in_modal_loop is
1270 * assigned Qnil. 1298 * assigned 0.
1271 * 1299 *
1272 * If the value of mswindows_error_caught_in_modal_loop is not 1300 * If the value of mswindows_error_caught_in_modal_loop is not
1273 * nil already upon entry, the function just returns non-nil. 1301 * zero already upon entry, the function just returns non-nil.
1274 * This situation means that a new event has been queued while 1302 * This situation means that a new event has been queued while
1275 * in cancel mode. The event will be dequeued on the next regular 1303 * in cancel mode. The event will be dequeued on the next regular
1276 * call of next-event; the pump is off since error is caught. 1304 * call of next-event; the pump is off since error is caught.
1277 * The caller must *unconditionally* cancel modal loop if the 1305 * The caller must *unconditionally* cancel modal loop if the
1278 * value returned by this function is nil. Otherwise, everything 1306 * value returned by this function is nil. Otherwise, everything
1279 * will become frozen until the modal loop exits under normal 1307 * will become frozen until the modal loop exits under normal
1280 * condition (scrollbar drag is released, menu closed etc.) 1308 * condition (scrollbar drag is released, menu closed etc.) */
1281 */
1282 Lisp_Object 1309 Lisp_Object
1283 mswindows_pump_outstanding_events (void) 1310 mswindows_pump_outstanding_events (void)
1284 { 1311 {
1285 /* This function can call lisp */ 1312 /* This function can call lisp */
1286 1313
1287 Lisp_Object result = Qt; 1314 Lisp_Object result = Qt;
1288 struct gcpro gcpro1; 1315 struct gcpro gcpro1;
1289 GCPRO1 (result); 1316 GCPRO1 (result);
1290 1317
1291 if (NILP(mswindows_error_caught_in_modal_loop)) 1318 if (!mswindows_error_caught_in_modal_loop)
1292 result = mswindows_protect_modal_loop (mswindows_unsafe_pump_events, Qnil); 1319 result = mswindows_protect_modal_loop
1320 ("Error during event handling", mswindows_unsafe_pump_events, Qnil, 0);
1293 UNGCPRO; 1321 UNGCPRO;
1294 return result; 1322 return result;
1295 } 1323 }
1296 1324
1297 /* 1325 /*
1407 mswindows_need_event (int badly_p) 1435 mswindows_need_event (int badly_p)
1408 { 1436 {
1409 while (NILP (mswindows_u_dispatch_event_queue) 1437 while (NILP (mswindows_u_dispatch_event_queue)
1410 && NILP (mswindows_s_dispatch_event_queue)) 1438 && NILP (mswindows_s_dispatch_event_queue))
1411 { 1439 {
1412 #ifdef HAVE_MSG_SELECT 1440 #ifdef CYGWIN
1413 int i; 1441 int i;
1414 int active; 1442 int active;
1415 SELECT_TYPE temp_mask = input_wait_mask; 1443 SELECT_TYPE temp_mask = input_wait_mask;
1416 EMACS_TIME sometime; 1444 EMACS_TIME sometime;
1417 EMACS_SELECT_TIME select_time_to_block, *pointer_to_this; 1445 EMACS_SELECT_TIME select_time_to_block, *pointer_to_this;
1504 } 1532 }
1505 else 1533 else
1506 { 1534 {
1507 assert(0); 1535 assert(0);
1508 } 1536 }
1509 #else /* not HAVE_MSG_SELECT */ 1537 #else /* not CYGWIN */
1510 /* Now try getting a message or process event */ 1538 /* Now try getting a message or process event */
1511 DWORD active; 1539 DWORD active;
1512 DWORD what_events; 1540 DWORD what_events;
1513 if (mswindows_in_modal_loop) 1541 if (mswindows_in_modal_loop)
1514 /* In a modal loop, only look for timer events, and only if 1542 /* In a modal loop, only look for timer events, and only if
1590 The value of this entry is a keyboard scan code. The default 1618 The value of this entry is a keyboard scan code. The default
1591 value, 0x0, represents the F12 key on a 101-key keyboard or the - 1619 value, 0x0, represents the F12 key on a 101-key keyboard or the -
1592 (hyphen, VK_SUBTRACT) key on an 82-key keyboard. 1620 (hyphen, VK_SUBTRACT) key on an 82-key keyboard.
1593 */ 1621 */
1594 1622
1595 __try 1623 __try
1596 { 1624 {
1597 active = MsgWaitForMultipleObjects (mswindows_waitable_count, 1625 active = MsgWaitForMultipleObjects (mswindows_waitable_count,
1598 mswindows_waitable_handles, 1626 mswindows_waitable_handles,
1599 FALSE, badly_p ? INFINITE : 0, 1627 FALSE, badly_p ? INFINITE : 0,
1600 what_events); 1628 what_events);
1601 } 1629 }
1602 __except (GetExceptionCode () == EXCEPTION_BREAKPOINT ? 1630 __except (GetExceptionCode () == EXCEPTION_BREAKPOINT ?
1603 EXCEPTION_CONTINUE_EXECUTION : 1631 EXCEPTION_CONTINUE_EXECUTION :
1604 EXCEPTION_CONTINUE_SEARCH) 1632 EXCEPTION_CONTINUE_SEARCH)
1605 { 1633 {
1606 } 1634 }
1607 1635
1608 /* This will assert if handle being waited for becomes abandoned. 1636 /* This will assert if handle being waited for becomes abandoned.
1609 Not the case currently tho */ 1637 Not the case currently tho */
1610 assert ((!badly_p && active == WAIT_TIMEOUT) || 1638 assert ((!badly_p && active == WAIT_TIMEOUT) ||
1611 (active >= WAIT_OBJECT_0 && 1639 (active >= WAIT_OBJECT_0 &&
1627 else 1655 else
1628 { 1656 {
1629 int ix = active - WAIT_OBJECT_0; 1657 int ix = active - WAIT_OBJECT_0;
1630 /* First, try to find which process' output has signaled */ 1658 /* First, try to find which process' output has signaled */
1631 Lisp_Process *p = 1659 Lisp_Process *p =
1632 get_process_from_usid (HANDLE_TO_USID (mswindows_waitable_handles[ix])); 1660 get_process_from_usid (HANDLE_TO_USID
1661 (mswindows_waitable_handles[ix]));
1633 if (p != NULL) 1662 if (p != NULL)
1634 { 1663 {
1635 /* Found a signaled process input handle */ 1664 /* Found a signaled process input handle */
1636 mswindows_enqueue_process_event (p); 1665 mswindows_enqueue_process_event (p);
1637 } 1666 }
1650 kick_status_notify (); 1679 kick_status_notify ();
1651 /* We need to return a process event here so that 1680 /* We need to return a process event here so that
1652 (1) accept-process-output will return when called on this 1681 (1) accept-process-output will return when called on this
1653 process, and (2) status notifications will happen in 1682 process, and (2) status notifications will happen in
1654 accept-process-output, sleep-for, and sit-for. */ 1683 accept-process-output, sleep-for, and sit-for. */
1655 /* #### horrible kludge till my real process fixes go in.
1656 #### Replaced with a slightly less horrible kluge that
1657 at least finds the right process instead of axing the
1658 first one on the list.
1659 */
1660 if (!NILP (vproctail)) 1684 if (!NILP (vproctail))
1685 mswindows_enqueue_process_event (XPROCESS (vaffanculo));
1686 else
1661 { 1687 {
1662 mswindows_enqueue_process_event (XPROCESS (vaffanculo)); 1688 /* abort (); */
1689 /* #### FUCKME! When can this happen? I hit this abort()
1690 when I tried enabling it. */
1691 /* Have to return something: there may be no accompanying
1692 process event */
1693 mswindows_enqueue_magic_event (NULL, XM_BUMPQUEUE);
1663 } 1694 }
1664 else /* trash me soon. */
1665 /* Have to return something: there may be no accompanying
1666 process event */
1667 mswindows_enqueue_magic_event (NULL, XM_BUMPQUEUE);
1668 } 1695 }
1669 } 1696 }
1670 #endif /* not HAVE_MSG_SELECT */ 1697 #endif /* not CYGWIN */
1671 } /* while */ 1698 } /* while */
1672 } 1699 }
1673 1700
1674 /************************************************************************/ 1701 /************************************************************************/
1675 /* Event generators */ 1702 /* Event generators */
1713 { 1740 {
1714 switch (uType) 1741 switch (uType)
1715 { 1742 {
1716 case XTYP_CONNECT: 1743 case XTYP_CONNECT:
1717 if (!DdeCmpStringHandles (hszTopic, mswindows_dde_topic_system)) 1744 if (!DdeCmpStringHandles (hszTopic, mswindows_dde_topic_system))
1718 return (HDDEDATA)TRUE; 1745 return (HDDEDATA) TRUE;
1719 return (HDDEDATA)FALSE; 1746 return (HDDEDATA) FALSE;
1720 1747
1721 case XTYP_WILDCONNECT: 1748 case XTYP_WILDCONNECT:
1722 { 1749 {
1723 /* We only support one {service,topic} pair */ 1750 /* We only support one {service,topic} pair */
1724 HSZPAIR pairs[2] = 1751 HSZPAIR pairs[2] =
1727 1754
1728 if (!(hszItem 1755 if (!(hszItem
1729 || DdeCmpStringHandles (hszItem, mswindows_dde_service)) && 1756 || DdeCmpStringHandles (hszItem, mswindows_dde_service)) &&
1730 !(hszTopic 1757 !(hszTopic
1731 || DdeCmpStringHandles (hszTopic, mswindows_dde_topic_system))) 1758 || DdeCmpStringHandles (hszTopic, mswindows_dde_topic_system)))
1732 return (DdeCreateDataHandle (mswindows_dde_mlid, (LPBYTE)pairs, 1759 return (DdeCreateDataHandle (mswindows_dde_mlid, (LPBYTE) pairs,
1733 sizeof (pairs), 0L, 0, uFmt, 0)); 1760 sizeof (pairs), 0L, 0, uFmt, 0));
1734 } 1761 }
1735 return (HDDEDATA)NULL; 1762 return (HDDEDATA) NULL;
1736 1763
1737 case XTYP_EXECUTE: 1764 case XTYP_EXECUTE:
1738 if (!mswindows_dde_enable) 1765 if (!mswindows_dde_enable)
1739 return (HDDEDATA) DDE_FBUSY; 1766 return (HDDEDATA) DDE_FBUSY;
1740 1767
1741 if (!DdeCmpStringHandles (hszTopic, mswindows_dde_topic_system)) 1768 if (!DdeCmpStringHandles (hszTopic, mswindows_dde_topic_system))
1742 { 1769 {
1743 DWORD len = DdeGetData (hdata, NULL, 0, 0); 1770 DWORD len = DdeGetData (hdata, NULL, 0, 0);
1744 LPBYTE extcmd = (LPBYTE) ALLOCA (len+1); 1771 LPBYTE extcmd = (LPBYTE) ALLOCA (len + 1);
1745 Intbyte *cmd; 1772 Intbyte *cmd;
1746 Intbyte *end; 1773 Intbyte *end;
1747 struct gcpro gcpro1, gcpro2; 1774 struct gcpro gcpro1, gcpro2;
1748 Lisp_Object l_dndlist = Qnil; 1775 Lisp_Object l_dndlist = Qnil;
1749 Lisp_Object emacs_event = Fmake_event (Qnil, Qnil); 1776 Lisp_Object emacs_event = Fmake_event (Qnil, Qnil);
2195 goto defproc; 2222 goto defproc;
2196 return 1; 2223 return 1;
2197 2224
2198 case WM_CLOSE: 2225 case WM_CLOSE:
2199 fobj = mswindows_find_frame (hwnd); 2226 fobj = mswindows_find_frame (hwnd);
2200 mswindows_enqueue_misc_user_event (fobj, Qeval, list3 (Qdelete_frame, fobj, Qt)); 2227 mswindows_enqueue_misc_user_event (fobj, Qeval, list3 (Qdelete_frame, fobj,
2228 Qt));
2201 break; 2229 break;
2202 2230
2203 case WM_KEYUP: 2231 case WM_KEYUP:
2204 case WM_SYSKEYUP: 2232 case WM_SYSKEYUP:
2205 2233
3161 HWND hwndScrollBar = (HWND) lParam; 3189 HWND hwndScrollBar = (HWND) lParam;
3162 struct gcpro gcpro1, gcpro2; 3190 struct gcpro gcpro1, gcpro2;
3163 3191
3164 mswindows_handle_scrollbar_event (hwndScrollBar, code, pos); 3192 mswindows_handle_scrollbar_event (hwndScrollBar, code, pos);
3165 GCPRO2 (emacs_event, fobj); 3193 GCPRO2 (emacs_event, fobj);
3166 if (UNBOUNDP (mswindows_pump_outstanding_events())) /* Can GC */ 3194 if (UNBOUNDP (mswindows_pump_outstanding_events ())) /* Can GC */
3167 { 3195 {
3168 /* Error during event pumping - cancel scroll */ 3196 /* Error during event pumping - cancel scroll */
3169 qxeSendMessage (hwndScrollBar, WM_CANCELMODE, 0, 0); 3197 qxeSendMessage (hwndScrollBar, WM_CANCELMODE, 0, 0);
3170 } 3198 }
3171 UNGCPRO; 3199 UNGCPRO;
3295 } 3323 }
3296 } 3324 }
3297 goto defproc; 3325 goto defproc;
3298 3326
3299 #ifdef HAVE_DRAGNDROP 3327 #ifdef HAVE_DRAGNDROP
3300 case WM_DROPFILES: /* implementation ripped-off from event-Xt.c */ 3328 case WM_DROPFILES: /* implementation ripped-off from event-Xt.c */
3301 { 3329 {
3302 UINT filecount, i; 3330 UINT filecount, i;
3303 POINT point; 3331 POINT point;
3304 3332
3305 Lisp_Object l_dndlist = Qnil, l_item = Qnil; 3333 Lisp_Object l_dndlist = Qnil, l_item = Qnil;
3309 event = XEVENT (emacs_event); 3337 event = XEVENT (emacs_event);
3310 3338
3311 GCPRO3 (emacs_event, l_dndlist, l_item); 3339 GCPRO3 (emacs_event, l_dndlist, l_item);
3312 3340
3313 if (!DragQueryPoint ((HDROP) wParam, &point)) 3341 if (!DragQueryPoint ((HDROP) wParam, &point))
3314 point.x = point.y = -1; /* outside client area */ 3342 point.x = point.y = -1; /* outside client area */
3315 3343
3316 event->event_type = misc_user_event; 3344 event->event_type = misc_user_event;
3317 event->channel = mswindows_find_frame (hwnd); 3345 event->channel = mswindows_find_frame (hwnd);
3318 event->timestamp = GetMessageTime(); 3346 event->timestamp = GetMessageTime();
3319 event->event.misc.button = 1; /* #### Should try harder */ 3347 event->event.misc.button = 1; /* #### Should try harder */
4093 default: 4121 default:
4094 assert(0); 4122 assert(0);
4095 } 4123 }
4096 } 4124 }
4097 4125
4098 #ifndef HAVE_MSG_SELECT 4126 #ifndef CYGWIN
4127
4099 static HANDLE 4128 static HANDLE
4100 get_process_input_waitable (Lisp_Process *process) 4129 get_process_input_waitable (Lisp_Process *process)
4101 { 4130 {
4102 Lisp_Object instr, outstr, p; 4131 Lisp_Object instr, outstr, errstr, p;
4103 p = wrap_process (process); 4132 p = wrap_process (process);
4104 get_process_streams (process, &instr, &outstr); 4133 get_process_streams (process, &instr, &outstr, &errstr);
4105 assert (!NILP (instr)); 4134 assert (!NILP (instr));
4106 #if defined (HAVE_SOCKETS) && !defined(HAVE_MSG_SELECT)
4107 return (network_connection_p (p) 4135 return (network_connection_p (p)
4108 ? get_winsock_stream_waitable (XLSTREAM (instr)) 4136 ? get_winsock_stream_waitable (XLSTREAM (instr))
4109 : get_ntpipe_input_stream_waitable (XLSTREAM (instr))); 4137 : get_ntpipe_input_stream_waitable (XLSTREAM (instr)));
4138 }
4139
4140 static HANDLE
4141 get_process_stderr_waitable (Lisp_Process *process)
4142 {
4143 Lisp_Object instr, outstr, errstr;
4144 get_process_streams (process, &instr, &outstr, &errstr);
4145 if (NILP (errstr))
4146 return INVALID_HANDLE_VALUE;
4147 return get_ntpipe_input_stream_waitable (XLSTREAM (errstr));
4148 }
4149
4150 #endif /* not CYGWIN */
4151
4152 static void
4153 emacs_mswindows_select_process (Lisp_Process *process, int doin, int doerr)
4154 {
4155 #ifdef CYGWIN
4156 int infd, errfd;
4157
4158 event_stream_unixoid_select_process (process, doin, doerr, &infd, &errfd);
4110 #else 4159 #else
4111 return get_ntpipe_input_stream_waitable (XLSTREAM (instr)); 4160 HANDLE hev = INVALID_HANDLE_VALUE;
4112 #endif 4161 HANDLE herr = INVALID_HANDLE_VALUE;
4113 } 4162
4114 4163 if (doin)
4115 static void 4164 {
4116 emacs_mswindows_select_process (Lisp_Process *process) 4165 hev = get_process_input_waitable (process);
4117 { 4166 if (!add_waitable_handle (hev))
4118 HANDLE hev = get_process_input_waitable (process); 4167 {
4119 4168 hev = INVALID_HANDLE_VALUE;
4120 if (!add_waitable_handle (hev)) 4169 goto err;
4121 invalid_operation ("Too many active processes", Qunbound); 4170 }
4122 4171 }
4123 #ifdef HAVE_WIN32_PROCESSES 4172
4173 if (doerr)
4174 {
4175 herr = get_process_stderr_waitable (process);
4176 if (herr != INVALID_HANDLE_VALUE && !add_waitable_handle (herr))
4177 {
4178 herr = INVALID_HANDLE_VALUE;
4179 goto err;
4180 }
4181 }
4182
4124 { 4183 {
4184 /* Also select on the process handle itself, so we can receive
4185 exit notifications. Only do this once, not each time this
4186 function is called (which can happen many times, e.g. if
4187 (set-process-filter proc t) is called and then a process filter
4188 is set again). It will be unselected in mswindows_need_event(). */
4125 Lisp_Object p = wrap_process (process); 4189 Lisp_Object p = wrap_process (process);
4126 4190
4127 if (!network_connection_p (p)) 4191 if (!network_connection_p (p))
4128 { 4192 {
4129 HANDLE hprocess = get_nt_process_handle (process); 4193 HANDLE hprocess = get_nt_process_handle_only_first_time (process);
4130 if (!add_waitable_handle (hprocess)) 4194 if (hprocess != INVALID_HANDLE_VALUE
4131 { 4195 && !add_waitable_handle (hprocess))
4132 remove_waitable_handle (hev); 4196 goto err;
4133 invalid_operation ("Too many active processes", Qunbound);
4134 }
4135 } 4197 }
4136 } 4198 }
4137 #endif 4199
4200 return;
4201
4202 err:
4203 if (hev != INVALID_HANDLE_VALUE)
4204 remove_waitable_handle (hev);
4205 if (herr != INVALID_HANDLE_VALUE)
4206 remove_waitable_handle (herr);
4207 invalid_operation ("Too many active processes", wrap_process (process));
4208 #endif /* CYGWIN */
4138 } 4209 }
4139 4210
4140 static void 4211 static void
4141 emacs_mswindows_unselect_process (Lisp_Process *process) 4212 emacs_mswindows_unselect_process (Lisp_Process *process, int doin, int doerr)
4142 { 4213 {
4143 /* Process handle is removed in the event loop as soon 4214 #ifdef CYGWIN
4144 as it is signaled, so don't bother here about it */ 4215 int infd, errfd;
4145 HANDLE hev = get_process_input_waitable (process); 4216
4146 remove_waitable_handle (hev); 4217 event_stream_unixoid_unselect_process (process, doin, doerr, &infd, &errfd);
4147 } 4218 #else
4148 #endif /* HAVE_MSG_SELECT */ 4219 if (doin)
4220 {
4221 /* Process handle is removed in the event loop as soon
4222 as it is signaled, so don't bother here about it */
4223 HANDLE hev = get_process_input_waitable (process);
4224 remove_waitable_handle (hev);
4225 }
4226 if (doerr)
4227 {
4228 /* Process handle is removed in the event loop as soon
4229 as it is signaled, so don't bother here about it */
4230 HANDLE herr = get_process_stderr_waitable (process);
4231 if (herr != INVALID_HANDLE_VALUE)
4232 remove_waitable_handle (herr);
4233 }
4234 #endif /* CYGWIN */
4235 }
4149 4236
4150 static void 4237 static void
4151 emacs_mswindows_select_console (struct console *con) 4238 emacs_mswindows_select_console (struct console *con)
4152 { 4239 {
4153 #ifdef HAVE_MSG_SELECT 4240 #ifdef CYGWIN
4154 if (CONSOLE_MSWINDOWS_P (con)) 4241 if (CONSOLE_MSWINDOWS_P (con))
4155 return; /* mswindows consoles are automatically selected */ 4242 return; /* mswindows consoles are automatically selected */
4156 4243
4157 event_stream_unixoid_select_console (con); 4244 event_stream_unixoid_select_console (con);
4158 #endif 4245 #endif
4159 } 4246 }
4160 4247
4161 static void 4248 static void
4162 emacs_mswindows_unselect_console (struct console *con) 4249 emacs_mswindows_unselect_console (struct console *con)
4163 { 4250 {
4164 #ifdef HAVE_MSG_SELECT 4251 #ifdef CYGWIN
4165 if (CONSOLE_MSWINDOWS_P (con)) 4252 if (CONSOLE_MSWINDOWS_P (con))
4166 return; /* mswindows consoles are automatically selected */ 4253 return; /* mswindows consoles are automatically selected */
4167 4254
4168 event_stream_unixoid_unselect_console (con); 4255 event_stream_unixoid_unselect_console (con);
4169 #endif 4256 #endif
4207 4294
4208 Vquit_flag = critical_p ? Qcritical : Qt; 4295 Vquit_flag = critical_p ? Qcritical : Qt;
4209 } 4296 }
4210 } 4297 }
4211 4298
4212 USID 4299 static void
4213 emacs_mswindows_create_stream_pair (void *inhandle, void *outhandle, 4300 emacs_mswindows_create_io_streams (void *inhandle, void *outhandle,
4214 Lisp_Object *instream, 4301 void *errhandle, Lisp_Object *instream,
4215 Lisp_Object *outstream, 4302 Lisp_Object *outstream,
4216 int flags) 4303 Lisp_Object *errstream,
4217 { 4304 USID *in_usid,
4305 USID *err_usid,
4306 int flags)
4307 {
4308 #ifdef CYGWIN
4309 event_stream_unixoid_create_io_streams (inhandle, outhandle,
4310 errhandle, instream,
4311 outstream, errstream,
4312 in_usid, err_usid, flags);
4313 #else
4218 /* Handles for streams */ 4314 /* Handles for streams */
4219 HANDLE hin, hout; 4315 HANDLE hin, hout, herr;
4220 /* fds. These just stored along with the streams, and are closed in 4316 /* fds. These just stored along with the streams, and are closed in
4221 delete stream pair method, because we need to handle fake unices 4317 delete stream pair method, because we need to handle fake unices
4222 here. */ 4318 here. */
4223 int fdi, fdo; 4319 int fdi, fdo, fde;
4224 4320
4225 /* Decode inhandle and outhandle. Their meaning depends on 4321 /* Decode inhandle, outhandle, errhandle. Their meaning depends on
4226 the process implementation being used. */ 4322 the process implementation being used. */
4227 #if defined (HAVE_WIN32_PROCESSES)
4228 /* We're passed in Windows handles. That's what we like most... */
4229 hin = (HANDLE) inhandle; 4323 hin = (HANDLE) inhandle;
4230 hout = (HANDLE) outhandle; 4324 hout = (HANDLE) outhandle;
4231 fdi = fdo = -1; 4325 if (errhandle == (void *) -1)
4232 #elif defined (HAVE_UNIX_PROCESSES) 4326 herr = INVALID_HANDLE_VALUE;
4233 /* We are passed UNIX fds. This must be Cygwin. 4327 else
4234 Fetch os handles */ 4328 herr = (HANDLE) errhandle;
4235 hin = inhandle >= 0 ? (HANDLE)get_osfhandle ((int)inhandle) : INVALID_HANDLE_VALUE; 4329 fdi = fdo = fde = -1;
4236 hout = outhandle >= 0 ? (HANDLE)get_osfhandle ((int)outhandle) : INVALID_HANDLE_VALUE;
4237 fdi=(int)inhandle;
4238 fdo=(int)outhandle;
4239 #else
4240 #error "So, WHICH kind of processes do you want?"
4241 #endif
4242 4330
4243 *instream = (hin == INVALID_HANDLE_VALUE 4331 *instream = (hin == INVALID_HANDLE_VALUE
4244 ? Qnil 4332 ? Qnil
4245 #if defined (HAVE_SOCKETS) && !defined (HAVE_MSG_SELECT)
4246 : flags & STREAM_NETWORK_CONNECTION 4333 : flags & STREAM_NETWORK_CONNECTION
4247 ? make_winsock_input_stream ((SOCKET)hin, fdi) 4334 ? make_winsock_input_stream ((SOCKET) hin, fdi)
4248 #endif
4249 : make_ntpipe_input_stream (hin, fdi)); 4335 : make_ntpipe_input_stream (hin, fdi));
4250 4336
4251 #ifdef HAVE_WIN32_PROCESSES 4337 *errstream = (herr == INVALID_HANDLE_VALUE
4338 ? Qnil
4339 : make_ntpipe_input_stream (herr, fde));
4340
4252 *outstream = (hout == INVALID_HANDLE_VALUE 4341 *outstream = (hout == INVALID_HANDLE_VALUE
4253 ? Qnil 4342 ? Qnil
4254 #if defined (HAVE_SOCKETS) && !defined (HAVE_MSG_SELECT)
4255 : flags & STREAM_NETWORK_CONNECTION 4343 : flags & STREAM_NETWORK_CONNECTION
4256 ? make_winsock_output_stream ((SOCKET)hout, fdo) 4344 ? make_winsock_output_stream ((SOCKET)hout, fdo)
4257 #endif
4258 : make_ntpipe_output_stream (hout, fdo)); 4345 : make_ntpipe_output_stream (hout, fdo));
4259 #elif defined (HAVE_UNIX_PROCESSES) 4346
4260 *outstream = (fdo >= 0 4347 *in_usid =
4261 ? make_filedesc_output_stream (fdo, 0, -1, LSTR_BLOCKED_OK) 4348 (NILP (*instream)
4262 : Qnil); 4349 ? USID_ERROR
4263 4350 : flags & STREAM_NETWORK_CONNECTION
4264 #if defined(HAVE_UNIX_PROCESSES) 4351 ? HANDLE_TO_USID (get_winsock_stream_waitable (XLSTREAM (*instream)))
4265 /* FLAGS is process->pty_flag for UNIX_PROCESSES */ 4352 : HANDLE_TO_USID (get_ntpipe_input_stream_waitable (XLSTREAM
4266 if ((flags & STREAM_PTY_FLUSHING) && fdo >= 0) 4353 (*instream))));
4267 { 4354
4268 Intbyte eof_char = get_eof_char (fdo); 4355 *err_usid =
4269 int pty_max_bytes = get_pty_max_bytes (fdo); 4356 (NILP (*errstream)
4270 filedesc_stream_set_pty_flushing (XLSTREAM(*outstream), pty_max_bytes, eof_char); 4357 ? USID_DONTHASH
4271 } 4358 : HANDLE_TO_USID (get_ntpipe_input_stream_waitable (XLSTREAM
4272 #endif 4359 (*errstream))));
4273 #endif 4360 #endif /* CYGWIN */
4274 4361 }
4275 return (NILP (*instream) 4362
4276 ? USID_ERROR 4363 static void
4277 #if defined(HAVE_SOCKETS) && !defined(HAVE_MSG_SELECT) 4364 emacs_mswindows_delete_io_streams (Lisp_Object instream,
4278 : flags & STREAM_NETWORK_CONNECTION 4365 Lisp_Object outstream,
4279 ? HANDLE_TO_USID (get_winsock_stream_waitable (XLSTREAM (*instream))) 4366 Lisp_Object errstream,
4280 #endif 4367 USID *in_usid,
4281 : HANDLE_TO_USID (get_ntpipe_input_stream_waitable (XLSTREAM (*instream)))); 4368 USID *err_usid)
4282 } 4369 {
4283 4370 #ifdef CYGWIN
4284 USID 4371 event_stream_unixoid_delete_io_streams (instream, outstream, errstream,
4285 emacs_mswindows_delete_stream_pair (Lisp_Object instream, 4372 in_usid, err_usid);
4286 Lisp_Object outstream) 4373 #else
4287 { 4374 *in_usid =
4288 /* Oh nothing special here for Win32 at all */ 4375 (NILP (instream)
4289 #if defined (HAVE_UNIX_PROCESSES) 4376 ? USID_DONTHASH
4290 int in = (NILP(instream) 4377 : LSTREAM_TYPE_P (XLSTREAM (instream), winsock)
4291 ? -1 4378 ? HANDLE_TO_USID (get_winsock_stream_waitable (XLSTREAM (instream)))
4292 #if defined(HAVE_SOCKETS) && !defined(HAVE_MSG_SELECT) 4379 : HANDLE_TO_USID (get_ntpipe_input_stream_waitable (XLSTREAM
4293 : LSTREAM_TYPE_P (XLSTREAM (instream), winsock) 4380 (instream))));
4294 ? get_winsock_stream_param (XLSTREAM (instream)) 4381
4295 #endif 4382 *err_usid =
4296 : get_ntpipe_input_stream_param (XLSTREAM (instream))); 4383 (NILP (errstream)
4297 int out = (NILP(outstream) ? -1 4384 ? USID_DONTHASH
4298 : filedesc_stream_fd (XLSTREAM (outstream))); 4385 : HANDLE_TO_USID (get_ntpipe_input_stream_waitable (XLSTREAM
4299 4386 (errstream))));
4300 if (in >= 0) 4387 #endif /* CYGWIN */
4301 retry_close (in);
4302 if (out != in && out >= 0)
4303 retry_close (out);
4304 #endif
4305
4306 return (NILP (instream)
4307 ? USID_DONTHASH
4308 #if defined(HAVE_SOCKETS) && !defined(HAVE_MSG_SELECT)
4309 : LSTREAM_TYPE_P (XLSTREAM (instream), winsock)
4310 ? HANDLE_TO_USID (get_winsock_stream_waitable (XLSTREAM (instream)))
4311 #endif
4312 : HANDLE_TO_USID (get_ntpipe_input_stream_waitable (XLSTREAM (instream))));
4313 } 4388 }
4314 4389
4315 static int 4390 static int
4316 emacs_mswindows_current_event_timestamp (struct console *c) 4391 emacs_mswindows_current_event_timestamp (struct console *c)
4317 { 4392 {
4319 } 4394 }
4320 4395
4321 #ifndef HAVE_X_WINDOWS 4396 #ifndef HAVE_X_WINDOWS
4322 /* This is called from GC when a process object is about to be freed. 4397 /* This is called from GC when a process object is about to be freed.
4323 If we've still got pointers to it in this file, we're gonna lose hard. 4398 If we've still got pointers to it in this file, we're gonna lose hard.
4324 */ 4399 */
4400 void debug_process_finalization (Lisp_Process *p);
4325 void 4401 void
4326 debug_process_finalization (Lisp_Process *p) 4402 debug_process_finalization (Lisp_Process *p)
4327 { 4403 {
4328 #if 0 /* #### */ 4404 #if 0 /* #### */
4329 Lisp_Object instr, outstr; 4405 Lisp_Object instr, outstr, errstr;
4330 4406
4331 get_process_streams (p, &instr, &outstr); 4407 get_process_streams (p, &instr, &outstr, &errstr);
4332 /* if it still has fds, then it hasn't been killed yet. */ 4408 /* if it still has fds, then it hasn't been killed yet. */
4333 assert (NILP (instr)); 4409 assert (NILP (instr));
4334 assert (NILP (outstr)); 4410 assert (NILP (outstr));
4411 assert (NILP (errstr));
4335 4412
4336 /* #### More checks here */ 4413 /* #### More checks here */
4337 #endif 4414 #endif
4338 } 4415 }
4339 #endif 4416 #endif
4677 mswindows_event_stream->add_timeout_cb = emacs_mswindows_add_timeout; 4754 mswindows_event_stream->add_timeout_cb = emacs_mswindows_add_timeout;
4678 mswindows_event_stream->remove_timeout_cb = emacs_mswindows_remove_timeout; 4755 mswindows_event_stream->remove_timeout_cb = emacs_mswindows_remove_timeout;
4679 mswindows_event_stream->quit_p_cb = emacs_mswindows_quit_p; 4756 mswindows_event_stream->quit_p_cb = emacs_mswindows_quit_p;
4680 mswindows_event_stream->select_console_cb = emacs_mswindows_select_console; 4757 mswindows_event_stream->select_console_cb = emacs_mswindows_select_console;
4681 mswindows_event_stream->unselect_console_cb = emacs_mswindows_unselect_console; 4758 mswindows_event_stream->unselect_console_cb = emacs_mswindows_unselect_console;
4682 #ifdef HAVE_MSG_SELECT
4683 mswindows_event_stream->select_process_cb =
4684 (void (*)(Lisp_Process *)) event_stream_unixoid_select_process;
4685 mswindows_event_stream->unselect_process_cb =
4686 (void (*)(Lisp_Process *)) event_stream_unixoid_unselect_process;
4687 mswindows_event_stream->create_stream_pair_cb = event_stream_unixoid_create_stream_pair;
4688 mswindows_event_stream->delete_stream_pair_cb = event_stream_unixoid_delete_stream_pair;
4689 #else
4690 mswindows_event_stream->select_process_cb = emacs_mswindows_select_process; 4759 mswindows_event_stream->select_process_cb = emacs_mswindows_select_process;
4691 mswindows_event_stream->unselect_process_cb = emacs_mswindows_unselect_process; 4760 mswindows_event_stream->unselect_process_cb = emacs_mswindows_unselect_process;
4692 mswindows_event_stream->create_stream_pair_cb = emacs_mswindows_create_stream_pair; 4761 mswindows_event_stream->create_io_streams_cb = emacs_mswindows_create_io_streams;
4693 mswindows_event_stream->delete_stream_pair_cb = emacs_mswindows_delete_stream_pair; 4762 mswindows_event_stream->delete_io_streams_cb = emacs_mswindows_delete_io_streams;
4694 #endif
4695 mswindows_event_stream->current_event_timestamp_cb = 4763 mswindows_event_stream->current_event_timestamp_cb =
4696 emacs_mswindows_current_event_timestamp; 4764 emacs_mswindows_current_event_timestamp;
4697 } 4765 }
4698 4766
4699 void 4767 void
4709 mswindows_s_dispatch_event_queue = Qnil; 4777 mswindows_s_dispatch_event_queue = Qnil;
4710 staticpro (&mswindows_s_dispatch_event_queue); 4778 staticpro (&mswindows_s_dispatch_event_queue);
4711 mswindows_s_dispatch_event_queue_tail = Qnil; 4779 mswindows_s_dispatch_event_queue_tail = Qnil;
4712 dump_add_root_object (&mswindows_s_dispatch_event_queue_tail); 4780 dump_add_root_object (&mswindows_s_dispatch_event_queue_tail);
4713 4781
4714 mswindows_error_caught_in_modal_loop = Qnil; 4782 mswindows_error_caught_in_modal_loop = 0;
4715 staticpro (&mswindows_error_caught_in_modal_loop);
4716
4717 4783
4718 #ifdef DEBUG_XEMACS 4784 #ifdef DEBUG_XEMACS
4719 DEFVAR_INT ("debug-mswindows-events", &debug_mswindows_events /* 4785 DEFVAR_INT ("debug-mswindows-events", &debug_mswindows_events /*
4720 If non-zero, display debug information about Windows messages that XEmacs sees. 4786 If non-zero, display debug information about Windows messages that XEmacs sees.
4721 Information is displayed in a console window. Currently defined values are: 4787 Information is displayed in a console window. Currently defined values are:
4790 } 4856 }
4791 4857
4792 void 4858 void
4793 lstream_type_create_mswindows_selectable (void) 4859 lstream_type_create_mswindows_selectable (void)
4794 { 4860 {
4861 #ifndef CYGWIN
4795 init_slurp_stream (); 4862 init_slurp_stream ();
4796 init_shove_stream (); 4863 init_shove_stream ();
4797 #if defined (HAVE_SOCKETS) && !defined (HAVE_MSG_SELECT)
4798 init_winsock_stream (); 4864 init_winsock_stream ();
4799 #endif 4865 #endif
4800 } 4866 }
4801 4867
4802 void 4868 void
4803 init_event_mswindows_late (void) 4869 init_event_mswindows_late (void)
4804 { 4870 {
4805 #ifdef HAVE_MSG_SELECT 4871 #ifdef CYGWIN
4806 windows_fd = retry_open ("/dev/windows", O_RDONLY | O_NONBLOCK, 0); 4872 windows_fd = retry_open ("/dev/windows", O_RDONLY | O_NONBLOCK, 0);
4807 assert (windows_fd >= 0); 4873 assert (windows_fd >= 0);
4808 FD_SET (windows_fd, &input_wait_mask); 4874 FD_SET (windows_fd, &input_wait_mask);
4809 FD_ZERO (&zero_mask); 4875 FD_ZERO (&zero_mask);
4810 #endif 4876 #endif