diff options
| author | Steven Tamm | 2004-07-19 06:38:14 +0000 |
|---|---|---|
| committer | Steven Tamm | 2004-07-19 06:38:14 +0000 |
| commit | bfcf6608012308f18740cf8b6d7d0e7e26c76022 (patch) | |
| tree | ac337233db35ac1800da190c61bc86ce1904d700 /src | |
| parent | bde32f3bb4013543cac5ab9c9de927d59f2b0c2e (diff) | |
| download | emacs-bfcf6608012308f18740cf8b6d7d0e7e26c76022.tar.gz emacs-bfcf6608012308f18740cf8b6d7d0e7e26c76022.zip | |
mac.c (sys_select): Block input around call to
ReceiveNextEvent to prevent breakage. Correctly handle
blocking on event queue only by calling ReceiveNextEvent
instead of select (since GUI events aren't on an fd).
(sys_read): Remove function
sysdep.c: Remove redefine of read to sys_read if HAVE_CARBON
Diffstat (limited to 'src')
| -rw-r--r-- | src/ChangeLog | 9 | ||||
| -rw-r--r-- | src/mac.c | 146 | ||||
| -rw-r--r-- | src/sysdep.c | 4 |
3 files changed, 89 insertions, 70 deletions
diff --git a/src/ChangeLog b/src/ChangeLog index bc59ae9e2d7..0c8b389b65b 100644 --- a/src/ChangeLog +++ b/src/ChangeLog | |||
| @@ -1,5 +1,14 @@ | |||
| 1 | 2004-07-18 YAMAMOTO Mitsuharu <mituharu@math.s.chiba-u.ac.jp> | 1 | 2004-07-18 YAMAMOTO Mitsuharu <mituharu@math.s.chiba-u.ac.jp> |
| 2 | 2 | ||
| 3 | * mac.c (sys_select): Block input around call to | ||
| 4 | ReceiveNextEvent to prevent breakage. Correctly handle | ||
| 5 | blocking on event queue only by calling ReceiveNextEvent | ||
| 6 | instead of select (since GUI events aren't on an fd). | ||
| 7 | (sys_read): Remove function | ||
| 8 | * sysdep.c: Remove redefine of read to sys_read if HAVE_CARBON | ||
| 9 | |||
| 10 | 2004-07-18 YAMAMOTO Mitsuharu <mituharu@math.s.chiba-u.ac.jp> | ||
| 11 | |||
| 3 | * mac.c (sys_select): Redo sys_select to use alarm-based | 12 | * mac.c (sys_select): Redo sys_select to use alarm-based |
| 4 | polling instead of 1 sec timeouts (like solaris). | 13 | polling instead of 1 sec timeouts (like solaris). |
| 5 | 14 | ||
| @@ -2769,6 +2769,8 @@ and t is the same as `SECONDARY'. */) | |||
| 2769 | extern int inhibit_window_system; | 2769 | extern int inhibit_window_system; |
| 2770 | extern int noninteractive; | 2770 | extern int noninteractive; |
| 2771 | 2771 | ||
| 2772 | #include "blockinput.h" | ||
| 2773 | |||
| 2772 | /* When Emacs is started from the Finder, SELECT always immediately | 2774 | /* When Emacs is started from the Finder, SELECT always immediately |
| 2773 | returns as if input is present when file descriptor 0 is polled for | 2775 | returns as if input is present when file descriptor 0 is polled for |
| 2774 | input. Strangely, when Emacs is run as a GUI application from the | 2776 | input. Strangely, when Emacs is run as a GUI application from the |
| @@ -2776,88 +2778,100 @@ extern int noninteractive; | |||
| 2776 | the system call SELECT corrects this discrepancy. */ | 2778 | the system call SELECT corrects this discrepancy. */ |
| 2777 | int | 2779 | int |
| 2778 | sys_select (n, rfds, wfds, efds, timeout) | 2780 | sys_select (n, rfds, wfds, efds, timeout) |
| 2779 | int n; | 2781 | int n; |
| 2780 | SELECT_TYPE *rfds; | 2782 | SELECT_TYPE *rfds; |
| 2781 | SELECT_TYPE *wfds; | 2783 | SELECT_TYPE *wfds; |
| 2782 | SELECT_TYPE *efds; | 2784 | SELECT_TYPE *efds; |
| 2783 | struct timeval *timeout; | 2785 | struct timeval *timeout; |
| 2784 | { | 2786 | { |
| 2787 | OSErr err; | ||
| 2788 | EMACS_TIME end_time, now, remaining_time; | ||
| 2789 | |||
| 2785 | if (inhibit_window_system || noninteractive | 2790 | if (inhibit_window_system || noninteractive |
| 2786 | || rfds == NULL || !FD_ISSET (0, rfds)) | 2791 | || rfds == NULL || !FD_ISSET (0, rfds)) |
| 2787 | return select(n, rfds, wfds, efds, timeout); | 2792 | return select (n, rfds, wfds, efds, timeout); |
| 2788 | else | 2793 | |
| 2789 | { | 2794 | if (wfds == NULL && efds == NULL) |
| 2790 | EMACS_TIME end_time, now; | 2795 | { |
| 2791 | 2796 | int i; | |
| 2792 | EMACS_GET_TIME (end_time); | 2797 | |
| 2793 | if (timeout) | 2798 | for (i = 1; i < n; i++) |
| 2794 | EMACS_ADD_TIME (end_time, end_time, *timeout); | 2799 | if (FD_ISSET (i, rfds)) |
| 2795 | 2800 | break; | |
| 2796 | do | 2801 | if (i == n) |
| 2797 | { | 2802 | { |
| 2798 | EMACS_TIME select_timeout; | 2803 | EventTimeout timeout_sec = |
| 2799 | SELECT_TYPE orfds = *rfds; | 2804 | (timeout |
| 2800 | int r; | 2805 | ? (EMACS_SECS (*timeout) * kEventDurationSecond |
| 2801 | OSErr err; | 2806 | + EMACS_USECS (*timeout) * kEventDurationMicrosecond) |
| 2802 | 2807 | : kEventDurationForever); | |
| 2803 | EMACS_SET_SECS (select_timeout, 0); | 2808 | |
| 2804 | EMACS_SET_USECS (select_timeout, 100); | 2809 | BLOCK_INPUT; |
| 2805 | 2810 | err = ReceiveNextEvent (0, NULL, timeout_sec, | |
| 2806 | if (timeout && EMACS_TIME_LT (*timeout, select_timeout)) | 2811 | kEventLeaveInQueue, NULL); |
| 2807 | select_timeout = *timeout; | 2812 | UNBLOCK_INPUT; |
| 2808 | 2813 | if (err == noErr) | |
| 2809 | r = select (n, &orfds, wfds, efds, &select_timeout); | ||
| 2810 | err = ReceiveNextEvent (0, NULL, kEventDurationNoWait, false, NULL); | ||
| 2811 | if (r > 0) | ||
| 2812 | { | ||
| 2813 | *rfds = orfds; | ||
| 2814 | if (err == noErr) | ||
| 2815 | { | ||
| 2816 | FD_SET (0, rfds); | ||
| 2817 | r++; | ||
| 2818 | } | ||
| 2819 | return r; | ||
| 2820 | } | ||
| 2821 | else if (err == noErr) | ||
| 2822 | { | 2814 | { |
| 2823 | FD_ZERO (rfds); | 2815 | FD_ZERO (rfds); |
| 2824 | FD_SET (0, rfds); | 2816 | FD_SET (0, rfds); |
| 2825 | return 1; | 2817 | return 1; |
| 2826 | } | 2818 | } |
| 2827 | 2819 | else | |
| 2828 | EMACS_GET_TIME (now); | 2820 | return 0; |
| 2829 | EMACS_SUB_TIME (now, end_time, now); | ||
| 2830 | } | 2821 | } |
| 2831 | while (!timeout || !EMACS_TIME_NEG_P (now)); | 2822 | } |
| 2832 | 2823 | ||
| 2833 | return 0; | 2824 | if (timeout) |
| 2825 | { | ||
| 2826 | remaining_time = *timeout; | ||
| 2827 | EMACS_GET_TIME (now); | ||
| 2828 | EMACS_ADD_TIME (end_time, now, remaining_time); | ||
| 2834 | } | 2829 | } |
| 2835 | } | 2830 | FD_CLR (0, rfds); |
| 2831 | do | ||
| 2832 | { | ||
| 2833 | EMACS_TIME select_timeout; | ||
| 2834 | SELECT_TYPE orfds = *rfds; | ||
| 2835 | int r; | ||
| 2836 | 2836 | ||
| 2837 | #undef read | 2837 | EMACS_SET_SECS_USECS (select_timeout, 0, 20000); |
| 2838 | int sys_read (fds, buf, nbyte) | 2838 | |
| 2839 | int fds; | 2839 | if (timeout && EMACS_TIME_LT (remaining_time, select_timeout)) |
| 2840 | char *buf; | 2840 | select_timeout = remaining_time; |
| 2841 | unsigned int nbyte; | 2841 | |
| 2842 | { | 2842 | r = select (n, &orfds, wfds, efds, &select_timeout); |
| 2843 | SELECT_TYPE rfds; | 2843 | BLOCK_INPUT; |
| 2844 | EMACS_TIME one_second; | 2844 | err = ReceiveNextEvent (0, NULL, kEventDurationNoWait, |
| 2845 | int r; | 2845 | kEventLeaveInQueue, NULL); |
| 2846 | 2846 | UNBLOCK_INPUT; | |
| 2847 | /* Use select to block on IO while still checking for quit_char */ | 2847 | if (r > 0) |
| 2848 | if (!inhibit_window_system && !noninteractive && | 2848 | { |
| 2849 | ! (fcntl(fds, F_GETFL, 0) & O_NONBLOCK)) | 2849 | *rfds = orfds; |
| 2850 | { | 2850 | if (err == noErr) |
| 2851 | FD_ZERO (&rfds); | 2851 | { |
| 2852 | FD_SET (fds, &rfds); | 2852 | FD_SET (0, rfds); |
| 2853 | if (sys_select (fds+1, &rfds, 0, 0, NULL) < 0) | 2853 | r++; |
| 2854 | return -1; | 2854 | } |
| 2855 | return r; | ||
| 2856 | } | ||
| 2857 | else if (err == noErr) | ||
| 2858 | { | ||
| 2859 | FD_ZERO (rfds); | ||
| 2860 | FD_SET (0, rfds); | ||
| 2861 | return 1; | ||
| 2862 | } | ||
| 2863 | |||
| 2864 | if (timeout) | ||
| 2865 | { | ||
| 2866 | EMACS_GET_TIME (now); | ||
| 2867 | EMACS_SUB_TIME (remaining_time, end_time, now); | ||
| 2868 | } | ||
| 2855 | } | 2869 | } |
| 2870 | while (!timeout || EMACS_TIME_LT (now, end_time)); | ||
| 2856 | 2871 | ||
| 2857 | return read (fds, buf, nbyte); | 2872 | return 0; |
| 2858 | } | 2873 | } |
| 2859 | 2874 | ||
| 2860 | |||
| 2861 | /* Set up environment variables so that Emacs can correctly find its | 2875 | /* Set up environment variables so that Emacs can correctly find its |
| 2862 | support files when packaged as an application bundle. Directories | 2876 | support files when packaged as an application bundle. Directories |
| 2863 | placed in /usr/local/share/emacs/<emacs-version>/, /usr/local/bin, | 2877 | placed in /usr/local/share/emacs/<emacs-version>/, /usr/local/bin, |
diff --git a/src/sysdep.c b/src/sysdep.c index 5ede3d27208..d5236a3f88a 100644 --- a/src/sysdep.c +++ b/src/sysdep.c | |||
| @@ -70,10 +70,6 @@ static int delete_exited_processes; | |||
| 70 | #endif | 70 | #endif |
| 71 | #endif /* not WINDOWSNT */ | 71 | #endif /* not WINDOWSNT */ |
| 72 | 72 | ||
| 73 | #ifdef HAVE_CARBON | ||
| 74 | #define read sys_read | ||
| 75 | #endif | ||
| 76 | |||
| 77 | /* Does anyone other than VMS need this? */ | 73 | /* Does anyone other than VMS need this? */ |
| 78 | #ifndef fwrite | 74 | #ifndef fwrite |
| 79 | #define sys_fwrite fwrite | 75 | #define sys_fwrite fwrite |